• AtCoder Beginner Contest 069 ABCD题


    题目链接:http://abc069.contest.atcoder.jp/assignments

    A - K-City


    Time limit : 2sec / Memory limit : 256MB

    Score : 100 points

    Problem Statement

    In K-city, there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?

    Constraints

    • 2≤n,m≤100

    Input

    Input is given from Standard Input in the following format:

    n m
    

    Output

    Print the number of blocks in K-city.


    Sample Input 1

    Copy
    3 4
    

    Sample Output 1

    Copy
    6
    

    There are six blocks, as shown below:

    9179be829dc9810539213537d4c7398c.png

    Sample Input 2

    Copy
    2 2
    

    Sample Output 2

    Copy
    1
    

    There are one block, as shown below:

    997bfafa99be630b54d037225a5c68ea.png
    题解:水题
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <string>
     5 using namespace std;
     6 int main()
     7 {
     8     int n,m;
     9     while(cin>>n>>m){
    10         cout<<(n-1)*(m-1)<<endl;
    11     }
    12     return 0;
    13 }
    View Code

    B - i18n


    Time limit : 2sec / Memory limit : 256MB

    Score : 200 points

    Problem Statement

    The word internationalization is sometimes abbreviated to i18n. This comes from the fact that there are 18 letters between the first i and the last n.

    You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.

    Constraints

    • 3≤|s|≤100 (|s| denotes the length of s.)
    • s consists of lowercase English letters.

    Input

    Input is given from Standard Input in the following format:

    s
    

    Output

    Print the abbreviation of s.


    Sample Input 1

    Copy
    internationalization
    

    Sample Output 1

    Copy
    i18n
    

    Sample Input 2

    Copy
    smiles
    

    Sample Output 2

    Copy
    s4s
    

    Sample Input 3

    Copy
    xyz
    

    Sample Output 3

    Copy
    x1z
    

     题解:水题

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <string>
     5 using namespace std;
     6 int main()
     7 {
     8     string a;
     9     while(cin>>a){
    10         int len=a.length();
    11         cout<<a[0]<<len-2<<a[len-1]<<endl;
    12     }
    13     return 0;
    14 }

    C - 4-adjacent


    Time limit : 2sec / Memory limit : 256MB

    Score : 400 points

    Problem Statement

    We have a sequence of length Na=(a1,a2,…,aN). Each ai is a positive integer.

    Snuke's objective is to permute the element in a so that the following condition is satisfied:

    • For each 1≤iN−1, the product of ai and ai+1 is a multiple of 4.

    Determine whether Snuke can achieve his objective.

    Constraints

    • 2≤N≤105
    • ai is an integer.
    • 1≤ai≤109

    Input

    Input is given from Standard Input in the following format:

    N
    a1 a2  aN
    

    Output

    If Snuke can achieve his objective, print Yes; otherwise, print No.


    Sample Input 1

    Copy
    3
    1 10 100
    

    Sample Output 1

    Copy
    Yes
    

    One solution is (1,100,10).


    Sample Input 2

    Copy
    4
    1 2 3 4
    

    Sample Output 2

    Copy
    No
    

    It is impossible to permute a so that the condition is satisfied.


    Sample Input 3

    Copy
    3
    1 4 1
    

    Sample Output 3

    Copy
    Yes
    

    The condition is already satisfied initially.


    Sample Input 4

    Copy
    2
    1 1
    

    Sample Output 4

    Copy
    No
    

    Sample Input 5

    Copy
    6
    2 7 1 8 2 8
    

    Sample Output 5

    Copy
    Yes
    

     题解:找出4和2的倍数即可

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <string>
     5 #include <algorithm>
     6 using namespace std;
     7 const int N=100005;
     8 int a[N];
     9 int main()
    10 {
    11     int n;
    12     cin>>n;
    13     int t1=0,t2=0;
    14     for(int i=0;i<n;i++){
    15         cin>>a[i];
    16         if(a[i]%4==0)
    17             t1++;
    18         else if(a[i]%2==0)
    19             t2++;
    20     }
    21     int flag=0;
    22     int m;
    23     if(t2%2==0) m=t2;
    24     else m=t2-1;
    25     if((n-m)/2<=t1)flag=1;
    26     if(flag) cout<<"Yes"<<endl;
    27     else cout<<"No"<<endl;
    28     return 0;
    29 }

    D - Grid Coloring


    Time limit : 2sec / Memory limit : 256MB

    Score : 400 points

    Problem Statement

    We have a grid with H rows and W columns of squares. Snuke is painting these squares in colors 12N. Here, the following conditions should be satisfied:

    • For each i (1≤iN), there are exactly ai squares painted in Color i. Here, a1+a2+…+aN=HW.
    • For each i (1≤iN), the squares painted in Color i are 4-connected. That is, every square painted in Color i can be reached from every square painted in Color iby repeatedly traveling to a horizontally or vertically adjacent square painted in Color i.

    Find a way to paint the squares so that the conditions are satisfied. It can be shown that a solution always exists.

    Constraints

    • 1≤H,W≤100
    • 1≤NHW
    • ai≥1
    • a1+a2+…+aN=HW

    Input

    Input is given from Standard Input in the following format:

    H W
    N
    a1 a2  aN
    

    Output

    Print one way to paint the squares that satisfies the conditions. Output in the following format:

    c11  c1W
    :
    cH1  cHW
    

    Here, cij is the color of the square at the i-th row from the top and j-th column from the left.


    Sample Input 1

    Copy
    2 2
    3
    2 1 1
    

    Sample Output 1

    Copy
    1 1
    2 3
    

    Below is an example of an invalid solution:

    1 2
    3 1
    

    This is because the squares painted in Color 1 are not 4-connected.


    Sample Input 2

    Copy
    3 5
    5
    1 2 3 4 5
    

    Sample Output 2

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

    Sample Input 3

    Copy
    1 1
    1
    1
    

    Sample Output 3

    Copy
    1
    

     题解:看半天不懂撒意思 题解说是蛇形填数

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <string>
     5 #include <algorithm>
     6 using namespace std;
     7 int r,c,n,x,y,ans[200][200];
     8 int main(void)
     9 {
    10     scanf("%d%d%d",&r,&c,&n);
    11     x=1,y=1;
    12     for(int i=1,cnt;i<=n;i++){
    13         scanf("%d",&cnt);
    14         while(cnt--){
    15             ans[x][y]=i;
    16             if(y==c&&x%2==1)
    17                 y=c,x++;
    18             else if(y==1&&x%2==0)
    19                 y=1,x++;
    20             else if(x&1)
    21                 y++;
    22             else
    23                 y--;
    24         }
    25     }
    26     for(int i=1;i<=r;i++)
    27     for(int j=1;j<=c;j++)
    28         printf("%d%c",ans[i][j],j==c?'
    ':' ');
    29     return 0;
    30 }
  • 相关阅读:
    【POJ2176】Folding
    【NOIP2018】赛道修建
    优雅的文本编辑器——Sublime Text 3的搭建与使用
    【NOIP2010】乌龟棋
    【POJ3585】Accumulation Degree
    【POJ3322】Bloxorz I
    python之路_常用模块介绍
    python之路_正则表达式及re模块
    python之路_内置函数及匿名函数
    python之路_递归函数及实例讲解
  • 原文地址:https://www.cnblogs.com/wydxry/p/7349124.html
Copyright © 2020-2023  润新知