zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 068 (A B C D)

    A - ABCxxx

    水题。

    1 #include <iostream>
    2 using namespace std;
    3 int main(){
    4     int n;
    5     cin>>n;
    6     cout << "ABC" << n << endl;
    7     return 0;
    8 }

    B - Break Number

    水题。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int main(){
     4     int n;
     5     cin >> n;
     6     int x = 1;
     7     while(x <= n) x<<=1;
     8     printf("%d
    ",x>>1);
     9     return 0;
    10 }

    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

    • 3N200 000
    • 1M200 000
    • 1ai<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.

    把与1和n相连的点分别放在两个集合里。

    只要这两个集合就一个公共数就是POSSIBLE,否则就是IMPOSSIBLE。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 int main(){
     5     int n, m;
     6     cin>>n>>m;
     7     set<int> st,st1;
     8     for(int i = 1; i <= m; i ++) {
     9         int x, y;
    10         cin >> x >> y;
    11         if(x == 1) st.insert(y);
    12         if(y == 1) st.insert(x);
    13         if(x == n) st1.insert(y);
    14         if(y == n) st1.insert(x);
    15     }
    16     set<int>::iterator it;
    17     for(it = st.begin(); it != st.end(); it ++) {
    18         if(st1.count((*it))){
    19             return 0*printf("POSSIBLE
    ");
    20         }
    21     }
    22     printf("IMPOSSIBLE
    ");
    23     return 0;
    24 }

    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 N1 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 N1 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

    • 0K50×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, 2N50 and 0ai1016+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].

    直接让N等于50,k=0是就是 0,1,2,4...49。k = 1时就是50,0,1,2,....48。k = 2 时就是49,50,0,1,2...47。50一个循环就都加1,k=50 就是1,2,3,...50

     1 #include <bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 ll a[55];
     5 int main() {
     6     ll n;
     7     cin >> n;
     8     for(int i = 1; i <= 50; i ++) {
     9         a[i] = n/50LL + i - 1;
    10     }
    11     n %= 50;
    12     for(int i = 1; 1LL*i <= n; i ++) {
    13         for(int j = 1; j <= 50; j ++)
    14             a[j]--;
    15         a[i] += 51;
    16     }
    17     cout << 50 << endl;
    18     for(int i = 1; i < 50; i ++)cout << a[i] << ' ';
    19     cout << a[50] << endl;
    20     return 0;
    21 }
  • 相关阅读:
    回调函数 协程
    网络编程 之线程
    并发编程 之进程相关
    并发编程的理论 python中实现多进程
    基于tcp的粘包处理终极版本
    基于socket的网络编程
    数据分析
    zabbix从入门到放弃
    Linux
    Django
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/7258433.html
Copyright © 2011-2022 走看看