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变 ...
随机推荐
- 如何制作可以在 MaxCompute 上使用的 crcmod
之前我们介绍过在 PyODPS DataFrame 中使用三方包.对于二进制包而言,MaxCompute 要求使用包名包含 cp27-cp27m 的 Wheel 包.但对于部分长时间未更新的包,例如 ...
- shared_from_this bad_weak_ptr的原因
原因:创建类A的对象的时候没有用智能指针包裹,而是直接new的裸指针. enable_from_this 的使用与实现原理说明: shared_from_this()是enable_shared_fr ...
- 学习笔记(3)---安装SVM问题及解决方法
1. LibSVM下载,安装 下载地址:http://www.csie.ntu.edu.tw/~cjlin/libsvm/,最新的版本是3.17 2. 入门 [heart_scale_label,he ...
- 在n个球中,任意取出m个(不放回),求共有多少种取法
要求: 在n个球中,任意取出m个(不放回),求共有多少种取法 分析: 假设3个球A,B,C,任意取出2个,可分为取出的球中含A的部分和不含A的部分.即AB,AC为一组,BC为一组. 设函数F(n,m) ...
- Codeforces 404B
毫无疑问这题不是难题,但是这种题目最让人纠结 打心里对这种题目就比较害怕,果然,各种WE 这里贴上代码,用Python写的,比较偷懒: def cur_pos(a, d): if 0 <= d ...
- 【JZOJ3211】【SDOI2013】随机数生成器
╰( ̄▽ ̄)╭ 小 W喜欢读 书,尤其喜欢读 书,尤其喜欢读<约翰克里斯 朵夫>. 最近小 W准备读一本新书,这本一共有 p页, 页码范围为 0..p -1. 小 W很忙,所以每天只能读一 ...
- 【JZOJ4793】【GDOI2017模拟9.21】妮厨的愤怒
题目描述 栋栋和标标都是厨力++的妮厨.俗话说"一机房不容二厨",他们两个都加入了某OI( )交流♂( )群,在钦定老婆的时候出现了偏差,于是闹得不可开交.可是栋栋是群内的长者,斗 ...
- oracle如何限定特定IP访问数据库
可以利用登录触发器.cmgw或者是在$OREACLE_HOME/network/admin下新增一个protocol.ora文件(有些os可能是. protocol.ora),9i可以直接修改sqln ...
- thinkphp php审核后返回信息给html
1.die("<script>alert('至少选择一个收款方式!');history.back(-1);</script>");
- Oracle函数——MINUS
解释 “minus”直接翻译为中文是“减”的意思,在Oracle中也是用来做减法操作的,只不过它不是传统意义上对数字的减法,而是对查询结果集的减法.A minus B就意味着将结果集A去除结果集B中所 ...