AtCoder Beginner Contest 0972018/05/12 20:00:00 ~ 2018/05/12 21:40:00
A - Colorful Transceivers
Time limit : 2sec / Memory limit : 1024MB
Score : 100 points
Problem Statement
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
Constraints
- 1 ≤ a,b,c ≤ 100
- 1 ≤ d ≤ 100
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
a b c d
Output
If A and C can communicate, print Yes
; if they cannot, print No
.
Sample Input 1
4 7 9 3
Sample Output 1
Yes
A and B can directly communicate, and also B and C can directly communicate, so we should print Yes
.
Sample Input 2
100 10 1 2
Sample Output 2
No
They cannot communicate in this case.
Sample Input 3
10 10 10 1
Sample Output 3
Yes
There can be multiple people at the same position.
Sample Input 4
1 100 2 10
Sample Output 4
Yes
这题不是一般坑,比赛时我没仔细看题就编了,结果WA了n多次,浪费了5分钟
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
int d;
cin>>d;
if (fabs(a-b)<=d && fabs(b-c)<=d || fabs(a-c)<=d)
{
cout<<"Yes";
}
else
{
cout<<"No";
}
}
B - Exponential
Time limit : 2sec / Memory limit : 1024MB
Score : 200 points
Problem Statement
You are given a positive integer X. Find the largest perfect power that is at most X. Here, a perfect power is an integer that can be represented as bp, where b is an integer not less than 1 and p is an integer not less than 2.
Constraints
- 1 ≤ X ≤ 1000
- X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print the largest perfect power that is at most X.
Sample Input 1
10
Sample Output 1
9
There are four perfect powers that are at most 10: 1, 4, 8 and 9. We should print the largest among them, 9.
Sample Input 2
1
Sample Output 2
1
B题还是很水的,比赛时我直接打了一个表,神之AC
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[101]={0,1000,1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361,400,441,484,529,576,625,676,729,784,841,900,961,8,27,64,125,216,343,512,729,32,243,128,512};
sort(a+1,a+101);
for (int i=100;i>=1;i--)
{
if (a[i]<=n)
{
cout<<a[i]<<endl;
return 0;
}
}
}