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.
input
7
NonZERO
output
5
input
24
this is zero answer text
output
0
input
24
Harbour Space University
output
1
题目大意:
对于每一个数据,有一个数字代表下一行的字符串的长度。
一个字符串里可能有很多个单词,问在这其中的单词里,大写字母最多的单词中有多少个大写字母。
大致思路:
纯水题,记录一下已经读进去的字符串长度,到了n直接跳出。
每一个单词扫一遍,记录大写字母的个数。与记录的最大值取一个max
然后输出结果就可以了。
代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 ios::sync_with_stdio(false); 6 //freopen("in.txt","r",stdin); 7 int n,len=0,maxn=0,cnt; 8 char str[210]; 9 cin>>n; 10 while(cin>>str) 11 { 12 cnt=0; 13 int l=strlen(str); 14 for(int i=0;i<l;++i) 15 if(isupper(str[i])) 16 cnt++; 17 maxn=max(maxn,cnt); 18 19 len+=l; 20 if(len>=n) 21 break; 22 len++; 23 } 24 cout<<maxn<<endl; 25 return 0; 26 }
B Flag of Berland
题面:
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.
题目大意:
现在有一个长宽已知的矩形。
一个合法的矩形要求是里面只有三个形状一样的区域,且分别是R,G,B这三个字母组成的。
然后给你一个矩形,让你判断是否合法
大致思路:
这个题看起来很简单,但写起来有点恶心。
首先可以知道,如果这个矩形里三个字母的数量不相等,那么肯定不合法。
所以可以在输入矩阵时将他们的ASC码记录,然后看是否能被R,G,B的ASC码之和整除。
如果不能,则肯定不合法
然后看矩形的第一个字母是什么,然后通过扫描矩阵来确定第一个区域的形状。是横着摆还是竖着摆。有一个结论:如果能三分一个矩形,则这个形状至少横着占满一行或者竖着占满一列。所以可以把第一个区域的长宽与横竖确定。然后再区域内扫一遍看是否有其他颜色的点。
之后再根据形状来扫另外的区域,看是否都合法。
代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn=110; 4 char mart[maxn][maxn]; 5 int cnt=0,c,l; 6 int n,m,num=0; 7 bool flag_line=true;//判断形状的flag 8 bool rpp()//判断第一个区域的形状 9 { 10 char color=mart[1][1]; 11 for(int i=1;i<=m;++i) 12 if(color!=mart[1][i]){ 13 flag_line=false; 14 l=i-1; 15 break; 16 } 17 for(int i=1;i<=n;++i){ 18 if(color!=mart[i][1]){ 19 if(!flag_line) 20 return false; 21 c=i-1; 22 break; 23 } 24 } 25 for(int i=1;i<=c;++i) 26 for(int j=1;j<=l;++j) 27 if(color!=mart[i][j]) 28 return false; 29 return true; 30 } 31 bool other() 32 { 33 char color1=mart[1][1]; 34 char color2; 35 if(flag_line){ 36 // 37 color2=mart[1+c][1]; 38 for(int i=1+c;i<=n&&i<=2*c;++i) 39 for(int j=1;j<=m;++j) 40 if(color2!=mart[i][j]){ 41 return false; 42 } 43 44 color2=mart[1+2*c][1]; 45 for(int i=1+2*c;i<=n;++i) 46 for(int j=1;j<=m;++j) 47 if(color2!=mart[i][j]){ 48 return false; 49 } 50 }else{ 51 color2=mart[1][1+l]; 52 for(int i=1;i<=n;++i) 53 for(int j=1+l;j<=2*l&&j<=m;++j) 54 if(color2!=mart[i][j]) 55 return false; 56 57 color2=mart[1][1+2*l]; 58 for(int i=1;i<=n;++i) 59 for(int j=1+l*2;j<=m;++j) 60 if(color2!=mart[i][j]) 61 return false; 62 } 63 return true; 64 } 65 int main() 66 { 67 ios::sync_with_stdio(false); 68 //freopen("in.txt","r",stdin); 69 cin>>n>>m; 70 c=n; 71 l=m; 72 for(int i=1;i<=n;++i) 73 for(int j=1;j<=m;++j){ 74 cin>>mart[i][j]; 75 num+=mart[i][j]; 76 } 77 if(num%('R'+'G'+'B')) 78 cout<<"NO"<<endl; 79 else if(!rpp()) 80 cout<<"NO"<<endl; 81 else if(!other()) 82 cout<<"NO"<<endl; 83 else 84 cout<<"YES"<<endl; 85 return 0; 86 }
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.
题目大意:
有一张长宽已知的矩形。
现在有很多个小矩形,长宽已知,摆放方式可以旋转90°。
现在取两个小矩形放在大矩形上,要求两个小矩形不能有互相覆盖的地方。
求可以覆盖的最大面积,如果没有合法解,输出0
大致思路:
贪心+枚举
把每一个小矩形根据面积排序。
我在开始的时候把每一个矩形(包括大矩形)的x,y按照大小排好。
这样在取第一个矩形的时候就可以贪心的让剩下的面积最大。
然后再挨个试第二个矩形,取成功之后和保存的最大值取一个max。
代码:
#include<bits/stdc++.h> using namespace std; const int maxn=110; typedef struct{ int x,y; int s; }Type; bool cmp(Type a,Type b) { return a.s>b.s; } bool check(int nx,int ny,int x,int y)//看取的矩形和现在剩下的区域能否放下 { if((nx<=x&&ny<=y)||(nx<=y&&ny<=x)) return true; return false; } int main() { //freopen("in.txt","r",stdin); Type Node[maxn]; int n,x,y; cin>>n>>x>>y; if(x>y) swap(x,y); for(int i=0;i<n;++i){ cin>>Node[i].x>>Node[i].y; if(Node[i].x>Node[i].y) swap(Node[i].x,Node[i].y); Node[i].s=Node[i].x*Node[i].y; } sort(Node,Node+n,cmp); int nx,ny,maxx=0,ans; for(int i=0;i<n-1;++i){ if(!check(Node[i].x,Node[i].y,x,y)) continue; ans=Node[i].s; if(Node[i].y<x){ nx=x-Node[i].y; ny=y-Node[i].x; }else{ nx=x-Node[i].x; ny=y-Node[i].y; } for(int j=i+1;j<n;++j){ if(check(Node[j].x,Node[j].y,nx,y)|| check(Node[j].x,Node[j].y,x,ny)){ maxx=max(maxx,ans+Node[j].s); } } } cout<<maxx<<endl; return 0; }