NC200594. LaunchPad
描述
输入描述
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; }