首页 > 代码库 > Educational Codeforces Round 26 (A B C)
Educational Codeforces Round 26 (A B C)
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.
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.
Print one integer number — volume of text.
7
NonZERO
5
24
this is zero answer text
0
24
Harbour Space University
1
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\n",MAX); 34 return 0; 35 }
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).
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.
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
YES
4 3
BRG
BRG
BRG
BRG
YES
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
NO
4 4
RRRR
RRRR
BBBB
GGGG
NO
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\n",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\n"); 52 } else printf("NO\n"); 53 } else printf("NO\n"); 54 return 0; 55 }
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?
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).
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
2 2 2
1 2
2 1
4
4 10 9
2 3
1 1
5 10
9 11
56
3 10 10
6 6
7 7
20 5
0
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判断下放的位置是否符合。
#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\n",MAX); return 0; }
Educational Codeforces Round 26 (A B C)