zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 096

    A - Day of Takahashi


    Time limit : 2sec / Memory limit : 256MB

    Score: 100 points

    Problem Statement

    In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
    For example, May 32018 is written as 2018-5-3, or 5-3 without the year.

    In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
    How many days from 2018-1-1 through 2018-a-b are Takahashi?

    Constraints

    • a is an integer between 1 and 12 (inclusive).
    • b is an integer between 1 and 31 (inclusive).
    • 2018-a-b is a valid date in Gregorian calendar.

    Input

    Input is given from Standard Input in the following format:

    a b
    

    Output

    Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.


    Sample Input 1

    Copy
    5 5
    

    Sample Output 1

    Copy
    5
    

    There are five days that are Takahashi: 1-12-23-34-4 and 5-5.


    Sample Input 2

    Copy
    2 1
    

    Sample Output 2

    Copy
    1
    

    There is only one day that is Takahashi: 1-1.


    Sample Input 3

    Copy
    11 30
    

    Sample Output 3

    Copy
    11
    

    There are eleven days that are Takahashi: 1-12-23-34-45-56-67-78-89-910-10 and 11-11.

     1 #include <iostream>
     2  
     3 using namespace std;
     4  
     5 int main(){
     6     int a,b;
     7     cin>>a>>b;
     8     cout<<(b>=a?a:(a-1))<<endl;
     9     return 0;
    10 }

    B - Maximum Sum


    Time limit : 2sec / Memory limit : 256MB

    Score: 200 points

    Problem Statement

    There are three positive integers AB and C written on a blackboard. E869120 performs the following operation K times:

    • Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.

    What is the largest possible sum of the integers written on the blackboard after K operations?

    Constraints

    • A,B and C are integers between 1 and 50 (inclusive).
    • K is an integer between 1 and 10 (inclusive).

    Input

    Input is given from Standard Input in the following format:

    A B C
    K
    

    Output

    Print the largest possible sum of the integers written on the blackboard after K operations by E869220.


    Sample Input 1

    Copy
    5 3 11
    1
    

    Sample Output 1

    Copy
    30
    

    In this sample, 5,3,11 are initially written on the blackboard, and E869120 can perform the operation once.
    There are three choices:

    1. Double 5: The integers written on the board after the operation are 10,3,11.
    2. Double 3: The integers written on the board after the operation are 5,6,11.
    3. Double 11: The integers written on the board after the operation are 5,3,22.

    If he chooses 3., the sum of the integers written on the board afterwards is 5+3+22=30, which is the largest among 1. through 3.


    Sample Input 2

    Copy
    3 3 4
    2
    

    Sample Output 2

    Copy
    22
    

    E869120 can perform the operation twice. The sum of the integers eventually written on the blackboard is maximized as follows:

    • First, double 4. The integers written on the board are now 3,3,8.
    • Next, double 8. The integers written on the board are now 3,3,16.

    Then, the sum of the integers eventually written on the blackboard is 3+3+16=22.

     1 #include <iostream>
     2 #define ll long long int
     3 using namespace std;
     4  
     5 int main(){
     6     ll a,b,c,k;
     7     cin>>a>>b>>c>>k;
     8     ll x = max(c,max(a,b));
     9     ll shit = a + b + c - x;
    10     while(k--){
    11         x<<=1;
    12     }
    13     cout<<x+shit<<endl;
    14     return 0;
    15 }

    C - Grid Repainting 2


    Time limit : 2sec / Memory limit : 256MB

    Score: 300 points

    Problem Statement

    We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i,j).
    Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i,j) black when si,j= #, and to make Square (i,j) white when si,j= ..
    However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.
    Determine if square1001 can achieve his objective.

    Constraints

    • H is an integer between 1 and 50 (inclusive).
    • W is an integer between 1 and 50 (inclusive).
    • For every (i,j) (1≤iH,1≤jW)si,j is # or ..

    Input

    Input is given from Standard Input in the following format:

    H W
    s1,1s1,2s1,3…s1,W
    s2,1s2,2s2,3…s2,W
      :   :
    sH,1sH,2sH,3…sH,W
    

    Output

    If square1001 can achieve his objective, print Yes; if he cannot, print No.


    Sample Input 1

    Copy
    3 3
    .#.
    ###
    .#.
    

    Sample Output 1

    Copy
    Yes
    

    One possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.


    Sample Input 2

    Copy
    5 5
    #.#.#
    .#.#.
    #.#.#
    .#.#.
    #.#.#
    

    Sample Output 2

    Copy
    No
    

    square1001 cannot achieve his objective here.


    Sample Input 3

    Copy
    11 11
    ...#####...
    .##.....##.
    #..##.##..#
    #..##.##..#
    #.........#
    #...###...#
    .#########.
    .#.#.#.#.#.
    ##.#.#.#.##
    ..##.#.##..
    .##..#..##.
    

    Sample Output 3

    Copy
    Yes
    

     

     1 #include <iostream>
     2 #define ll long long int
     3 #define N 55
     4 using namespace std;
     5 char s[N][N];
     6 int dir[4][2]={0,1,1,0,0,-1,-1,0};
     7 int a,b;
     8  
     9 bool search(int x,int y){
    10     for(int i=0;i<4;i++){
    11         int xx = x+dir[i][0];
    12         int yy = y+dir[i][1];
    13         if(xx>=0&&xx<a&&y>=0&&y<b){
    14             if(s[xx][yy]=='#')
    15                 return true;
    16         }
    17     }
    18     return false;
    19 }
    20 int main(){
    21     cin>>a>>b;
    22     for(int i=0;i<a;i++)
    23         for(int j=0;j<b;j++)
    24             cin>>s[i][j];
    25     for(int i=0;i<a;i++){
    26         for(int j=0;j<b;j++){
    27             if(s[i][j]=='#'){
    28                 bool prime = search(i,j);
    29                 if(!prime){
    30                     return 0*printf("No
    ");
    31                 }
    32             }
    33         }
    34     }
    35     printf("Yes
    ");
    36     return 0;
    37 }

    D - Five, Five Everywhere


    Time limit : 2sec / Memory limit : 256MB

    Score: 400 points

    Problem Statement

    Print a sequence a1,a2,…,aN whose length is N that satisfies the following conditions:

    • ai (1≤iN) is a prime number at most 55 555.
    • The values of a1,a2,…,aN are all different.
    • In every choice of five different integers from a1,a2,…,aN, the sum of those integers is a composite number.

    If there are multiple such sequences, printing any of them is accepted.

    Notes

    An integer N not less than 2 is called a prime number if it cannot be divided evenly by any integers except 1 and N, and called a composite number otherwise.

    Constraints

    • N is an integer between 5 and 55 (inclusive).

    Input

    Input is given from Standard Input in the following format:

    N
    

    Output

    Print N numbers a1,a2,a3,…,aN in a line, with spaces in between.


    Sample Input 1

    Copy
    5
    

    Sample Output 1

    Copy
    3 5 7 11 31
    

    Let us see if this output actually satisfies the conditions.
    First, 35711 and 31 are all different, and all of them are prime numbers.
    The only way to choose five among them is to choose all of them, whose sum is a1+a2+a3+a4+a5=57, which is a composite number.
    There are also other possible outputs, such as 2 3 5 7 1311 13 17 19 31 and 7 11 5 31 3.


    Sample Input 2

    Copy
    6
    

    Sample Output 2

    Copy
    2 3 5 7 11 13
    
    • 23571113 are all different prime numbers.
    • 2+3+5+7+11=28 is a composite number.
    • 2+3+5+7+13=30 is a composite number.
    • 2+3+5+11+13=34 is a composite number.
    • 2+3+7+11+13=36 is a composite number.
    • 2+5+7+11+13=38 is a composite number.
    • 3+5+7+11+13=39 is a composite number.

    Thus, the sequence 2 3 5 7 11 13 satisfies the conditions.


    Sample Input 3

    Copy
    8
    

    Sample Output 3

    Copy
    2 5 7 13 19 37 67 79

    要想5个数任意一个都可以被整除,不如就规定好被5整除,那么每个数只要n×5+1就行了。
     1 #include <iostream>
     2 using namespace std;
     3 int an[55566];
     4 void search() {
     5     an[0] = 1,an[1] = 1;
     6     for(int i=2;i<=55555;i++){
     7         if(!an[i]){
     8             for(int j=2;j*i<=55555;j++){
     9                 an[i*j] = 1;
    10             }
    11         }
    12     }
    13 }
    14 int main() {
    15   int n, count = 2;
    16   search();
    17   cin >> n;
    18   int prime[n];
    19   for (int i = 0; i < n;) {
    20     if ( !an[count] && count % 5 == 1) {
    21       prime[i] = count;
    22       i++;
    23     }
    24     count++;
    25   }
    26   for (int i = 0; i < n; i++) {
    27     cout << prime[i] <<" ";
    28   }
    29   cout<<endl;
    30   return 0;
    31 }
    32 #include <iostream>
    33 using namespace std;
    34 int an[55566];
    35 void search() {
    36     an[0] = 1,an[1] = 1;
    37     for(int i=2;i<=55555;i++){
    38         if(!an[i]){
    39             for(int j=2;j*i<=55555;j++){
    40                 an[i*j] = 1;
    41             }
    42         }
    43     }
    44 }
    45 int main() {
    46   int n, count = 2;
    47   search();
    48   cin >> n;
    49   int prime[n];
    50   for (int i = 0; i < n;) {
    51     if ( !an[count] && count % 5 == 1) {
    52       prime[i] = count;
    53       i++;
    54     }
    55     count++;
    56   }
    57   for (int i = 0; i < n; i++) {
    58     cout << prime[i] <<" ";
    59   }
    60   cout<<endl;
    61   return 0;
    62 }
  • 相关阅读:
    Base64 编解码
    MFC:CTime类和CTimeSpan类
    VC对话框实现添加滚动条实现滚动效果
    组合框控件 -- CComboBox
    快速排序
    归并排序
    插入排序
    堆排序
    Mozilla新特性只支持https网站,再次推动SSL证书普及
    企业如何选择最佳的SSL
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/8996849.html
Copyright © 2011-2022 走看看