CSU 1469 Handles
来源:互联网 发布:全球云计算公司排名 编辑:程序博客网 时间:2024/06/06 01:32
1469: Handles
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 258 Solved: 65
[Submit][Status][Web Board]
Description
There are N·M handles on the ground. Every handle can be in one of two states: open or closed. The handles are represented as anN·M matrix. You can change the state of handle in any location (i,j) (1 ≤ i ≤N, 1 ≤j ≤M). However, this also changes states of all handles in rowi and all handles in column j.
The figure below shows how the states of handles changed.
Input
The first line contains an integer T (T > 0), giving the number of test cases.
For each test case, the first lines contains two integersN, M (2 ≤ N,M ≤ 1000) as defined above. Then followN lines with M characters describing the initial states of the handles. A symbol “+” denotes the handle in open state, “-” denotes the handle in closed state. The next line contains an integerQ (1 ≤ Q ≤ 105), meaning you will do Q change operations successively. Then followQ lines with two integers i, j (1 ≤ i ≤ N, 1 ≤j ≤ M), meaning you will change the state of handle in location (i,j).
Output
For each test case, output the number of handles which are in open state after doing all the operations.
Sample Input
22 4--------41 11 11 12 45 5+--+-++--+--+-++-----++-+33 21 43 3
Sample Output
614
HINT
Explanation of sample 1: The states of the handles will be changed as the figure shown below.
Explanation of sample 2: The states of the handles will be changed as the figure shown below.
Source
模拟题。
#include <stdio.h>#include <string.h>using namespace std;char a[1005][1005];int xx[1005],yy[1005];int n,m;int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); memset(xx,0,sizeof(xx)); memset(yy,0,sizeof(yy)); for(int i=0;i<n;i++) scanf("%s",a[i]); int q; scanf("%d",&q); while(q--) { int x,y; scanf("%d%d",&x,&y); a[x-1][y-1]=(a[x-1][y-1]=='+'?'-':'+'); xx[x-1]++; yy[y-1]++; } for(int i=0;i<n;i++) { if(xx[i]%2!=0) { for(int j=0;j<m;j++) a[i][j]=(a[i][j]=='+'?'-':'+'); } } for(int i=0;i<m;i++) { if(yy[i]%2!=0) { for(int j=0;j<n;j++) a[j][i]=(a[j][i]=='+'?'-':'+'); } } int sum=0; for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(a[i][j]=='+') sum++; printf("%d\n",sum); } return 0;}
- CSU 1469 Handles
- csu 1469 Change The Handles
- CSU 1469 Change The Handles acm 模拟题
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- 数据结构笔记之绪论
- 在linux上安装tigervnc server
- adb help all
- NYOJ 35 表达式求值 or 267 郁闷的C小加(二)
- linux 进程间通信 FIFO
- CSU 1469 Handles
- iOS 模拟器不弹出软键盘的解决办法
- 解决【RedHat】sendmail启动慢的问题
- Netty权威指南-NIO实现TimeServer服务器端源代码
- 图片之不可错过图片
- DDR学习笔记(一)-FPGA驱动DDR时时钟、突发长度的关系
- Android ActionBar的图标和标题
- 【Android】intent传递数据时,数据大小的限制问题
- ava.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook