链接: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)denoting the rows and columns of LaunchPad.
The second line of input contains single integer 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)

输出描述:

Print one line - the number of the squares that is on light state.

示例1

输入


输出

 
示例2

输入


输出

 

说明

开两个数组分别记录当前行或列是否有操作,再开一个二维数组计算每个灯在操作后的亮灭情况(用来调整行和列所带来的一次操作而不是两次操作)。

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
#include <ctime>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
const LL MOD=;
const double PI = acos(-);
const double eps =1e-;
#define Bug cout<<"---------------------"<<endl
const int maxn=1e5+;
using namespace std; int row[];
int col[];
int d[][]; int main()
{
#ifdef DEBUG
freopen("sample.txt","r",stdin);
#endif
// ios_base::sync_with_stdio(false);
// cin.tie(NULL); int n,m;
scanf("%d %d",&n,&m);
int q;
scanf("%d",&q);
for(int i=;i<=q;i++)
{
int x,y;
scanf("%d %d",&x,&y);
row[x]++;
col[y]++;
d[x][y]++;
}
int sum=;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if((row[i]+col[j]+d[i][j])&)
sum++;
}
}
printf("%d\n",sum); return ;
}
 作者:Uncle_drew
链接:https://ac.nowcoder.com/discuss/363155?type=101
来源:牛客网 #include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=+;
int a[maxn],b[maxn];
int c[maxn][maxn];
int main()
{
int n,m,q;
scanf("%d %d",&n,&m);
scanf("%d",&q);
while(q--){
int u,v;
scanf("%d %d",&u,&v);
c[u][v]^=;
a[u]^=;
b[v]^=;
}
int ans=;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
ans+=a[i]^b[j]^c[i][j];
}
}
printf("%d\n",ans);
return ;
}

-

LaunchPad(思维)的更多相关文章

  1. [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序

    用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html  目录 马桶排序(令人 ...

  2. Photoshop、Illustrator思维导图笔记

    半年前学习Photoshop时记得的思维导图笔记,可能不是很全,常用的基本都记下了.

  3. CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维

    前言: 随着CYQ.Data 开始回归免费使用之后,发现用户的情绪越来越激动,为了保持这持续的激动性,让我有了开源的念头. 同时,由于框架经过这5-6年来的不断演进,以前发的早期教程已经太落后了,包括 ...

  4. 计算机程序的思维逻辑 (8) - char的真正含义

    看似简单的char 通过前两节,我们应该对字符和文本的编码和乱码有了一个清晰的认识,但前两节都是与编程语言无关的,我们还是不知道怎么在程序中处理字符和文本. 本节讨论在Java中进行字符处理的基础 - ...

  5. 计算机程序的思维逻辑 (29) - 剖析String

    上节介绍了单个字符的封装类Character,本节介绍字符串类.字符串操作大概是计算机程序中最常见的操作了,Java中表示字符串的类是String,本节就来详细介绍String. 字符串的基本使用是比 ...

  6. 计算机程序的思维逻辑 (31) - 剖析Arrays

    数组是存储多个同类型元素的基本数据结构,数组中的元素在内存连续存放,可以通过数组下标直接定位任意元素,相比我们在后续章节介绍的其他容器,效率非常高. 数组操作是计算机程序中的常见基本操作,Java中有 ...

  7. 计算机程序的思维逻辑 (33) - Joda-Time

    Joda-Time上节介绍了JDK API中的日期和时间类,我们提到了JDK API的一些不足,并提到,实践中有一个广泛使用的日期和时间类库,Joda-Time,本节我们就来介绍Joda-Time.俗 ...

  8. 计算机程序的思维逻辑 (53) - 剖析Collections - 算法

    之前几节介绍了各种具体容器类和抽象容器类,上节我们提到,Java中有一个类Collections,提供了很多针对容器接口的通用功能,这些功能都是以静态方法的方式提供的. 都有哪些功能呢?大概可以分为两 ...

  9. 成吨提高开发效率:Intellij Shortcuts精简子集与思维模式

    在线精简cheatsheet备查表:intellij.linesh.twGithub项目:intellij-mac-frequent-keymap Intellij的快捷键多而繁杂,从官方推荐的key ...

随机推荐

  1. (1)关于PSP寄存器和MSP寄存器的简单描述

    由于 Cortex-M3 和 M4 内核具有双堆栈指针, MSP 主堆栈指针和 PSP 进程堆栈指针,或者叫 PSP任务堆栈指针也是可以的.在 FreeRTOS 操作系统中,主堆栈指针 MSP 是给系 ...

  2. 记录第一次制作pypi包的过程

    准备工作 1.创建一个项目文件夹 mkdir dada_openapi_python cd dada_openapi_python 2.创建包文件夹 在里面在创建一个 dada_openapi_cli ...

  3. Promise 与 await 组合使用

    看例子就行了,废话不多说!   async function checkStatus(name){   return new Promise((resolve,reject) => {      ...

  4. Docker每次启动容器,IP及hosts指定

    原文链接:https://blog.csdn.net/u012834750/article/details/80508464 前言 每次在使用Docker启动Hadoop集群的时候,都需要重新绑定下网 ...

  5. AD中内电层设置

    用于走线与普铜 内电层分割

  6. COGS 1489玩纸牌

    %%%http://blog.csdn.net/clover_hxy/article/details/53171234 #include<bits/stdc++.h> #define LL ...

  7. 利用方法HttpUtility.HtmlEncode来预处理用户输入

    利用方法HttpUtility.HtmlEncode来预处理用户输入.这样能阻止用户用链接注入JavaScript代码或HTML标记,比如//Store/Broswe?Genre=<script ...

  8. React之生命周期函数(16.3以后新版本)

    学习链接: https://www.jianshu.com/p/514fe21b9914 学习链接:https://zhuanlan.zhihu.com/p/38030418 学习链接:https:/ ...

  9. [XNUCA2019Qualifier]EasyPHP

    0x00 知识点 预期解中知识点: htaccess生效 如果尝试上传htaccess文件会发现出现响应500的问题,因为文件尾有Just one chance 这里采用# \的方式将换行符转义成普通 ...

  10. 使用 this 关键字定义方法和属性

    1.方法和属性的定义 属性是类中声明的变量,与其他地方变量的声明基本相同,只是属性必须 this 关键字,并且这里没有var 关键字. this.age; 在使用时,先是 this 关键字,之后的点语 ...