AtCoder Beginner Contest 068 ABCD题

 

A - ABCxxx


Time limit : 2sec / Memory limit : 256MB

Score : 100 points

Problem Statement

This contest, AtCoder Beginner Contest, is abbreviated as ABC.

When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.

What is the abbreviation for the N-th round of ABC? Write a program to output the answer.

Constraints

  • 100≤N≤999

Input

Input is given from Standard Input in the following format:

N

Output

Print the abbreviation for the N-th round of ABC.


Sample Input 1

Copy
100

Sample Output 1

Copy
ABC100

The 100th round of ABC is ABC100.


Sample Input 2

Copy
425

Sample Output 2

Copy
ABC425

Sample Input 3

Copy
999

Sample Output 3

Copy
ABC999

题解:水水

1 #include <cstdio>
2 int main()
3 {
4     int n;
5     scanf("%d",&n);
6     printf("ABC%d\n",n);
7     return 0;
8 }

B - Break Number


Time limit : 2sec / Memory limit : 256MB

Score : 200 points

Problem Statement

Takahashi loves numbers divisible by 2.

You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.

Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.

For example,

  • 6 can be divided by 2 once: 6 -> 3.
  • 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
  • 3 can be divided by 2 zero times.

Constraints

  • 1≤N≤100

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

Copy
7

Sample Output 1

Copy
4

4 can be divided by 2 twice, which is the most number of times among 12, ..., 7.


Sample Input 2

Copy
32

Sample Output 2

Copy
32

Sample Input 3

Copy
1

Sample Output 3

Copy
1

Sample Input 4

Copy
100

Sample Output 4

Copy
64

题解:水水
 1 #include <iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     int n;
 6     cin>>n;
 7     if(n<2) cout<<1<<endl;
 8     else if(n<4) cout<<2<<endl;
 9     else if(n<8) cout<<4<<endl;
10     else if(n<16) cout<<8<<endl;
11     else if(n<32) cout<<16<<endl;
12     else if(n<64) cout<<32<<endl;
13     else cout<<64<<endl;
14     return 0;
15 }

C - Cat Snuke and a Voyage


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N.

There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island ai and Island bi.

Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.

Help him.

Constraints

  • 3≤N≤200 000
  • 1≤M≤200 000
  • 1≤ai<biN
  • (ai,bi)≠(1,N)
  • If ij(ai,bi)≠(aj,bj).

Input

Input is given from Standard Input in the following format:

N M
a1 b1
a2 b2
:
aM bM

Output

If it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.


Sample Input 1

Copy
3 2
1 2
2 3

Sample Output 1

Copy
POSSIBLE

Sample Input 2

Copy
4 3
1 2
2 3
3 4

Sample Output 2

Copy
IMPOSSIBLE

You have to use three boat services to get to Island 4.


Sample Input 3

Copy
100000 1
1 99999

Sample Output 3

Copy
IMPOSSIBLE

Sample Input 4

Copy
5 5
1 3
4 5
2 3
2 4
1 4

Sample Output 4

Copy
POSSIBLE

You can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.

题目大意:给出一个有向图,问1->n能否两步到达
解题思路:dfs搜索,或者判断1的下一个结点和n的上一个结点是否有公共的就行了

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<vector>
 4 #include<map>
 5 #include<set>
 6 #include<queue>
 7 #include<cmath>
 8 #include<string>
 9 #include<cstring>
10 #include<algorithm>
11 using namespace std;
12 typedef long long LL;
13 const LL INF=1e18;
14 const int MAXN=2e5+100;
15 const double eps=1e-10;
16 bool vis[MAXN];
17 int main()
18 {
19     int n,m;
20     while(scanf("%d%d",&n,&m)!=EOF){
21         int u,v;
22         bool flag=false;
23         for(int i=1;i<=n;i++)
24             vis[i]=false;
25         for(int i=1;i<=m;i++){
26             scanf("%d%d",&u,&v);
27             if(flag) continue;
28             if(u==1){
29                 if(vis[v]){
30                     flag=true;
31                 }
32                 vis[v]=true;
33             }else if(v==n){
34                 if(vis[u]){
35                     flag=true;
36                 }
37                 vis[u]=true;
38             }
39         }
40         if(flag) printf("POSSIBLE\n");
41         else printf("IMPOSSIBLE\n");
42     }
43     return 0;
44 }
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<vector>
 4 #include<map>
 5 #include<set>
 6 #include<queue>
 7 #include<cmath>
 8 #include<string>
 9 #include<cstring>
