Flip Game

Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1800    Accepted Submission(s):
589

Problem Description
Flip game is played on a square N*N field with
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.

 
Input
The first line contains a positive integer T,
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).
 
Output
For each case, please print the case number (beginning
with 1) and the number of white pieces after sequences of commands.
 
Sample Input
2
4
bwww
wbww
wwbw
wwwb
2
1 1
4 4
4
wwww
wwww
wwww
wwww
1
1 1
 
Sample Output
Case #1: 4
Case #2: 10
 
Author
Hzwu@SWJTU
 
Source
 
Recommend
lcy   |   We have carefully selected several similar
problems for you:  4145 4143 4147 4148 4144 
 
水题,不过很容易超时,不能完全暴力,思想是记录每行每列的地板变换了多少次,偶数则不改变,奇数则改变。
 
题意:给定一个矩阵,包含黑白两种地砖,每次选定一块地砖,将这块地砖所在的行,列的所有地砖转换颜色(黑变白,白变黑);问最后白色地砖有多少块。
 
附上代码:
 
 #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的更多相关文章

  1. HDU 3487 Play with Chain(Splay)

    题目大意 给一个数列,初始时为 1, 2, 3, ..., n,现在有两种共 m 个操作 操作1. CUT a b c 表示把数列中第 a 个到第 b 个从原数列中删除得到一个新数列,并将它添加到新数 ...

  2. HDU 5694---BD String

    HDU   5694 Problem Description 众所周知,度度熊喜欢的字符只有两个:B和D.今天,它发明了一种用B和D组成字符串的规则:S(1)=BS(2)=BBDS(3)=BBDBBD ...

  3. HDU 1890 区间反转

    http://acm.hdu.edu.cn/showproblem.php?pid=1890 Robotic Sort Problem Description Somewhere deep in th ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. hdu 4869 Turn the pokers (2014多校联合第一场 I)

    Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. 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变 ...

随机推荐

  1. 模拟4题解 T3奇袭

    T3奇袭 题目描述 由于各种原因,桐人现在被困在Under World(以下简称UW)中,而UW马上 要迎来最终的压力测试——魔界入侵. 唯一一个神一般存在的Administrator被消灭了,靠原本 ...

  2. bzoj2467 生成树

    传送门 生成树计数裸题,因为模数不是质数所以要用辗转相除的高斯消元. de了很久的bug然后发现一个变量A赋值后下一行又申明了一个新的临时变量A(: //Achen #include<algor ...

  3. Excel怎么增加撤销操作的次数?Excel增加可撤销次数教程

    Excel怎么增加撤销操作的次数?Excel增加可撤销次数教程 在Excel的使用中,返回上一步是经常用到的一个工具,当数据填写有误需要查看之前的内容时,一般会通过"Ctrl Z" ...

  4. Eclipse创建jsp web项目

    Eclipse 是一个开放源代码的.基于Java的可扩展开发平台.就其本身而言,它只是一个框架和一组服务,用于通过插件组件构建开发环境.幸运的是,Eclipse 附带了一个标准的插件集,包括Java开 ...

  5. 如何设置单个 Git 仓库的代理从而提高更新速度

    如何设置单个 Git 仓库的代理从而提高更新速度 因为特殊原因,需要单独对 Git 仓库设置远程代理,从而提高更新速度. 主要原因是因为有一些远程 Git 仓库比较慢. 最初的想法是系统全局代理,但是 ...

  6. 如何在Liferay 7中用html显示页面

    liferay portlet默认的显示页面是view.jsp,虽然可以在jsp中用include标签包括html文件,但是如何直接通过修改配置文件让默认的显示页面为view.html呢? 1.用Li ...

  7. 【机器学习PAI实战】—— 玩转人工智能之商品价格预测

    摘要: 我们经常思考机器学习,深度学习,以至于人工智能给我们带来什么?在数据相对充足,足够真实的情况下,好的学习模型可以发现事件本身的内在规则,内在联系.我们去除冗余的信息,可以通过最少的特征构建最简 ...

  8. 三.BP神经网络

    BP神经网络是包含多个隐含层的网络,具备处理线性不可分问题的能力.以往主要是没有适合多层神经网络的学习算法,,所以神经网络的研究一直处于低迷期. 20世纪80年代中期,Rumelhart,McClel ...

  9. Python PEP8标准

    1.编码 如无特殊情况,文件一律使用utf-8编码 如无特殊情况,文件头部必须添加# -*- coding:utf-8 -*- 标志 2.代码 统一使用四个空格缩进 每行代码不超过80个字符 自然语言 ...

  10. IE下的双外边距浮动bug

    最常见且最容易发现的额一个bug是IE 6和最低版本中的双外边距浮动bug.这个bug是任何浮动元素上的外边距加倍. 上面代码中,div盒子向左边浮动,设置的margin-left的值是10px.在c ...