链接: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

说明

题目大意:

就是说一开始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=,f=;char c=getchar();while(c!='-'&&(c<''||c>''))c=getchar();if(c=='-')f=-,c=getchar();while(c>=''&&c<='')x=x*+c-'',c=getchar();return f*x;}
typedef long long ll;
const int maxn=1e4+;
const int M=1e7+;
const int INF=0x3f3f3f3f;
int vis[][];
int h[maxn];//行
int l[maxn];//列
int main()
{
int n,m,t;
cin>>n>>m>>t;
int a,b;
for(int i=;i<t;i++){
cin>>a>>b;
h[a]++;
l[b]++;
vis[a][b]++;
}
int sum=;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if((h[i]+l[j]-vis[i][j])%==){
sum++;
}
}
}
printf("%d",sum);
return ;
}

最新文章

  1. .NET静态变量与静态方法并发的问题
  2. (PPT)Linux服务器基础
  3. Linux---从start_kernel到init进程启动
  4. Spring中@Cacheable的用法
  5. Java条件语句之 switch
  6. gdb在运行maintenance info program-spaces命令时coredump
  7. 前端MVVM学习之KnockOut(二)
  8. 【转】搜索引擎选择: Elasticsearch与Solr
  9. CodeVS1344 线型网络
  10. thinkphp 单字母函数
  11. ThinkSNS+ alpha.2 版本发布,功能抢先看!【社交系统研发日记六】
  12. System.getProperty()参数大全
  13. Java NIO之网络编程
  14. python -- conda pytorch
  15. Hadoop服务库与事件库的使用及其工作流程
  16. Swift 栈和堆
  17. thinkphp中出现unserialize(): Error at offset 533 of 1857 bytes如何解决
  18. 百度编辑器插入视频、iframe 失败
  19. 洛谷P4138 挂饰 背包
  20. yii2视频教材

热门文章

  1. Idea实用小Tips
  2. 圆桌问题 (ArrayList+模拟)
  3. java包装类型的一些知识点
  4. AcWing 8.二维费用的背包问题
  5. i5+GT730+B85安装OSX10.10.5 (Yosemite Install(14F27).cdr)
  6. EAC3 Adaptive Hybrid Transform (AHT)
  7. OSI七层协议详解
  8. vs 安装svn插件
  9. 利用Xshell5从本机上向Linux(虚拟机中)上传文件
  10. 关于MultiAutoCompleteTextView的用法:多文本匹配