LaunchPad

链接:https://ac.nowcoder.com/acm/contest/3665/D
来源:牛客网

Hery is a boy with strong practical abilities. Nowadays,he designed a LaunchPad which is not same as what you ever seen.
The LaunchPad is a touch screen divided into squares of N rows and M columns. Each square has two states of light and shade. And all squares are shady initially. When you touch the square in row X and column Y, the state of all the squares in the row and column will change. Now he wants to know how many squares are light on the LaunchPad after he makes multiple touches.

输入描述:

The first line of input contains two integers N,M(1≤N,M≤1000)N,M (1\leq N,M\leq 1000)N,M(1N,M1000) denoting the rows and columns of LaunchPad.
The second line of input contains single integer Q(0≤Q≤106)Q (0\leq Q\leq 10^6)Q(0Q106) denoting the times of touch.
On the next Q lines,describe X and Y - the position of the square being touched. (1≤X≤N,1≤Y≤M)(1\leq X \leq N,1\leq Y\leq M)(1XN,1YM)

输出描述:

Print one line - the number of the squares that is on light state.
示例1

输入

复制
1 1
1
1 1

输出

复制
1
示例2

输入

复制
2 4
2
2 4
1 4

输出

复制
6

说明

 

题目大意:

就是说一开始n*m矩阵中都是暗的,你可以按压n*m矩阵中任意一个方格,该方格行和列都会变亮,再摁一次会变暗,问m次操作后亮的方格的个数;

解析:

就是行和列的性质不变,但是vis[a][b]会重复

AC代码:

复制代码
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}
typedef long long ll;
const int maxn=1e4+10;
const int M=1e7+10;
const int INF=0x3f3f3f3f;
int vis[1010][1010];
int h[maxn];//
int l[maxn];//
int main()
{
    int n,m,t; 
    cin>>n>>m>>t;
    int a,b;
    for(int i=0;i<t;i++){
        cin>>a>>b;
        h[a]++;
        l[b]++;
        vis[a][b]++;
    }
    int sum=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if((h[i]+l[j]-vis[i][j])%2==1){
                sum++;
            }
        }
    }
    printf("%d",sum);
    return 0;
}
复制代码

 

 

posted @   lipu123  阅读(281)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示