CSU 1469 Change The Handles acm 模拟题



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 ≤ iN, 1 ≤ jM). 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 doQ change operations successively. Then follow Q lines with two integersi, j (1 ≤ iN, 1 ≤ jM), 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

2
2 4
----
----
4
1 1
1 1
1 1
2 4
5 5
+--+-
++--+
--+-+
+----
-++-+
3
3 2
1 4
3 3

Sample Output

6
14
    
    

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.

这是一道模拟题,由于数据量大,所以可以用一个二维数组来记录对某一个点的操作次数,如果为奇数则改变状态。

#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; }

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值