7A - Kalevitch and Chess
2 seconds
64 megabytes
standard input
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 a 8 × 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, and B 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.
WWWBWWBW
BBBBBBBB
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW
3
WWWWWWWW
BBBBBBBB
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW
1
这题挺简单,输入8x8的矩阵,画家一笔8格。问画家最少画几笔。
下面对比下我和高手代码上扎心的差距:
我的代码:
1 #include<bits/stdc++.h>
2 #define Max 9
3 using namespace std;
4
5 char st[Max][Max];
6 int row[Max],col[Max];
7 int main()
8 {
9 int ans=0,flag=0;
10
11 for(int i=0;i<Max-1;i++)
12 scanf("%s",st[i]);
13 for(int i=0;i<Max-1;i++)
14 {
15 for(int k=0;k<Max-1;k++)
16 {
17 if(st[i][k]!='B')
18 {
19 row[i]=1;
20 break;
21 }
22 }
23 }
24 for(int i=0;i<Max-1;i++)
25 {
26 for(int k=0;k<Max-1;k++)
27 {
28 if(st[k][i]!='B')
29 {
30 col[i]=1;
31 break;
32 }
33 }
34 }
35 for(int i=0;i<Max-1;i++)
36 {
37 if(!col[i])
38 ans++;
39 if(!row[i])
40 ans++;
41 }
42 if(ans==16)
43 printf("8\n");
44 else
45 printf("%d\n",ans);
46 return 0;
47 }
别人家的代码:
1 #include <bits/stdc++.h>
2 using namespace std;
3 char s[8];
4 int a,b,c;
5 int main(){
6 for(int i=0;i<8;i++){
7 c=0;
8 for(int j=0;j<8;j++){
9 cin>>s[j];
10 if(s[j]=='B')c++;
11 }
12 if(c==8)a++;
13 else b=c;
14 }
15 cout<<a+b<<endl;
16 }
7A - Kalevitch and Chess的更多相关文章
- Codeforces Beta Round #7 A. Kalevitch and Chess 水题
A. Kalevitch and Chess 题目连接: http://www.codeforces.com/contest/7/problem/A Description A famous Berl ...
- 组合数学 UVa 11538 Chess Queen
Problem A Chess Queen Input: Standard Input Output: Standard Output You probably know how the game o ...
- hdu4405 Aeroplane chess
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 5742 Chess SG函数博弈
Chess Problem Description Alice and Bob are playing a special chess game on an n × 20 chessboard. ...
- POJ2425 A Chess Game[博弈论 SG函数]
A Chess Game Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3917 Accepted: 1596 Desc ...
- HDU 4832 Chess (DP)
Chess Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- Emacs-24.1 + ECB-2.40 + cscope-15.7a + cedet 无root权限指定目录安装与配置
emacs等安装在-/INSTALL目录下,在-下新建一个INSTALL目录. 1. emacs-24.1.tar.gz ecb-2.40.tar.gz cscope-15.7a.tar.bz2下载到 ...
- 2016暑假多校联合---A Simple Chess
2016暑假多校联合---A Simple Chess Problem Description There is a n×m board, a chess want to go to the po ...
- HDU5724 Chess(SG定理)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5724 Description Alice and Bob are playing a spe ...
随机推荐
- 消息队列之kafka
消息队列之activeMQ 消息队列之RabbitMQ 1.kafka介绍 kafka是由scala语言开发的一个多分区,多副本的并且居于zookeeper协调的分布式的发布-订阅消息系统.具有高吞吐 ...
- VS2019中scanf返回值被忽略的问题及其解决方法
目录 [问题](#昨天在使用Visual Studio 2019编写C语言程序时遇到了scanf返回值被忽略问题) 问题原因 方法① 方法② 方法③ 方法④ 昨天在使用Visual Studio 20 ...
- 提供个HDFS的目录的路径,对该目录进行创建和删除操作。创建目录时,如果目录 文件所在目录不存在则自动创建相应目录;删除目录时,由用户指定当该目录不为空时是否还删 除该目录
import java.io.IOException; import java.util.Scanner; import org.apache.hadoop.fs.*; public class G_ ...
- 对话 CTO〡用声音在一起,听荔枝 CTO 丁宁聊 UGC 声音互动平台的技术世界 原创 王颖奇 极客公园 2018-12-01
https://mp.weixin.qq.com/s/jfHFXZpzbAEbHKkCMSev6w 对话 CTO〡用声音在一起,听荔枝 CTO 丁宁聊 UGC 声音互动平台的技术世界 原创 王颖奇 极 ...
- Excel导出中HttpServletResponse消息头参数设置
response.setCharacterEncoding("UTF-8"); //编码格式为UTF-8 response.setContentType("applica ...
- 函数式编程(json、pickle、shelve)
本节内容 前言 json模块 pickle模块 shelve模块 总结 一.前言 1. 现实需求 每种编程语言都有各自的数据类型,其中面向对象的编程语言还允许开发者自定义数据类型(如:自定义类),Py ...
- f5 http和tcp_80 monitor
f5上的http和tcp_80 monitor是有区别的.假如使用http为monitor,即使80端口是通的,但是有的情况f5也会根据http的访问返回值情况判断站点不可用. 如, telnet I ...
- Vue-Cli程序环境搭建
环境搭建 ##1.下载node.js cmd输入 node -v 查看是否能够正确打印出版本号 cmd输入 npm -v 查看是否能够正确打印出版本号 ##2.安装node.js淘宝镜像加速器 ### ...
- DEDECMS:将dedecms系统的data目录迁移到web以外目录
dedecms系统的data目录是系统缓存和配置文件的目录,一般都有可以读写的权限,只要是能够写入的目录都可能存在安全隐患,很多站长甚至给予这个目录可执行的权限,更是非常危险,所以我们建议将这个dat ...
- 你必须知道的关于操作系统的N个概念!
本文全部概念都是基于<计算机操作系统教程(第四版)>中的表述归纳而成. 操作系统的任务和功能 操作系统的职能是管理和控制计算机系统中的所有硬件和软件资源,合理地组织计算机流程,并为用户提供 ...