列表

详情


NC200594. LaunchPad

描述

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  denoting the rows and columns of LaunchPad.
The second line of input contains single integer denoting the times of touch.
On the next Q lines,describe X and Y - the position of the square being touched.

输出描述

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

说明:

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 714ms, 内存消耗: 4360K, 提交时间: 2020-01-20 10:41:21

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int r[1010],c[1010];
int g[1010][1010];
int main(){
	int n,m,q;
	cin>>n>>m>>q;
	while(q--){
		int u,v;
		cin>>u>>v;
		g[u][v]^=1;
		r[u]^=1;
		c[v]^=1;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++){
		ans+=g[i][j]^r[i]^c[j];
	}
	cout<<ans<<'\n';
}

C++11(clang++ 3.9) 解法, 执行用时: 673ms, 内存消耗: 15484K, 提交时间: 2020-01-19 13:50:19

#include <iostream>
using namespace std;
int m,n,q,a,b,r;
int h[2000],w[2000],c[2000][2000];
int main(){
    cin>>n>>m>>q;
    while(q--){
        cin>>a>>b;
        h[a]++;
        w[b]++;
        c[a][b]++;
    }
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)r+=(h[i]+w[j]+c[i][j])%2;
    cout<<r<<endl;
}

上一题