CodeForces 7A Kalevitch and Chess
来源:互联网 发布:巴蒂斯图塔意甲数据 编辑:程序博客网 时间:2024/05/17 03:10
1、http://codeforces.com/problemset/problem/7/A
2、题目:
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.
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 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.
WWWBWWBWBBBBBBBBWWWBWWBWWWWBWWBWWWWBWWBWWWWBWWBWWWWBWWBWWWWBWWBW
3
WWWWWWWWBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
1
#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*/
- codeforces 7A - Kalevitch and Chess
- Codeforces 7A Kalevitch and Chess
- CodeForces 7A Kalevitch and Chess
- CodeForces 7A Kalevitch and Chess
- CodeForces 7A Kalevitch and Chess
- codeforces 7 A. Kalevitch and Chess
- CodeForces 7A - Kalevitch and Chess
- CodeForces 7A Kalevitch and Chess
- Codeforces 7A Kalevitch and Chess
- 7A Kalevitch and Chess
- Codeforces Beta Round #7 A. Kalevitch and Chess
- CodeForces - 7A Kalevitch and Chess(搜索?!模拟!)
- A. Kalevitch and Chess
- code forces 7A Kalevitch and Chess
- 【取巧遍历】#7 A. Kalevitch and Chess
- CF 7A Kalevitch and Chess
- cf 7a Kalevitch and Chess
- A. Kalevitch and Chess【思维】
- NYOJ-891-找点
- 表达式二叉树
- 在VS2010中开发ActiveX控件设置测试容器的方式 .
- 写给笨人的法线贴图原理
- hdu 3006 位运算
- CodeForces 7A Kalevitch and Chess
- C 语言中基本数据类型的sizeof大小
- 不走寻常路的“硅谷”
- 第26天
- TCP状态详解
- 多通道光纤信号高速采集记录存储回放系统
- Qt QString类型 转换为 const char*
- spring mvc与mybatis事务整合
- 每天坚持写点东西把!