[Agc029D]Grid game_贪心
Grid game
题目链接:https://atcoder.jp/contests/agc029/tasks/agc029_d
数据范围:略。
题解:
方法肯定很简单,就是找一处障碍待在他上面就好。
那就随便搞一搞呗
代码:
#include <bits/stdc++.h>
#define N 300010
using namespace std;
char *p1, *p2, buf[100000];
#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )
int rd() {
int x = 0, f = 1;
char c = nc();
while (c < 48) {
if (c == '-')
f = -1;
c = nc();
}
while (c > 47) {
x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
}
return x * f;
}
vector <int> v[N];
bool vis[N];
int main() {
int h = rd(), w = rd(), n = rd();
for (int i = 1; i <= n; i ++ ) {
int x = rd(), y = rd();
v[y].push_back(x);
}
for (int i = 1; i <= w; i ++ ) {
v[i].push_back(h + 1);
}
sort(v[1].begin(), v[1].end());
int ans = v[1][0] - 1;
int t = 0;
for (int i = 2; i <= w; i ++ ) {
sort(v[i].begin(), v[i].end());
int s = v[i].size(), m = 0;
for (int k = 0; k < s; k ++ ) {
if (v[i][k] <= i + t) {
vis[v[i][k]] = 1;
m = max(v[i][k], m);
}
else if (vis[v[i][k] - 1]) {
vis[v[i][k]] = 1;
m = max(v[i][k], m);
}
else {
ans = min(ans, v[i][k] - 1);
break;
}
}
t = max(t, m - i + 1);
}
cout << ans << endl ;
return 0;
}
[Agc029D]Grid game_贪心的更多相关文章
- Codeforces Global Round 9 B. Neighbor Grid (构造,贪心)
题意:给一个\(n\)X\(m\)的矩阵,矩阵中某个数字\(k\)表示其四周恰好有\(k\)个不为0的数字,你可以使任意位置上的数字变大,如果操作后满足条件,输出新矩阵,否则输出NO. 题解:贪心,既 ...
- UVA 12382 Grid of Lamps 贪心
题目链接: C - Grid of Lamps Time Limit:1000MSMemory Limit: 0KB 问题描述 We have a grid of lamps. Some of the ...
- UVA 12382 Grid of Lamps --贪心+优先队列
题意:给出每行每列至少有的灯泡数,问最少有的灯泡数. 解法:要使灯泡数尽量小,说明要使交叉点尽量多,这样即抵了行,又抵了列,为最优的.所以可以用行来消去列,也可以用列来消去行,我这里是列来消去行.首先 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- CF 115B Lawnmower(贪心)
题目链接: 传送门 Lawnmower time limit per test:2 second memory limit per test:256 megabytes Description ...
- Codeforces Round #192 (Div. 1) A. Purification 贪心
A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...
- Aizu 2302 On or Off dfs/贪心
On or Off Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...
- #292 (div.2) D.Drazil and Tiles (贪心+bfs)
Description Drazil created a following problem about putting × tiles into an n × m grid: "The ...
- hdu 5463 Clarke and minecraft(贪心)
Problem Description Clarke is a patient with multiple personality disorder. One day, Clarke turned i ...
随机推荐
- P1578 奶牛浴场 有障碍点的最大子矩形
这题咕咕了很久终于写了\(QwQ\) 思路:扫? 提交:2次 错因:数据差评,第一次把矩形的长宽搞反了竟然只有一个点没有\(A\). 题解: 显然能成为答案的矩形的边界一定有障碍点或者与大矩形边界重合 ...
- MySQL 锁(lock与latch)
一.什么是锁 锁机制用于管理对共享资源的并发访问,它是数据库系统区别于文件系统的一个关键特性. 数据库系统使用锁是为了支持对共享资源的并发访问,提供数据的完整性和一致性. InnoDB存储引擎锁的实现 ...
- 030_根据 md5 校验码,检测文件是否被修改
#!/bin/bash#本示例脚本检测的是/etc 目录下所有的 conf 结尾的文件,根据实际情况,可以修改为其他目录或文件#本脚本在目标数据没有被修改时执行一次,当怀疑数据被人篡改,再执行一次#将 ...
- UDP广播,组播服务器
广播 #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/ ...
- Codevs 1768 种树 3(差分约束)
1768 种树 3 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 为了绿化乡村,H村积极响应号召,开始种树了. H村里有n幢 ...
- oracle查询消耗服务器资源SQL语句
1.查找最近一天内,最消耗CPU的SQL语句 SELECT ASH.INST_ID, ASH.SQL_ID, (SELECT VS.SQL_TEXT FROM GV$SQLAREA VS WHERE ...
- spring事物不回滚的问题
学习spring分布式事务的时候,自己整了个demo,写test测试的时候发先事物没有回滚.此问题和分布式事务没关系.1.在service层引入@Transaction注解 使用 throw new ...
- Python语法 - yield表达式(类似 m = yield i )
yield是个表达式而不仅仅是个语句,所以可以使用x = yield r 这样的语法, yield表达式可以接收send()发出的参数,yield表达式是跟send方法一起配合使用 send方 ...
- 【原创】FltGetFileNameInformation蓝屏分析
FAULTING_IP: nt!SeCreateAccessStateEx+5b80564184 848788000000 test byte ptr [edi+88h],al TRAP_FRAME: ...
- Mongodb更新数组$pull修饰符 (mongodb 修改器($inc/$set/$unset/$push/$pop/upsert))
mongodb 修改器($inc/$set/$unset/$push/$pop/upsert)) https://www.jb51.net/article/112588.htm http://bl ...