CSU 1469 Change The Handles acm 模拟题
来源:互联网 发布:淘宝店铺封了怎么激活 编辑:程序博客网 时间:2024/05/22 02:48
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 columnj.
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 withM 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 doQ change operations successively. Then followQ lines with two integersi, 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
614Hint
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.
这是一道模拟题,由于数据量大,所以可以用一个二维数组来记录对某一个点的操作次数,如果为奇数则改变状态。
#include<iostream>#include<string>using namespace std;int op[100005][2];bool c[1010][1010];long long row[1010], arr[1010];int main(){ int t; cin >> t; long long q; while (t--){ int n,m; string s; cin >> n>>m; for (int i = 1; i <= n;i++){ cin >> s; for (int j = 1; j <= m; j++){ if (s[j - 1] == '+')c[i][j] = true; else c[i][j] = false; } } cin >> q; for (int i = 0; i < q; i++){ cin >> op[i][0] >> op[i][1]; } for (int i = 0; i < 1010; i++)row[i] = 0; for (int i = 0; i < 1010; i++)arr[i] = 0; for (int i = 0; i < q; i++){ row[op[i][0]]++; arr[op[i][1]]++; c[op[i][0]][op[i][1]] = !c[op[i][0]][op[i][1]]; } for (int i = 1; i <= n; i++){ int k = row[i] % 2; if (k){ for (int j = 1; j <= m; j++){ c[i][j] = !c[i][j]; } } } for (int i = 1; i <= m; i++){ int k = arr[i] % 2; if (k){ for (int j = 1; j <= n; j++){ c[j][i] = !c[j][i]; } } } int total = 0; for (int i = 1; i <= n; i++){ for (int j = 1; j <= m; j++){ if (c[i][j])total++; } } cout << total << endl; } return 0;}
- CSU 1469 Change The Handles acm 模拟题
- csu 1469 Change The Handles
- CSU 1469 Handles
- 文章标题CSU 1862: The Same Game(模拟)
- CSU 1574 Amanda Lounges 模拟题
- CSU 1112: 机器人的指令【模拟题】
- Sdut 2409 The Best Seat in ACM Contest(山东省第三届ACM省赛 H 题)(模拟)
- acm CSU 1111
- CSU 1160-ACM
- CSU 1111-ACM
- Handles the HTTP POST method
- ACM--模拟––湖南12年省赛--机器人的指令--CSU OJ--水
- CSU 1555 splay模拟
- CSU 1711 Kinfolk【模拟】
- 三道acm基础题 CSU-1000.1001.1002
- CSU OJ:1318 Small change(规律)
- hdoj 2277 Change the ball【规律题】
- CSU-ACM 1003: UC Browser
- 如何用Git GUI下载Spring Framework源码
- 南邮 OJ 1070 南邮仙林自行车停放场
- Java基础--重温Java的继承和重写
- android 闪屏
- oracle database 11g 架构图
- CSU 1469 Change The Handles acm 模拟题
- NSMakeRange,substringWithRange,substringToIndex,substringFromIndex区别和联系
- Android异步消息之Looper、Handler、Message、HandlerThread的关系
- 社説 20150804 感染症対策施設 迅速な診断と治療に生かせ
- Java反射机制
- 关于PDB, 你所知道的和想知道的
- QTP11 freely using extension
- 南邮 OJ 1071 数字的空洞
- ubuntu下PHP开发环境搭建记录