省赛集训第二场

省赛第二场个人积分赛的总结:
这次比赛完全不在状态,想想当初就不该拔了那颗智齿,疼得特别难受。
现在状态好了,直接可以A出六道题,其实这题还是挺水的,所以,很可惜,我失去了一次拿多积分的机会,所以,接下来就需要更加努力了,加油,往追求的目标前进,绝不可以轻易失败。
Dinner
Little A is one member of ACM team. He had just won the gold in World Final. To celebrate, he decided to invite all to have one meal. As bowl, knife and other tableware is not enough in the kitchen, Little A goes to take backup tableware in warehouse. There are many boxes in warehouse, one box contains only one thing, and each box is marked by the name of things inside it. For example, if “basketball” is written on the box, which means the box contains only basketball. With these marks, Little A wants to find out the tableware easily. So, the problem for you is to help him, find out all the tableware from all boxes in the warehouse.
Input
There are many test cases. Each case contains one line, and one integer N at the first, N indicates that there are N boxes in the warehouse. Then N strings follow, each string is one name written on the box.
Output
For each test of the input, output all the name of tableware.
Sample Input
3 basketball fork chopsticks
2 bowl letter
Sample Output
fork chopsticks
bowl
Hint
The tableware only contains: bowl, knife, fork and chopsticks.
题意:
Little A是ACM团队的一员。他刚刚在世界总决赛中获得金牌。为了庆祝,他决定邀请所有人一顿饭。由于碗,刀和其他餐具在厨房里还不够,Little A去仓库里备用餐具。仓库中有很多箱子,一个箱子只包含一件物品,每个箱子都标有其中的物品名称。例如,如果在框中写入“篮球”,则表示该框仅包含篮球。有了这些标记,Little A想要轻松找到餐具。所以,问题在于帮助他,从仓库中的所有箱子中找出所有餐具。
输入:
有很多测试用例。每个案例包含一行,第一个包含一个整数N,N表示仓库中有N个框。然后是N个字符串,每个字符串都是一个写在盒子上的名字。
输出:
对于输入的每个测试,输出餐具的所有名称
暗示
餐具只包含:碗,刀,叉和筷子。
简单的说:其实,就是每次先输入一个数字,代表有多少个字符串,然后要做的就是判断餐具名与字符串是否相同。
水题,看懂题意就很简单;
解题思路:
每次输入一个字符串a,共N个,用每一个餐具名与它比较。相同则按格式输出,先输出餐具名,然后,一个空格,最后不要空格。
补一下知识点:
C/C++函数,strcmp比较两个字符串
设这两个字符串为str1,str2,
若str1=str2,则返回零;
若str1<str2,则返回负数;
若str1>str2,则返回正数。
matlab中函数,strcmp(s1,s2) 判断两个字符串s1和s2是否相同,相同返回true ,不同返回false

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    char a[55];
    bool flag;
    while(~scanf("%d",&n))
    {
        flag=false;
        while(n--)
        {
            cin>>a;
            if(strcmp(a,"bowl")==0||strcmp(a,"knife")==0||strcmp(a,"fork")==0||strcmp(a,"chopsticks")==0)//直接比较相同则直接输出,
            {
                if(flag)
                    printf(" ");
                cout<<a;
                flag=true;
            }
        }
        cout<<endl;
    }
    return 0;
}

You are my brother
Little A gets to know a new friend, Little B, recently. One day, they realize that they are family 500 years ago. Now, Little A wants to know whether Little B is his elder, younger or brother.
Input
There are multiple test cases.
For each test case, the first line has a single integer, n (n<=1000). The next n lines have two integers a and b (1<=a,b<=2000) each, indicating b is the father of a. One person has exactly one father, of course. Little A is numbered 1 and Little B is numbered 2.
Proceed to the end of file.
Output
For each test case, if Little B is Little A’s younger, print “You are my younger”. Otherwise, if Little B is Little A’s elder, print “You are my elder”. Otherwise, print “You are my brother”. The output for each test case occupied exactly one line.
Sample Input
5
1 3
2 4
3 5
4 6
5 6
6
1 3
2 4
3 5
4 6
5 7
6 7
Sample Output
You are my elder
You are my brother
Hint
输入
对于每个测试用例,第一行有一个整数n(n <= 1000)。接下来的n行各有两个整数a和b(1 <= a,b <= 2000),表示b是a的父亲。当然,一个人只有一个父亲。 Little A编号为1,Little B编号为2。
继续到文件的末尾。
输出
对于每个测试用例,如果Little B是Little A的年轻人,请打印“你是我的年轻人”。否则,如果小B是小A的长者,请打印“你是我的长辈”。否则,请打印“你是我的兄弟”。每个测试用例的输出只占用一行。

