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 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\leq Q\leq 10^6)Q(0≤Q≤10
6
) denoting the times of touch.
On the next Q lines,describe X and Y - the position of the square being touched. (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
说明
解析:用两个数组记录行改变的次数,和列改变的次数,还有当前(i,j)改变的次数
然后遍历每个点,三者相加是否是奇数,是答案+1
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;
int x[N],y[N];
int ans[1005][1005];
int n,m,t;
int a,b;
int main()
{
cin>>n>>m>>t;
while(t--)
{
cin>>a>>b;
x[a]++;
y[b]++;
ans[a][b]++;
}
int res=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
if((x[i]+y[j]+ans[i][j])%2) res++;
}
cout<<res<<endl;
}
上一篇: java版排序算法之快速排序
下一篇: poj 3278 简单BFS多状态搜索