CSU 1469 Handles

来源:互联网 发布:全球云计算公司排名 编辑:程序博客网 时间:2024/06/06 01:32

1469: Handles

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 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) (1iN, 1jM). 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 (2N,M1000) 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 ≤ 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

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


0 0
原创粉丝点击