hdu 4146 Flip Game
Flip Game
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1800 Accepted Submission(s):
589
two-sided pieces placed on each of its N^2 squares. One side of each piece is
white and the other one is black and each piece is lying either it's black or
white side up. The rows are numbered with integers from 1 to N upside down; the
columns are numbered with integers from 1 to N from the left to the right.
Sequences of commands (xi, yi) are given from input, which
means that both pieces in row xi and pieces in column yi
will be flipped (Note that piece (xi, yi) will be flipped
twice here). Can you tell me how many white pieces after sequences of
commands?
Consider the following 4*4 field as an
example:
bwww
wbww
wwbw
wwwb
Here "b" denotes pieces
lying their black side up and "w" denotes pieces lying their white side
up.
Two commands are given in order: (1, 1), (4, 4). Then we can get the
final 4*4 field as follows:
bbbw
bbwb
bwbb
wbbb
So the
answer is 4 as there are 4 white pieces in the final field.
indicating the number of test cases (1 <= T <= 20).
For each case, the
first line contains a positive integer N, indicating the size of field; The
following N lines contain N characters each which represent the initial field.
The following line contain an integer Q, indicating the number of commands; each
of the following Q lines contains two integer (xi, yi),
represent a command (1 <= N <= 1000, 0 <= Q <= 100000, 1 <=
xi, yi <= N).
with 1) and the number of white pieces after sequences of commands.
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char ch[][];
int a[],b[];
int main()
{
int w,T,n,m,t,x,y,i,j,k;
scanf("%d",&T);
for(w=; w<=T; w++)
{
scanf("%d",&n);
for(i=; i<n; i++)
scanf("%s",ch[i]);
memset(a,,sizeof(a));
memset(b,,sizeof(b));
scanf("%d",&m);
while(m--)
{
scanf("%d%d",&x,&y);
x--,y--; //注意输入从(1,1)开始
a[x]++; //记录每一行变换的次数
b[y]++; //记录每一列变换的次数
if(a[x]==) //出现2,则表示变换2次,也就是没变,所以0表示不变,1表示变
a[x]=;
if(b[y]==)
b[y]=;
}
int s=;
for(i=; i<n; i++)
for(j=; j<n; j++)
{
if(a[i]+b[j]==) //只有出现1才是变换了,0或2都是保持不变
{
if(ch[i][j]=='b')
s++;
}
else
{
if(ch[i][j]=='w')
s++;
}
}
printf("Case #%d: %d\n",w,s);
}
return ;
}
hdu 4146 Flip Game的更多相关文章
- HDU 3487 Play with Chain(Splay)
题目大意 给一个数列,初始时为 1, 2, 3, ..., n,现在有两种共 m 个操作 操作1. CUT a b c 表示把数列中第 a 个到第 b 个从原数列中删除得到一个新数列,并将它添加到新数 ...
- HDU 5694---BD String
HDU 5694 Problem Description 众所周知,度度熊喜欢的字符只有两个:B和D.今天,它发明了一种用B和D组成字符串的规则:S(1)=BS(2)=BBDS(3)=BBDBBD ...
- HDU 1890 区间反转
http://acm.hdu.edu.cn/showproblem.php?pid=1890 Robotic Sort Problem Description Somewhere deep in th ...
- HDU 4064 Carcassonne(插头DP)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4064 Problem Description Carcassonne is a tile-based ...
- HDU 4897 Little Devil I(树链剖分)(2014 Multi-University Training Contest 4)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4897 Problem Description There is an old country and ...
- HDU 3487:Play with Chain(Splay)
http://acm.hdu.edu.cn/showproblem.php?pid=3487 题意:有两种操作:1.Flip l r ,把 l 到 r 这段区间 reverse.2.Cut a b c ...
- hdu 3487 Play with Chain
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3487 YaoYao is fond of playing his chains. He has a c ...
- hdu 4869 Turn the pokers (2014多校联合第一场 I)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 3397 Sequence operation(线段树)
HDU 3397 Sequence operation 题目链接 题意:给定一个01序列,有5种操作 0 a b [a.b]区间置为0 1 a b [a,b]区间置为1 2 a b [a,b]区间0变 ...
随机推荐
- Latex 出现编辑公式,出现错误 !pdfTex error: Font rntxmi7 at 438 not found
http://docs.miktex.org/manual/advanced.html http://www.cl-projects.de/projects/misc/miktex-fonts.pht ...
- OpenLayers在地图外放置控件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...
- Python2.7用sys.stdout.write实现打印刷新
如何能在控制台实现在一行中显示进度的信息呢,就像使用pip安装时的进度那样. 如果用print则会打印成多行,下面这个小技巧可以在一行中打印: import time import sys if __ ...
- oracle国家字符集
国家字符集是一个备用字符集,利用此字符集可以在没有Unicode 数据库字符集的数据库中存储 Unicode 字符. 选择国家字符集的其它原因如下: 对于频繁的字符处理操作,不同的字符编码方案可能更为 ...
- 第一章 Web应用程序开发基础
一.HTTP协议工作机制 HTTP协议(HyperText Transfer Protocol,超文本传输协议)是用于从WWW服务器传输超文本到本地浏览器的传送协议.它是一种主流B/S架构中应用的通信 ...
- 19-2 from和modelform的用法和介绍
一 form 1. form的作用 1. 生成HTML代码 2. 帮我们做数据有效性的校验 3. 保留上次输入内容,显示错误提示 2. form组件校验数据有效性 1. 内置的校验规则 1. re ...
- win10上修改docker的镜像文件存储位置
记住:修改的是docker从服务器上拉下来的镜像文件存储位置(本地),是不是镜像源地址(服务器) 首先 win10下的docker有可视化操作界面和命令行操作,下载了docker-ce.exe双击后就 ...
- 阿里云对象存储OSS支持版本管理特性
阿里云对象存储OSS现已经全面支持“对象版本管理”特性.该功能适用于所有的存储类型以及区域.当Bucket启用该特性后,“对象版本管理”功能可以保护和恢复误删除.误覆盖的数据. 对象存储OSS“版本管 ...
- ArcMap影像纠偏
客户给了一张PNG图,如下图,需要提取其中北极航线. 策略是ArcMap中先配准PNG,使之与底图较好重合.再新建线图层,描出航线.这种彩色丰富的图,很难用栅格转矢量的方式,故应用描边法. 一.配准P ...
- php-textarea 换行
PHP接收表单提交的信息之后 存入数据库 再次从数据库获取数据再前端显示时 空格还有回车都消失了: 解决办法: 1,存入数据库时候进行替换 2,或者在取出数据之后进行替换 然后再在html中显示 s ...