2022暑期个人训练赛第04场

Problem A: 月相

题目描述

牛牛最近在观察月相,他把月亮的大小分为 0~15 这16 个大小等级,月亮会在每个月先每天放大1,从0缓慢变大到15,然后再每天减小1,从15逐渐变成0,以此循环往复。 

牛牛连续观察了2天月亮的大小,牛牛想知道下一天月亮的大小是多少。 

输入

第一行输入两个整数a, b,表示牛牛观察的月亮的大小,分别是第一天、第二天的结果。 
对于60%的数据有1 ≤ a, b ≤ 14。 
对于100%的数据有0 ≤ a, b ≤ 15。

输出

一行一个整数,表示下一天的月亮的大小。 

样例输入 

15 14

样例输出 

13

提示

【样例说明】 
前两天分别是15, 14,故牛牛知道月亮在逐渐变小,所以下一天是13。 
思路:送分题,做好特殊判定(1,0,1 和 14,15,14)就行了
代码:
#include<iostream>
using namespace std;
int a,b;
int main()
{
    cin>>a>>b;
    if(a==14 && b==15){ //特判1
        cout<<"14";
    }else if(a==1 && b==0){ //特判2
        cout<<"1";
    }else if(a>b){
        cout<<b-1;
    }else{
        cout<<b+1;
    }
    return 0;
}

Problem H: 伞 (flag)

题目描述

当我跨过沉沦的一切,向着永恒开战的时候,你是我的军旗。
这是 Marser 给她的笔记上写的一句话。
然后被她爆 D 一顿:我知道你很真诚,但我想,你应该打磨一下自己的文字。

送完笔记的 Marser 站在润德楼电梯前思考人生,无意识地转起了雨伞。
他回过神来,发现雨伞上落下的雨滴围成了一个封闭图形。
我们可以把 Marser 的雨伞抽象成一个平行于地面的圆,不考虑风力等因素。
Marser 记录下了雨伞旋转的角速度w(单位为 rad·s-1),半径r(单位为 m),以及雨伞边缘离地高度 h(单位为 m)。他要求你计算封闭图形的面积,其中,重力加速度 g 取 10 m·s-2。
如果你没有学过有关知识,请参阅附加内容。

输入

第一行有三个数w,r,h,意义如题面所述。

输出

输出一行,表示所求图形的面积,保留 3 位小数。

样例输入

0 4 4

样例输出

50.265

提示

思路:这一题只要把公式推出来就很快能写完了

公式如下:

 

不过这里要注意,pi不可以直接用3.14,不然答案会有偏差,需要用cmath函数里面的acos(-1)

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const double pi=acos(-1); //定义pi
double w,r,h;
int main()
{
    cin>>w>>r>>h;
    double ans=pi*((r*r*w*w*(2*h))/10+r*r); //公式
    printf("%.3lf",ans); //用printf保留三位小数
    return 0;
}

Problem I: Move Right

题目描述

There are 4 squares lined up horizontally.You are given a string S of length 4 consisting of 0 and 1.
If the i-th character of S is 1, there is a person in the i-th square from the left;
if the i-th character of S is 0, there is no person in the i-th square from the left.Now, everyone will move to the next square to the right simultaneously. By this move, the person who was originally in the rightmost square will disappear.Determine if there will be a person in each square after the move. Print the result as a string in the same format as S. (See also Sample Input / Output for clarity.)
Constraints
S is a string of length 4 consisting of 0 and 1.
 

输入

Input is given from Standard Input in the following format:
S
 

输出

Print a string of length 4 such that the i-th character is 1 if there will be a person in the i-th square from the left after the move, and 0 otherwise.
 

样例输入

【输入样例1】
1011

【输入样例2】
0000

【输入样例3】
1111

样例输出 

【输出样例1】
0101

【输出样例2】
0000

【输出样例3】
0111

提示

样例1解释
After the move, the person who was originally in the 1-st square will move to the 2-nd square,
the person in the 3-rd square to the 4-th square,
and the person in the 4-th square will disappear.

思路:感觉就是考英语理解能力的,看不懂也没关系,看样例也能看出来其实就是字符串基本操作。把所有元素的位置往右移动一个,第一个位置以0代替。

代码:

#include<iostream>
#include<string>
using namespace std;
string s;
int main()
{
    cin>>s;
    s="0"+s;
    for(int i=0;i<4;i++){
        cout<<s[i];
    }
    return 0;
}

Problem J: Unique Nicknames

题目描述

There are N people numbered Person 1, Person 2,..., and Person N. Person i has a family name si and a given name ti.Consider giving a nickname to each of the N people. Person i's nickname ai should satisfy all the conditions below.Is it possible to give nicknames to all the N people? If it is possible, print Yes; otherwise, print No.
ai coincides with Person i's family name or given name. In other words, ai = si and/or ai = ti holds.
ai does not coincide with the family name and the given name of any other person. In other words, for all integer j such that 1 ≤ j ≤ N and i ≠ j, it holds that ai ≠ sj and ai ≠ tj.
Constraints
2 ≤ N ≤ 100
N is an integer.
si and ti are strings of lengths between 1 and 10 (inclusive) consisting of lowercase English alphabets.
 

输入

