Educational Codeforces Round 26

来源:互联网 发布:吉他歌曲教学软件 编辑:程序博客网 时间:2024/06/16 00:09

A. Text Volume
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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
7NonZERO
output
5
input
24this is zero answer text
output
0
input
24Harbour 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.


题意:就是给你一段话,一段话由多个单子组成,问那个单词的大写字母出现最多,输出这个单词大写字母的个数

思路:一遇到空格就是一个单词的结束,此时找一个最大的结果

Code:

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int n;char s[220];int main(){    while(~scanf("%d",&n))    {        getchar();        gets(s);        int maxi=0;        int maxn=0;        for(int i=0;i<n;i++)        {            if(s[i]>='A'&&s[i]<='Z')                maxi++;            if(s[i]==' ')            {                maxn=max(maxn,maxi);                maxi=0;            }        }        maxn=max(maxn,maxi);        printf("%d\n",maxn);    }    return 0;}

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 5RRRRRRRRRRBBBBBBBBBBGGGGGGGGGG
output
YES
input
4 3BRGBRGBRGBRG
output
YES
input
6 7RRRGGGGRRRGGGGRRRGGGGRRRBBBBRRRBBBBRRRBBBB
output
NO
input
4 4RRRRRRRRBBBBGGGG
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 — 21 and 1.

题意:现在有三种颜色分别是B、G、R。三个条纹由这三种颜色组成,每种条纹只有一种颜色,每种条纹尺寸大小相同,问给你一个a*b大小的纸片,能不能用这个三个条纹去装饰。现给你一个已经装饰好的纸片,问是否合理?若是输出YES,否则输出NO

思路:首先每种颜色出现次数应该相同,不相同输出NO,因为条纹大小一致。我们只需要记录每种颜色出现的起点与终点,从起点到终点遍历一次看存不存在其他颜色,若存在输出NO,然后通过起点与终点求每种颜色的面积,如果面积不一致输出NO,剩下的情况都是YES

Code:

#include<stdio.h>#include<string.h>#include<algorithm>#define Inf 1<<29using namespace std;int n,m;char a[110][110];int x,y,z;struct node{    int ql,qr,zl,zr;} b[5];int main(){    while(~scanf("%d%d",&n,&m))    {        x=0,y=0,z=0;        int flag=0;        for(int i=0; i<n; i++)        {            scanf("%s",a[i]);            for(int j=0; j<m; j++)            {                if(a[i][j]=='B')                    x++;                else if(a[i][j]=='G')                    y++;                else if(a[i][j]=='R')                    z++;            }        }        if(x!=y||x!=z||y!=z)            flag=1;        //printf("%d %d %d\n",x,y,z);        for(int i=0; i<3; i++)            {                b[i].ql=Inf;                b[i].qr=Inf;                b[i].zl=0;                b[i].zr=0;            }        for(int i=0; i<n; i++)        {            for(int j=0; j<m; j++)            {                if(a[i][j]=='B')                {                    b[0].ql=min(b[0].ql,i);                    b[0].qr=min(b[0].qr,j);                    b[0].zl=max(b[0].zl,i);                    b[0].zr=max(b[0].zr,j);                }                else if(a[i][j]=='G')                {                    b[1].ql=min(b[1].ql,i);                    b[1].qr=min(b[1].qr,j);                    b[1].zl=max(b[1].zl,i);                    b[1].zr=max(b[1].zr,j);                }                else if(a[i][j]=='R')                {                    b[2].ql=min(b[2].ql,i);                    b[2].qr=min(b[2].qr,j);                    b[2].zl=max(b[2].zl,i);                    b[2].zr=max(b[2].zr,j);                }            }        }        for(int i=b[0].ql; i<=b[0].zl; i++)        {            for(int j=b[0].qr; j<=b[0].zr; j++)            {                if(a[i][j]!='B')                    flag=1;            }        }        for(int i=b[1].ql; i<=b[1].zl; i++)        {            for(int j=b[1].qr; j<=b[1].zr; j++)            {                if(a[i][j]!='G')                    flag=1;            }        }        for(int i=b[2].ql; i<=b[2].zl; i++)        {            for(int j=b[2].qr; j<=b[2].zr; j++)            {                if(a[i][j]!='R')                    flag=1;            }        }        //printf("(%d,%d) (%d,%d)\n(%d,%d) (%d,%d)\n(%d,%d) (%d,%d)\n",b[0].ql,b[0].qr,b[0].zl,b[0].zr,b[1].ql,b[1].qr,b[1].zl,b[1].zr,b[2].ql,b[2].qr,b[2].zl,b[2].zr);        x=(b[0].zl-b[0].ql+1)*(b[0].zr-b[0].qr+1);        y=(b[1].zl-b[1].ql+1)*(b[1].zr-b[1].qr+1);        z=(b[2].zl-b[2].ql+1)*(b[2].zr-b[2].qr+1);        //printf("%d %d %d\n",x,y,z);        if(x!=y||x!=z||y!=z)            flag=1;        if(flag==1)            printf("NO\n");        else            printf("YES\n");    }    return 0;}


C. Two Seals
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 na and b (1 ≤ n, a, b ≤ 100).

Each of the next n lines contain two numbers xiyi (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 21 22 1
output
4
input
4 10 92 31 15 109 11
output
56
input
3 10 106 67 720 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.

题意:给你一个a*b的矩形,然后给你n个小矩形,问能放下多少个小矩形使得每个矩形不重复的放在a*b的矩形里面,并输出这些小矩形的面积和(注意每个小矩形可以旋转90度),要求只需要放两个矩形就好,如果一个都不能放就输出0.

思路:先放置第一个矩形(长i  宽j),从左上那个顶点开始放置,那么剩下的空间可能是i*(b-j)或者(a-i)*j,然后找一个最大面积即可

Code:

#include<stdio.h>#include<algorithm>using namespace std;int n,aa,bb;struct node{    int x,y;} a[220];bool cmp(node aa,node bb){    if(aa.x==bb.x)        return aa.y<bb.y;    return aa.x<bb.x;}int main(){    while(~scanf("%d%d%d",&n,&aa,&bb))    {        int k=0;        for(int i=0; i<n; i++)        {            int x,y;            scanf("%d%d",&x,&y);            a[k].x=x;            a[k++].y=y;        }        int maxn=0;        int flag=0;        for(int i=0; i<k; i++)        {            int x1=aa-a[i].x;            int y1=bb;            int x2=aa;            int y2=bb-a[i].y;            int z1=a[i].x*a[i].y;            int  cnt=1;            for(int j=0; j<k; j++)            {                int z2=a[j].x*a[j].y;                if(a[j].x<=x1&&a[j].y<=y1&&i!=j||a[j].x<=x2&&a[j].y<=y2&&i!=j||a[j].x<=y1&&a[j].y<=x1&&i!=j||a[j].x<=y2&&a[j].y<=x2&&i!=j)                {                    if(z1+z2<=aa*bb)                    maxn=max(maxn,z1+z2);                    cnt++;                }                if(cnt==2)                    flag=1;            }        }        if(flag==1)            printf("%d\n",maxn);        else            printf("0\n");    }    return 0;}#include<stdio.h>#include<algorithm>using namespace std;int n,k;int a[220];int b[220];int main(){    while(~scanf("%d%d",&n,&k))    {        for(int i=0; i<n; i++)        {            scanf("%d",&a[i]);            int x=a[i];            int ans=10;            while(1)            {                if((x%ans)%5==0)                {                    b[x][5]++;                    ans*=10;                }                else                    break;            }        }        return 0;    }