CSU 1469 Handles

本文深入探讨了游戏开发领域的核心技术,包括游戏引擎、动画、3D空间视频等,旨在为开发者提供全面的游戏开发知识和实践经验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


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 an N·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 row i 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 integers N, M (2N, M1000) as defined above. Then follow N 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 integer Q (1 ≤ Q ≤ 105), meaning you will do Q change operations successively. Then follow Q 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

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.


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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值