LaunchPad(思维)
链接:https://ac.nowcoder.com/acm/contest/3665/D
来源:牛客网
题目描述
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.
输入
输出
输入
输出
说明

开两个数组分别记录当前行或列是否有操作,再开一个二维数组计算每个灯在操作后的亮灭情况(用来调整行和列所带来的一次操作而不是两次操作)。
#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(思维)的更多相关文章
- [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序
用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html 目录 马桶排序(令人 ...
- Photoshop、Illustrator思维导图笔记
半年前学习Photoshop时记得的思维导图笔记,可能不是很全,常用的基本都记下了.
- CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维
前言: 随着CYQ.Data 开始回归免费使用之后,发现用户的情绪越来越激动,为了保持这持续的激动性,让我有了开源的念头. 同时,由于框架经过这5-6年来的不断演进,以前发的早期教程已经太落后了,包括 ...
- 计算机程序的思维逻辑 (8) - char的真正含义
看似简单的char 通过前两节,我们应该对字符和文本的编码和乱码有了一个清晰的认识,但前两节都是与编程语言无关的,我们还是不知道怎么在程序中处理字符和文本. 本节讨论在Java中进行字符处理的基础 - ...
- 计算机程序的思维逻辑 (29) - 剖析String
上节介绍了单个字符的封装类Character,本节介绍字符串类.字符串操作大概是计算机程序中最常见的操作了,Java中表示字符串的类是String,本节就来详细介绍String. 字符串的基本使用是比 ...
- 计算机程序的思维逻辑 (31) - 剖析Arrays
数组是存储多个同类型元素的基本数据结构,数组中的元素在内存连续存放,可以通过数组下标直接定位任意元素,相比我们在后续章节介绍的其他容器,效率非常高. 数组操作是计算机程序中的常见基本操作,Java中有 ...
- 计算机程序的思维逻辑 (33) - Joda-Time
Joda-Time上节介绍了JDK API中的日期和时间类,我们提到了JDK API的一些不足,并提到,实践中有一个广泛使用的日期和时间类库,Joda-Time,本节我们就来介绍Joda-Time.俗 ...
- 计算机程序的思维逻辑 (53) - 剖析Collections - 算法
之前几节介绍了各种具体容器类和抽象容器类,上节我们提到,Java中有一个类Collections,提供了很多针对容器接口的通用功能,这些功能都是以静态方法的方式提供的. 都有哪些功能呢?大概可以分为两 ...
- 成吨提高开发效率:Intellij Shortcuts精简子集与思维模式
在线精简cheatsheet备查表:intellij.linesh.twGithub项目:intellij-mac-frequent-keymap Intellij的快捷键多而繁杂,从官方推荐的key ...
随机推荐
- String巩固
About String in Java 如今做了一个重大决定,不定期温习The Basement Of Java String对象的认知简述 首先 String不属于 8种基本数据类型, Strin ...
- WCF 异常 The server was unable to process the request due to an internal error.
实习用的C#,不搞.NET,但且记下. 只有标题中的错误提示,完全不知道哪里出错,要么是Oracle服务器.要么是服务程序,最不愿代码有问题. <behaviors> <servic ...
- VUE- Cordova打包APP
VUE- Cordova打包APP 现在使用vue开发的项目越来越多,使用vue开发的移动端打包就成了最大的问题.现在前端打包方案有好多种,但是综合来说,我比较喜欢用cordova来进行Android ...
- 课程作业02-1-课后作业1-(1)使用组合数公式利用n!来计算
1.设计思想:运用递归阶乘的函数,依次求出n!.k!.(n-k)!,再根据组合数的公式计算(n!/(k!*(n-k)!)). 2.程序流程图: 3.源程序代码: //信1605-3 20163429 ...
- Bean Java配置
Spring 系列教程 Spring 框架介绍 Spring 框架模块 Spring开发环境搭建(Eclipse) 创建一个简单的Spring应用 Spring 控制反转容器(Inversion of ...
- Linux学习《第三章重定向,管道符和环境变量》
- phi
给定 \(T\) 个正整数 \(n\) ,对于每个 \(n\) ,输出做小的 \(m\) ,使得 \(\phi (m)\ge n\). 思路1:搞个线性欧拉函数筛,后缀最大值,二分查找 思路2:直接求 ...
- 005、mysql查询表的结构
EXPLAIN hcc_ip 如果有一个表,表明为hcc_ip,使用以上语句可以得到下图 不忘初心,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:38247724 ...
- CSS绘制小三角
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- sql server ------创建本地数据库 SQL Server 排序规则
sql server完整复制数据库 sql server导入导出方法 SQL Server 排序规则