10 #include<algorithm>
11 using namespace std;
12 typedef long long LL;
13 const LL INF=1e18;
14 const int MAXN=2e5+5;
15 const double eps=1e-10;
16 int tot;
17 int head[MAXN];
18 int n,m;
19 struct Edge
20 {
21     int from,to,nxt;
22 }e[MAXN];
23 void addedge(int u,int v)
24 {
25     e[tot].from=u;
26     e[tot].to=v;
27     e[tot].nxt=head[u];
28     head[u]=tot++;
29 }
30 bool dfs(int s,int t,int k)
31 {
32     if(s==n&&k==2) return true;
33     for(int i=head[s];i!=-1;i=e[i].nxt){
34         int to=e[i].to;
35         if(dfs(to,n,k+1)) return true;
36     }
37     return false;
38 }
39 int main()
40 {
41     int d,k;
42     while(scanf("%d%d",&n,&m)!=EOF){
43         memset(head,-1,sizeof(head));
44         int u,v;
45         for(int i=1;i<=m;i++){
46             scanf("%d%d",&u,&v);
47             addedge(u,v);
48         }
49         if(dfs(1,n,0))
50             printf("POSSIBLE\n");
51         else printf("IMPOSSIBLE\n");
52     }
53     return 0;
54 }

D - Decrease (Contestant ver.)


Time limit : 2sec / Memory limit : 256MB

Score : 600 points

Problem Statement

We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N−1 or smaller.

  • Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.

It can be proved that the largest element in the sequence becomes N−1 or smaller after a finite number of operations.

You are given an integer K. Find an integer sequence ai such that the number of times we will perform the above operation is exactly K. It can be shown that there is always such a sequence under the constraints on input and output in this problem.

Constraints

  • 0≤K≤50×1016

Input

Input is given from Standard Input in the following format:

K

Output

Print a solution in the following format:

N
a1 a2 ... aN

Here, 2≤N≤50 and 0≤ai≤1016+1000 must hold.


Sample Input 1

Copy
0

Sample Output 1

Copy
4
3 3 3 3

Sample Input 2

Copy
1

Sample Output 2

Copy
3
1 0 3

Sample Input 3

Copy
2

Sample Output 3

Copy
2
2 2

The operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].


Sample Input 4

Copy
3

Sample Output 4

Copy
7
27 0 0 0 0 0 0

Sample Input 5

Copy
1234567894848

Sample Output 5

Copy
10
1000 193 256 777 0 1 1192 1234567891011 48 425

题解:(构造)从n个t变化到n个t-1,恰好要n步,并且其中每一步的max值都>=t,所以把50个49当成最终局面,从这里开始,根据输入的K计算初始局面即可
此题题解转自:http://www.cnblogs.com/autsky-jadek/
 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 typedef long long ll;
 5 ll K;
 6 int main(){
 7     cin>>K;
 8     int n=50;
 9     printf("%d\n",n);
10     ll a=K/(ll)n; ll b=K%(ll)n;
11     int cnt=0;
12     for(int i=1;i<=(int)b;++i){
13         ++cnt;
14         cout<<49ll+a+((ll)n-(b-1ll))<<(cnt==n ? '\n' : ' ');
15     }
16     for(int i=1;i<=n-(int)b;++i){
17         ++cnt;
18         cout<<49ll+a-b<<(cnt==n ? '\n' : ' ');
19     }
20     return 0;
21 }

 

posted @ 2017-07-30 10:25  wydxry  阅读(513)  评论(0编辑  收藏  举报
Live2D