Input is given from Standard Input in the following format:
N
s1 t1
s2 t2
.
.
.
sN tN
 

输出

If it is possible to give nicknames to all the N people, print Yes; otherwise, print No.
 

样例输入

【输入样例1】
3
tanaka taro
tanaka jiro
suzuki hanako

【输入样例2】
3
aaa bbb
xxx aaa
bbb yyy

【输入样例3】
2
tanaka taro
tanaka taro

【输入样例4】
3
takahashi chokudai
aoki kensho
snu ke

样例输出

【输出样例1】
Yes

【输出样例2】
No

【输出样例3】
No

【输出样例4】
Yes

提示

样例1解释
The following assignment satisfies the conditions of nicknames described in the Problem Statement: a1= taro, a2= jiro, a3= hanako. (a4 may be suzuki, too.)
However, note that we cannot let a1= tanaka, which violates the second condition of nicknames, since Person 2's family name s2 is tanaka too.

样例2解释
There is no way to give nicknames satisfying the conditions in the Problem Statement.

样例3解释
There may be a pair of people with the same family name and the same given name.

样例4解释
We can let a1= chokudai, a2= kensho, and a3= ke.

思路:翻译过来其实就是如果si和ti都跟任何一个sj或者tj相同,就不合法。如果所有元素都没有这个条件,那就合法。这里可以用map数组配合结构体来标记。

代码:

#include<iostream>
#include<string>
#include<map>
using namespace std;
map<string,int> mp;
int n;
struct node{
    string s;
    string t;
}a[107];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].s>>a[i].t;
        mp[a[i].s]++;
        mp[a[i].t]++;
    }
    for(int i=1;i<=n;i++){
        if(mp[a[i].s]>1 && mp[a[i].t]>1){
            if(a[i].s != a[i].t){ //这里要再做一个判断,如果si和ti是同样的字符串,他也是合法的,但这个情况下mp里还是会计算出>1的结果,所以得做一个特判
                cout<<"No"; //如果si和ti不一样那就代表不合法
                return 0;
            }
        }
    }
    cout<<"Yes"; //如果顺利走完了循环那就代表合法
    return 0;
}

Problem K: 1 2 1 3 1 2 1

题目描述

We define sequences Sn as follows.For example, S2 and S3 is defined as follows.Given N, print the entire sequence SN.
S1 is a sequence of length 1 containing a single 1.
Sn (n is an integer greater than or equal to 2) is a sequence obtained by concatenating Sn-1, n, Sn-1 in this order.
Constraints
N is an integer.
1 ≤ N ≤ 16
 

输入

Input is given from Standard Input in the following format:
N
 

输出

Print SN, with spaces in between.
 

样例输入

【输入样例1】
2
【输入样例2】
1
【输入样例3】
4

样例输出

【输出样例1】
1 2 1
【输出样例2】
1
【输出样例3】
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1

提示

样例1解释
As described in the Problem Statement, S2 is 1,2,1.

样例3解释
S4 is a concatenation of S3, 4, and S3, in this order.

思路:根据题目描述,能很快的想到这是一道递归题。递归基就是n=1 否则应该return func(n-1)然后输出n 然后再return func(n-1)

代码:

#include<iostream>
#include<string>
using namespace std;
void print(int n){
    if(n==1){ //递归基
        cout<<"1"<<" ";
        return ;
    }
    //否则按照题目要求递归
    print(n-1);
    cout<<n<<" ";
    print(n-1);
    return ;
}
int main()
{
    int n;
    cin>>n;
    print(n);
    return 0;
}

Problem T: Selection of Participants of an Experiment

题目描述

Dr. Tsukuba has devised a new method of programming training. In order to evaluate the effectiveness of this method, he plans to carry out a control experiment. Having two students as the participants of the experiment, one of them will be trained under the conventional method and the other under his new method. Comparing the final scores of these two, he will be able to judge the effectiveness of his method. 

It is important to select two students having the closest possible scores, for making the comparison fair. He has a list of the scores of all students who can participate in the experiment. You are asked to write a program which selects two of them having the smallest difference in their scores. 

输入

The input consists of multiple datasets, each in the following format. 
n
a1 a2 … an 
A dataset consists of two lines. The number of students n is given in the first line. n is an integer satisfying 2 ≤ n ≤ 1000. The second line gives scores of n students. ai (1 ≤ i ≤ n) is the score of the i-th student, which is a non-negative integer not greater than 1,000,000. 
  
The end of the input is indicated by a line containing a zero. The sum of n's of all the datasets does not exceed 50,000. 

输出

For each dataset, select two students with the smallest difference in their scores, and output in a line (the absolute value of) the difference. 

样例输入 

5
10 10 10 10 10
5
1 5 8 9 11
7
11 34 83 47 59 29 70
0

样例输出 

0
1
5

思路:英文理解+排序+比较(好像除了这三句话没有啥好说的了)

代码:

//甚至觉得好像没啥好解释的?
#include<bits/stdc++.h>
using namespace std;
int n,a[1000007],minn;
int main()
{
    while(cin>>n){
        minn=10000000;
        if(n==0){
            break;
        }
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        sort(a+1,a+1+n);
        for(int i=2;i<=n;i++){
            minn=min(minn,a[i]-a[i-1]);
        }
        cout<<minn<<endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值