题意:A编号为1,B编号为2;找出他们的父亲或者以上的每一辈;或者说1和2分别是多少代子孙;如果B是小于A的辈分则打印You are my younger B是长辈则打印You are my elder,否则,打印You are my brother。
这个是找辈分的问题,
比如,对于第二组数据,
1的父亲是3,再找3的父亲是5,再找5的父亲是7,共3代。
同理,2的父亲是4,4的父亲是6,6的父亲是7,共3代,
因此1和2是兄弟!

#include <iostream>
#include <string.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
int  last[2005];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0; i<2005; i++)
        {
            last[i]=i;
        }
        for(int i=0; i<n; i++)
        {
            int a,b;
            scanf("%d %d",&a,&b);
            last[a]=b;
        }
        int t=1;
        int a1=0,a2=0;
        while(last[t]!=t)
        {
            a1++;
            t=last[t];
        }
        t=2;
        while(last[t]!=t)
        {
            a2++;
            t=last[t];
        }
        if(a1<a2)
            printf("You are my younger\n");
        else if(a1>a2)
            printf("You are my elder\n");
        else
            printf("You are my brother\n");
    }
    return 0;
}

DigitaTime
题目链接:https://ac.2333.moe/Problem/view.xhtml?id=1219
l clock use 4 digits to express time, each digit is described by 3*3 characters (including”|”,””and” “).now given the current time, please tell us how can it be expressed by the digital clock.
Input
There are several test cases.
Each case contains 4 integers in a line, separated by space.
Proceed to the end of file.
Output
For each test case, output the time expressed by the digital clock such as Sample Output.
Sample Input
1 2 5 6
2 3 4 2
Sample Output
_ _ _
| || |

||_ |||


_| ||| |
|
| ||
Hint
The digits showed by the digital clock are as follows:


| | |||| |_ |||||| |
||_ | | ||| ||| |||
补:这个数据看起来不清晰,请看原题:
题意:
l时钟用4位数来表示时间,每个数字用3 * 3个字符描述(包括“|”,“_”和“ ”)。现在给出当前时间,请告诉我们如何用数字时钟表示。
解题思路:用二维字符数组,存入一到九和零的数字时钟表示;
输入一组数字,在对应位置将数字代表的数字时钟输出即可:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
string s[3][10]= {{" _ ","   "," _ "," _ ","   "," _ "," _ "," _ "," _ "," _ "},
    {"| |","  |"," _|"," _|","|_|","|_ ","|_ ","  |","|_|","|_|"},
    {"|_|","  |","|_ "," _|","  |"," _|","|_|","  |","|_|"," _|"}
};//我们可以用string 或者二维字符数组存;
int main()
{
    int a[4];
    while(~scanf("%d",&a[0]))
    {
        scanf("%d%d%d",&a[1],&a[2],&a[3]);
        for(int i=0;i<3;i++)//控制行,
        {
            for(int j=0;j<4;j++)控制列总共四个数字代表时间;a[j]意味则是第几个数字,然后每次三行,输出对应的时钟的列;
                cout<<s[i][a[j]];//
            cout<<endl;
        }
    }
    return 0;
}

H题;
In this problem you need to make a triangle ,just like the sample out. The element in the ith row and jth column

should be the product(乘积) of i and j.

Input
The first line of input is an integer C which indicate the number of test cases.
Then C test cases follow.Each test case contains an integer N (1<=N<=20) in a line which mentioned above.
Output
For each test case, print out the triangle. the triangle separated by a blank line.
If the product is more than 9 (product > 9) you should print a space, or you should print two space.The final number of each line don’t need print space.
Sample Input
3
5
6
7
Sample Output
1 2 3 4 5
2 4 6 8
3 6 9
4 8
5

1 2 3 4 5 6
2 4 6 8 10
3 6 9 12
4 8 12
5 10
6

1 2 3 4 5 6 7
2 4 6 8 10 12
3 6 9 12 15
4 8 12 16
5 10 15
6 12
7

