• Educational Codeforces Round 26 (A B C)


    A. Text Volume

    You are given a text of single-space separated words, consisting of small and capital Latin letters.

    Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.

    Calculate the volume of the given text.

    Input

    The first line contains one integer number n (1 ≤ n ≤ 200) — length of the text.

    The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.

    Output

    Print one integer number — volume of text.

    Examples
    Input
    7
    NonZERO
    Output
    5
    Input
    24
    this is zero answer text
    Output
    0
    Input
    24
    Harbour Space University
    Output
    1
    Note

    In the first example there is only one word, there are 5 capital letters in it.

    In the second example all of the words contain 0 capital letters.

    水题。

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <algorithm>
     5 #include <string>
     6 #include <queue>
     7 #include <vector>
     8 #include <set>
     9 #include <map>
    10 #define ll long long
    11 #define INF 0x3f3f3f3f
    12 #define lowbit(x) x&(-x)
    13 #define fas ios::sync_with_stdio(false)
    14 #define N 110
    15 #define M 110
    16 using namespace std;
    17 
    18 int main() {
    19     fas;
    20     int n, MAX = 0, ans = 0;
    21     char str[300];
    22     cin>>n;
    23     while(cin>>str) {
    24         ans = 0;
    25         for(int i = 0; str[i]; i ++) {
    26             if(str[i] >= 'A' && str[i] <= 'Z'){
    27                 ans ++;
    28             }
    29         }
    30         if(ans > MAX) MAX = ans;
    31     }
    32     if(ans > MAX) MAX = ans;
    33     printf("%d
    ",MAX);
    34     return 0;
    35 }
    B. Flag of Berland
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    The flag of Berland is such rectangular field n × m that satisfies following conditions:

    • Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
    • Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
    • Each color should be used in exactly one stripe.

    You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).

    Input

    The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.

    Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.

    Output

    Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).

    Examples
    Input
    6 5
    RRRRR
    RRRRR
    BBBBB
    BBBBB
    GGGGG
    GGGGG
    Output
    YES
    Input
    4 3
    BRG
    BRG
    BRG
    BRG
    Output
    YES
    Input
    6 7
    RRRGGGG
    RRRGGGG
    RRRGGGG
    RRRBBBB
    RRRBBBB
    RRRBBBB
    Output
    NO
    Input
    4 4
    RRRR
    RRRR
    BBBB
    GGGG
    Output
    NO
    Note

    The field in the third example doesn't have three parralel stripes.

    Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.

    B R G 数量相同,并且只有一个区域,计下数量,然后记下B G R 出现的位置的最大(x,y)和最小(x,y) 看看这个区域的面积是否和记下的B G R的数量相同就行。。

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <algorithm>
     5 #include <string>
     6 #include <queue>
     7 #include <vector>
     8 #include <set>
     9 #include <map>
    10 #define ll long long
    11 #define INF 0x3f3f3f3f
    12 #define lowbit(x) x&(-x)
    13 #define N 110
    14 #define M 110
    15 using namespace std;
    16 char str[N][N];
    17 int main() {
    18     int n, m, B = 0, R = 0, G = 0;
    19     int xb = N, yb = N, xxb = -1, yyb = -1;
    20     int xr = N, yr = N, xxr = -1, yyr = -1;
    21     int xg = N, yg = N, xxg = -1, yyg = -1;
    22     cin>>n>>m;
    23     for(int i = 1; i <= n; i ++) cin>>str[i]+1;
    24     for(int i = 1; i <= n; i ++) {
    25         for(int j = 1; j <= m; j ++) {
    26             if(str[i][j] == 'B') {
    27                 B++;
    28                 xb = min(j, xb);
    29                 yb = min(i, yb);
    30                 xxb = max(xxb, j);
    31                 yyb = max(yyb, i);
    32             }
    33             else if(str[i][j] == 'R') {
    34                 R++;
    35                 xr = min(j, xr);
    36                 yr = min(i, yr);
    37                 xxr = max(xxr, j);
    38                 yyr = max(yyr, i);
    39             } else if(str[i][j] == 'G') {
    40                 G++;
    41                 xg = min(j, xg);
    42                 yg = min(i, yg);
    43                 xxg = max(xxg, j);
    44                 yyg = max(yyg, i);
    45             }
    46         }
    47     }
    48     // printf("%c
    ",str[1][3]);
    49     if(B != 0 && B == R && R == G) {
    50         if((yyb-yb+1)*(xxb-xb+1) == B && (yyr-yr+1)*(xxr-xr+1) == R && (yyg-yg+1)*(xxg-xg+1)==G) {
    51             printf("YES
    ");
    52         } else printf("NO
    ");
    53     } else printf("NO
    ");
    54     return 0;
    55 }
    C. Two Seals

    One very important person has a piece of paper in the form of a rectangle a × b.

    Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).

    A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?

    Input

    The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).

    Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).

    Output

    Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.

    Examples
    Input
    2 2 2
    1 2
    2 1
    Output
    4
    Input
    4 10 9
    2 3
    1 1
    5 10
    9 11
    Output
    56
    Input
    3 10 10
    6 6
    7 7
    20 5
    Output
    0
    Note

    In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.

    In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.

    In the third example there is no such pair of seals that they both can fit on a piece of paper.

    不知多少次看错题意了,我以为是可以放很多个,一直想不出来,没相同只要放两个就行了。

    用if判断下放的位置是否符合。

    --------更新线---------

    用c++写的错了,正确的是用Python写的,不想再写成C++的了,懂思路就行,有8种放法,C++写的只有4种。

     1 #python3
     2 k, n, m = map(int,input().split())
     3 x, y = [],[]
     4 for i in range(k):
     5     q, p = map(int, input().split())
     6     x.append(min(q, p))
     7     y.append(max(q, p))
     8 MAX = 0
     9 for i in range(k):
    10     for j in range(i+1,k):
    11         ok = False
    12         if x[i] + x[j] <= n and y[i] <= m and y[j] <= m:
    13             ok = True
    14         elif x[i] + y[j] <= n and y[i] <= m and x[j] <= m:
    15             ok = True
    16         elif y[i] + y[j] <= m and x[i] <= n and x[j] <= n:
    17             ok = True
    18         elif y[i] + x[j] <= m and x[i] <= n and y[j] <= n:
    19             ok = True
    20         elif y[i] + y[j] <= n and x[i] <= m and x[j] <= m:
    21             ok = True
    22         elif y[i] + x[j] <= n and x[i] <= m and y[j] <= m:
    23             ok = True
    24         elif x[i] + x[j] <= m and y[i] <= n and y[j] <= n:
    25             ok = True
    26         elif x[i] + y[j] <= m and y[i] <= n and x[j] <= n:
    27             ok = True
    28         if ok:
    29             MAX = max(MAX, x[i]*y[i] + x[j]*y[j])
    30 print(MAX)

    下面是错的

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    #include <string>
    #include <queue>
    #include <vector>
    #include <set>
    #include <map>
    #define ll long long
    #define INF 0x3f3f3f3f
    #define lowbit(x) x&(-x)
    #define N 110
    #define M 110
    using namespace std;
    struct Nod {
        int x, y, z;
    }nod[N];
    
    int main() {
        int k, n, m, x, y;
        cin >> k >> n >> m;
        if(n > m ) swap(n, m);
        for(int i = 1; i <= k; i ++) {
            cin >> x >> y;
            nod[i].x = min(x, y);
            nod[i].y = max(x, y);
            nod[i].z = x*y;
        }
        int MAX = 0;
        for(int i = 1; i <= k; i ++) {
            for(int j = i+1; j <= k; j ++) {
                if(max(nod[i].x,nod[j].x) <= n && (nod[i].y+nod[j].y) <= m)
                    MAX = max(MAX,nod[i].z+nod[j].z);
                else if((nod[i].x+nod[j].x) <= n && max(nod[i].y,nod[j].y) <= m)
                    MAX = max(MAX,nod[i].z+nod[j].z);
                else if(max(nod[i].y,nod[j].x) <= n && (nod[i].x+nod[j].y) <= m)
                    MAX = max(MAX,nod[i].z+nod[j].z);
                else if((nod[i].y+nod[j].x) <= n && max(nod[i].x,nod[j].y) <= m)
                    MAX = max(MAX, nod[i].z+nod[j].z);
            }
        }
        printf("%d
    ",MAX);
        return 0;
    }
  • 相关阅读:
    影响Scala语言设计的因素列表
    mysql查询不区分大小写问题分析和解决
    mysql基础之三:char与varchar区别,varchar(M)能存多少
    Springboot Actuator之三:spring boot健康检查对Redis的连接检查的调整
    nginx实现带参数目录域名重定向二级域名方法
    Nginx正则表达式之匹配操作符详解
    微服务API网关 vs. 传统企业级API网关
    无法打开SQL Server的连接
    URAL 1146 Maximum Sum(最大子矩阵的和 DP)
    leetCode 70.Climbing Stairs (爬楼梯) 解题思路和方法
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/7284221.html
Copyright © 2020-2023  润新知