您的位置:首页 > 其它

AtCoder Beginner Contest 070

2017-08-14 19:28 651 查看
A - Palindromic Number

Time limit : 2sec / Memory limit : 256MB

Score : 100 points

Problem Statement

You are given a three-digit positive integer N.

Determine whether N is a palindromic number.

Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.

Constraints

100≤N≤999

N is an integer.
Input

Input is given from Standard Input in the following format:

N
Output
If N is a palindromic number, print Yes; otherwise, print No.

Sample Input 1

575
Sample Output 1

Yes

N=575 is also 575 when read backward, so it is a palindromic number. You should print Yes.

Sample Input 2

123
Sample Output 2

No

N=123 becomes 321 when read backward, so it is not a palindromic number. You should print No.

Sample Input 3

812
Sample Output 3
No

小小翻译一下就是判断一下输入的数字是否是回文

#include<iostream>
using namespace std;
int main()
{
int n,t,sum;
while(cin>>n)
{
sum=0;
t=n;
while(n)
{
sum=sum*10+n%10;
n/=10;
}
if(t==sum)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
}B - Two Switches

Time limit : 2sec / Memory limit : 256MB

Score : 200 points

Problem Statement

Alice and Bob are controlling a robot. They each have one switch that controls the robot.

Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up.

Bob started holding down his button C second after the start-up, and released his button D second after the start-up.

For how many seconds both Alice and Bob were holding down their buttons?

Constraints

0≤A<B≤100

0≤C<D≤100

All input values are integers.
Input

Input is given from Standard Input in the following format:

A B C D
Output

Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.

Sample Input 1

0 75 25 100
Sample Output 1

50

Alice started holding down her button 0 second after the start-up of the robot, and released her button 75 second after the start-up.

Bob started holding down his button 25
4000
second after the start-up, and released his button 100 second after the start-up.

Therefore, the time when both of them were holding down their buttons, is the 50 seconds from 25 seconds after the start-up to 75 seconds after the start-up.

Sample Input 2

0 33 66 99
Sample Output 2

0

Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds.

Sample Input 3

10 90 20 80
Sample Output 3

60

整体意思就是A-B,C-D的时间段内,两个时间段的交集
#include<iostream>
using namespace std;
int a[110]={0};
int main()
{
int A,B,C,D,sum=0;
cin>>A>>B>>C>>D;
for(int i=0;i<=110;i++)
{
if(i>=A&&i<B)
a[i]++;
if(i>=C&&i<D)
a[i]++;
}
for(int i=0;i<=110;i++)
{
if(a[i]==2)
sum++;
}
cout<<sum<<endl;

}


C - Multiple Clocks

Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

We have N clocks.
The hand of the i-th clock (1≤i≤N) rotates
through 360° in exactly Ti seconds.

Initially, the hand of every clock stands still, pointing directly upward.

Now, Dolphin starts all the clocks simultaneously.

In how many seconds will the hand of every clock point directly upward again?

Constraints

1≤N≤100
1≤Ti≤1018
All input values are integers.
The correct answer is at most 1018 seconds.

Input

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


Output

Print the number of seconds after which the hand of every clock point directly upward again.

Sample Input 1

2
2
3


Sample Output 1

6

We have two clocks. The time when the hand of each clock points upward is as follows:
Clock 1: 2, 4, 6, … seconds
after the beginning
Clock 2: 3, 6, 9, … seconds
after the beginning
Therefore, it takes 6 seconds
until the hands of both clocks point directly upward.

Sample Input 2

5
2
5
10
1000000000000000000
1000000000000000000


Sample Output 2

1000000000000000000


#include<iostream>
using namespace std;
int main()
{
long long int n,c=1,m,t,temp;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>t;
if(t>c)
{
temp=c;
c=t;
t=temp;
}
long long int k,l;
k=t;
l=c;
while(t!=0)
{
temp=c%t;
c=t;
t=temp;
}
c=k/c*l;//数据太大,所以先除后乘
}
cout<<c<<endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: