CodeForces 7A Kalevitch and Chess

来源:互联网 发布:巴蒂斯图塔意甲数据 编辑:程序博客网 时间:2024/05/17 03:10

1、http://codeforces.com/problemset/problem/7/A

2、题目:

A. Kalevitch and Chess
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.

As before, the chessboard is a square-checkered board with the squares arranged in a8 × 8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke.

Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements.

It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task.

Input

The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements,W character stands for a white square, andB character — for a square painted black.

It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row).

Output

Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.

Sample test(s)
Input
WWWBWWBWBBBBBBBBWWWBWWBWWWWBWWBWWWWBWWBWWWWBWWBWWWWBWWBWWWWBWWBW
Output
3
Input
WWWWWWWWBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
Output
1
3、AC代码:

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int nr[10],nc[10];int main(){    char a[10][10];    for(int i=1;i<=8;i++)    {        for(int j=1;j<=8;j++)        {            scanf("%c",&a[i][j]);        }        getchar();    }    int r=0;    int c=0;    memset(nr,0,sizeof(nr));    memset(nc,0,sizeof(nc));    for(int i=1;i<=8;i++)    {        int flag=0;        for(int j=1;j<=8;j++)        {            if(a[i][j]=='W')            flag=1;        }        if(flag==0)        {            r++;            nr[i]=1;        }    }    for(int j=1;j<=8;j++)    {        int flag=0;        for(int i=1;i<=8;i++)        {            if(a[i][j]=='W')            flag=1;        }        if(flag==0)        {            nc[j]=1;            c++;        }    }    //printf("%d %d\n",r,c);    if(r>c)    {        int cnt=0;        for(int i=1;i<=8;i++)        {            if(nr[i]==1)            {                for(int j=1;j<=8;j++)                a[i][j]='W';            }        }        for(int i=1;i<=8;i++)        {            if(nc[i]==1)            {                for(int j=1;j<=8;j++)                {                    if(a[j][i]=='B')                    {                        cnt++;                        break;                    }                }            }        }        printf("%d\n",cnt+r);    }    else    {        int cnt=0;        for(int j=1;j<=8;j++)        {            if(nc[j]==1)            {                for(int i=1;i<=8;i++)                {                    a[i][j]='W';                }            }        }        for(int i=1;i<=8;i++)        {            if(nr[i]==1)            {                for(int j=1;j<=8;j++)                {                    if(a[i][j]=='B')                    {                        cnt++;                        break;                    }                }            }        }        printf("%d\n",cnt+c);    }    return 0;}/*BBBBBBBBBWWWWWWWBWWWWWWWBWWWWWWWBWWWWWWWBWWWWWWWBWWWWWWWBWWWWWWW*/


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 想在京东商城开个网店怎么办呢 京东买了东西收货了不想要了怎么办 京东转卖的商品有问题怎么办 如果衣服下架了然后有退货怎么办 想买二手车可没有懂车的人怎么办 买车的时候异地车牌回家怎么办 天猫下单显示下单人数太多券怎么办 英雄联盟进入游戏后无限崩溃怎么办 打开电视显示百度影棒打不开怎么办 家里路由器网速一会快一会慢怎么办 用快看影视下载电影网速太慢怎么办 苹果手机下载东西网速特别慢怎么办 网上买重庆时时彩输了很多钱怎么办 找不到自己在哪个平台借过钱怎么办 九游账号绑定手机之前绑定的怎么办 九游充过钱的游戏忘了游戏名怎么办 百度网盘密码忘了申诉不了怎么办 手机号被别人注册了百度账号怎么办 快手被盗找回时出来重置密码怎么办 魅族账号密码和密保都忘记了怎么办 vivo账号的密保问题忘了怎么办 oppo账号密保问题忘了怎么办 小米手机刷了机忘了账号密码怎么办 忘了小米账号的密码是多少怎么办 千牛账号在手机上被限制登录怎么办 违规的千牛账号被限制登录了怎么办 苹果id和锁屏密码忘记了怎么办 感应门的编程密码忘记了怎么办 交易猫买的号被找回了怎么办 uc上我的小说看不了怎么办 微信零钱忘记密码没有银行卡怎么办 九游平台冻结提不了现怎么办 计算机考试报名登录名忘记了怎么办 云顶扑克提现怎么提不出来怎么办 微信正在下载一直0kb怎么办 守望先锋运行时出现意外错误怎么办 信用卡暂停使用怎么办还能恢复吗 新刷乳胶漆墙面一碰一个坑怎么办 夏天开空调冻着了头疼打喷嚏怎么办 桑蚕丝衣服被沐浴露退了色怎么办 空间被别人知道了密码登录了怎么办