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(1≤N,M≤1000) 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(0≤Q≤106) 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)(1≤X≤N,1≤Y≤M)

输出描述:

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

说明

LaunchPad

 

题目大意:

就是说一开始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;
}

 

 

上一篇:Vue移动端实现左滑右滑


下一篇:Linux创建文件的5种方式