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

题目大意:

对于每一个数据,有一个数字代表下一行的字符串的长度。
一个字符串里可能有很多个单词,问在这其中的单词里,大写字母最多的单词中有多少个大写字母。

大致思路:

纯水题,记录一下已经读进去的字符串长度,到了n直接跳出。
每一个单词扫一遍,记录大写字母的个数。与记录的最大值取一个max
然后输出结果就可以了。

代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    //freopen("in.txt","r",stdin);
    int n,len=0,maxn=0,cnt;
    char str[210];
    cin>>n;
    while(cin>>str)
    {
        cnt=0;
        int l=strlen(str);
        for(int i=0;i<l;++i)
            if(isupper(str[i]))
                cnt++;
        maxn=max(maxn,cnt);

        len+=l;
        if(len>=n)
            break;
        len++;
    }
    cout<<maxn<<endl;
    return 0;
}

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码之和整除。
如果不能,则肯定不合法
然后看矩形的第一个字母是什么,然后通过扫描矩阵来确定第一个区域的形状。是横着摆还是竖着摆。有一个结论:如果能三分一个矩形,则这个形状至少横着占满一行或者竖着占满一列。所以可以把第一个区域的长宽与横竖确定。然后再区域内扫一遍看是否有其他颜色的点。
之后再根据形状来扫另外的区域,看是否都合法。

代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn=110;
char mart[maxn][maxn];
int cnt=0,c,l;
int n,m,num=0;
bool flag_line=true;//判断形状的flag
bool rpp()//判断第一个区域的形状
{
    char color=mart[1][1];
    for(int i=1;i<=m;++i)
        if(color!=mart[1][i]){
            flag_line=false;
            l=i-1;
            break;
        }
    for(int i=1;i<=n;++i){
        if(color!=mart[i][1]){
            if(!flag_line)
                return false;
            c=i-1;
            break;
        }
    }
    for(int i=1;i<=c;++i)
        for(int j=1;j<=l;++j)
            if(color!=mart[i][j])
                return false;
    return true;
}
bool other()
{
    char color1=mart[1][1];
    char color2;
    if(flag_line){
        //
        color2=mart[1+c][1];
        for(int i=1+c;i<=n&&i<=2*c;++i)
            for(int j=1;j<=m;++j)
                if(color2!=mart[i][j]){
                    return false;
                }

        color2=mart[1+2*c][1];
        for(int i=1+2*c;i<=n;++i)
            for(int j=1;j<=m;++j)
                if(color2!=mart[i][j]){
                    return false;
                }
    }else{
        color2=mart[1][1+l];
        for(int i=1;i<=n;++i)
            for(int j=1+l;j<=2*l&&j<=m;++j)
                if(color2!=mart[i][j])
                    return false;

        color2=mart[1][1+2*l];
        for(int i=1;i<=n;++i)
            for(int j=1+l*2;j<=m;++j)
                if(color2!=mart[i][j])
                    return false;
    }
    return true;
}
int main()
{
    ios::sync_with_stdio(false);
    //freopen("in.txt","r",stdin);
    cin>>n>>m;
    c=n;
    l=m;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j){
            cin>>mart[i][j];
            num+=mart[i][j];
        }
    if(num%('R'+'G'+'B'))
        cout<<"NO"<<endl;
    else if(!rpp())
        cout<<"NO"<<endl;
    else if(!other())
        cout<<"NO"<<endl;
    else
        cout<<"YES"<<endl;
    return 0;
}

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;
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值