链接: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. 本机无oracle,远程连接

    描述 本机无oracle,通过PLSQL Developer程序,连接虚拟机中的oracle11gR2 1 下载instant-client 需要和服务端版本对应 下载相应的instant-clien ...

  2. IDEA 分屏显示

    效果: 步骤: 对着某个标签页单击右键,选择Split Vertically或者Split Horizontally即可.

  3. ssh: connect to host 120.79.26.164 port 22: Connection timed out报错问题

    要是使用阿里云服务器,出现这种错误,一般是端口没有打开.需要在阿里云控制台中设置端口后,即可使用ssh连接.

  4. centos7搭建kafka集群

    一.安装jdk 1.下载jdk压缩包并移动到/usr/local目录 mv jdk-8u162-linux-x64.tar.gz /usr/local 2.解压 tar -zxvf jdk-8u162 ...

  5. 四、React创建组件、 JSX使用、绑定数据、引用图片方式、数组(列表)循环输出

    接:https://www.cnblogs.com/chenxi188/p/11702799.html 用上节建好的my-app项目: my-app/ README.md node_modules/ ...

  6. (排序)P1068 分数线划定

    题解: 需要注意的是,快排完之后并不是按照编号从小到大的顺序输出 #include<iostream>using namespace std;int r=0;void swap(int & ...

  7. 转载:HTTP 请求头中的 X-Forwarded-For

    本文转自:https://www.jianshu.com/p/15f3498a7fad X-Forwarded-For和相关几个头部的理解 $remote_addr    是nginx与客户端进行TC ...

  8. Linux每日一练20200219

  9. hibernate.hbm.xml必须必须配置主键

    hibernate.hbm.xml必须必须配置主键 <id name="XXid" type="java.lang.long" column=" ...

  10. apache2+django+virtualenv 服务器部署实战

    目录 基本配置 配置python环境 安装 python.pip 安装 virtualenv 配置python虚拟环境 配置 apache2 安装 apache2 安装 mod-wsgi 服务 部署d ...