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_贪心的更多相关文章

  1. Codeforces Global Round 9 B. Neighbor Grid (构造,贪心)

    题意:给一个\(n\)X\(m\)的矩阵,矩阵中某个数字\(k\)表示其四周恰好有\(k\)个不为0的数字,你可以使任意位置上的数字变大,如果操作后满足条件,输出新矩阵,否则输出NO. 题解:贪心,既 ...

  2. UVA 12382 Grid of Lamps 贪心

    题目链接: C - Grid of Lamps Time Limit:1000MSMemory Limit: 0KB 问题描述 We have a grid of lamps. Some of the ...

  3. UVA 12382 Grid of Lamps --贪心+优先队列

    题意:给出每行每列至少有的灯泡数,问最少有的灯泡数. 解法:要使灯泡数尽量小,说明要使交叉点尽量多,这样即抵了行,又抵了列,为最优的.所以可以用行来消去列,也可以用列来消去行,我这里是列来消去行.首先 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. CF 115B Lawnmower(贪心)

    题目链接: 传送门 Lawnmower time limit per test:2 second     memory limit per test:256 megabytes Description ...

  6. Codeforces Round #192 (Div. 1) A. Purification 贪心

    A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...

  7. 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 ...

  8. #292 (div.2) D.Drazil and Tiles (贪心+bfs)

    Description Drazil created a following problem about putting  ×  tiles into an n × m grid: "The ...

  9. hdu 5463 Clarke and minecraft(贪心)

    Problem Description Clarke is a patient with multiple personality disorder. One day, Clarke turned i ...

随机推荐

  1. luogu 5354 [Ynoi2017]由乃的OJ LCT+位运算

    如果做过起床困难综合征的话应该很快就能有思路,没做过那道题的话还真是挺费劲的. 我们不知道要带入的值是什么,但是我们可以知道假设带入值得当前位为 $1$ 时这一位在经过位运算后是否为 $1$. 至于这 ...

  2. 正则regex

    Regual expression 普通正常字符 字符匹配 . 表示任意字符 匹配次数 位置锚定 分组及引用

  3. js中4种遍历语法比较

    前言:本文主要比较for.for-in.forEach和for-of的异同以及优缺点. for for循环是最原始最易理解的循环遍历方式 for(var index = 0;index < ar ...

  4. RX232串口发送

    在进行工程调试的时候有时候需要对变量进行观察,SingnaTap II Logic Analyzer 只能对管脚进行观察,所以要观察内部的变量必须把内部的变量进行输出.一种方法是直接把变量定义成管脚通 ...

  5. Luogu5298 [PKUWC2018]Minimax

    太久没写博客了,过来水一发. 题目链接:洛谷 首先我们想到,考虑每个叶节点的权值为根节点权值的概率.首先要将叶节点权值离散化. 假设现在是$x$节点,令$f_i,g_i$分别表示左/右节点的权值$=i ...

  6. 从 s 点到 t 点的最短路(简单模板)(迪杰斯特拉)

    迪杰斯特拉简单版 #include <bits/stdc++.h> using namespace std; int m,n; const int inf = 0x3f3f3f3f; in ...

  7. SpringMVC配置数据验证(JSR-303)

    这篇文章已经过时了. 请参考比较合适的前后端交互方式. 1.pom.xml中追加hibernate-validator 2.在dto类的域上追加JSR-303的注解 public class Data ...

  8. python 监听键盘事件pyHook

    #coding=utf- import pyHook import pythoncom # 监听到鼠标事件调用 def onMouseEvent(event): if(event.MessageNam ...

  9. gym224647B

    gym224647B 题意: 在二维平面中·选出一个面积最小的三角形,输出这个三角形面积的两倍. 解法: 首先,最优解一定在相邻最近的三个点中产生. 然后我们就可以用向量求三角形的面积. CODE: ...

  10. Go语言 之捧腹网爬虫案例

    package main import ( "fmt" "net/http" "os" "regexp" "s ...