题意:在这个问题中,您需要制作一个三角形,就像样本一样。第i行和第j列中的元素
应该是i和j的乘积(乘积)。
解题思路:ij,两层for循环,输出i*j 在判断是否小于九,是则一个空格,否则两个空格,这题就是要卡不然很容易就过了;
特别要注意的是打印的格式;乘积小于9每个数之见按一个空格,大于等于九就 是两个空格;

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int n,m,t=0;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&m);
        int s=m;//为了打印三角形,每次减一;
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=s;j++)
            {
                printf("%d",i*j);
                if(i*j>9&&j!=s)
                    printf(" ");
                else if(i*j<=9&&j!=s)
                    printf("  ");
            }
            printf("\n");
            s--;
        }
        if(n)
            printf("\n");
    }
    return 0;
}

The boring Three-God get a boring question.
So you have to transform a binary number to a decimal.
Input
There are muti-case.
For each case, there are a binary number, the binary number’s length is less than 32, and the binary number have no pre-zero (前导零).
Output
For each binary number, print the decimal numbuer.the decimal number is less than 2^31 - 1.
Sample Input
1
10
11
Sample Output
1
2
3

题意:这题其实就是要你把二进制数转换为一个十进制数。
. 在这里补一下:
十进制整数转换为二进制整数
十进制整数转换为二进制整数采用"除2取余,逆序排列"法。具体做法是:用2整除十进制整数,可以得到一个商和余数;再用2去除商,又会得到一个商和余数,如此进行,直到商为小于1时为止,然后把先得到的余数作为二进制数的低位有效位,后得到的余数作为二进制数的高位有效位,依次排列起来。

解题思路:把二进制数当字符串,每一位都可以直接按下面的方法求,
十进制转二进制的方法:就是把一个有X位的二进制数,从右往左数,每一位依次乘以2的0次方,2的1次方,2的2次方,一直乘到2的X-1次方,然后把这些次方的结果加起来即可得到最终一个十进制数的结果。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    char t[34];
    while(~scanf("%s",t))
    {
        int l=strlen(t
        int a[34];
        for(int i=0;i<l;i++)
        {
            a[i]=t[i]-48;//每一个位数减去0的十进制的ASCLL值;
        }
        int x=a[0];
        for(int i=1;i<l;i++)
        {
            x=x*2+a[i];//进制转换;
        }
        printf("%d\n",x);
    }
   return 0;
}

北宋末年,奸臣当道,宦官掌权,外侮日亟,辽军再犯。时下战火连连,烽烟四起,哀鸿遍野,民不聊生,又有众多能人异士群起而反,天下志士云集响应,景粮影从。
值此危急存亡之秋,在一个与世隔绝的地方—MCA山上一位江湖人称<英雄哪里出来>的人正在为抗击辽贼研究剑法,终于于一雷电交加之夜精确计算出了荡剑回锋的剑气伤害公式。

定义 f(x, y, m, n) = sqrt(xx + yy + mm + nn - 2mx - 2ny);
hint : sqrt表示开方,即sqrt(4) = 2; sqrt(16) = 4;

(其中x,y为位置变量,m,n为属性常量)
剑气伤害 = f(x, y, a, b) + f(x, y, c, d);
剑气威力巨大无比,实难控制,现在他想知道剑气伤害的最小伤害值。

Input
首先输入一个t,表示有t组数据,跟着t行:
输入四个实数a,b,c,d均小于等于100
Output
输出剑气的最小伤害值M,保留小数点后一位
(可以使用.1lf)
Sample Input
2
0 0 3 4
4 0 0 3
Sample Output
5.0
5.0
题意:用剑气伤害公式,f(x,y,m,n)=sqrt(xx+yy,+mm+nn+2mx+2ny;求值:
解题思路:按照题意输入输出,留意处理输出的数据格式,直接求出答案:

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
#define T 10010
int main()
{
    int t;
    double a,b,c,d,s;
    scanf("%d",&t);
    while(t--)
    {
        cin>>a>>b>>c>>d;
        s=sqrt(a*a+b*b+c*c+d*d-2*c*a-2*d*b);
        printf("%.1lf\n",s);
    }
}

猜你喜欢

转载自blog.csdn.net/qq_43516113/article/details/88940818
今日推荐