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. word黏贴图片显示不出来

    word图片转存,是指UEditor为了解决用户从word中复制了一篇图文混排的文章粘贴到编辑器之后,word文章中的图片数据无法显示在编辑器中,也无法提交到服务器上的问题而开发的一个操作简便的图片转 ...

  2. [UVa12345] Dynamic len (带 修 )

    题意:有n个数编号从0→n-1,两种操作:            Q L R:询问编号为L→R-1的数中共有多少种不同的数             M X Y:将编号为X的数改为Y           ...

  3. webstorm双击鼠标出现光标块

    将Vim 选项对勾去掉

  4. 关于VGA显示实验的问题

    今天做了一个关于VGA的显示实验,但是由于产生的25M时钟不正确所以一直没有图像产生.刚开始的程序如下 虽然仿真的时候出现了时序,但是在下载到硬件的时候不正确. 后来改成 结果就正确了. 另外之前关于 ...

  5. ETL定义、四大模块及子系统说明

    ETL定义.四大模块及子系统说明 ——<Pentaho Kettle解决方案>读书笔记 罗小川 目前公司正在进行数据仓库的建设的前期需求整理和项目启动阶段,想简单来谈一下自己对目前公司在用 ...

  6. 解析配置文件 redis.conf

    1.units单位 2.INCLUDES包含 3.GENERAL通用 1).daemonize daemonize yes 启用后台守护进程运行模式 2).pidfile pidfile /var/r ...

  7. C++ 基础学习笔记

    c++中的左值与右值 左值与右值这两概念是从 c 中传承而来的,在 c 中,左值指的是既能够出现在等号左边也能出现在等号右边的变量(或表达式),右值指的则是只能出现在等号右边的变量(或表达式). 清除 ...

  8. Connection

    作用: * 获取执行sql语句对象 ** createStatement(): 获取Statement对象 ** prepareStatement(String sql): 获取预处理对象 ** pr ...

  9. OS X的CAOpenGLLayer中如何启用OpenGL3.2 core profile

    在OS X的openGL编程中,我们有时为了想在自己的OpenGL图层上再加些自己的某些涂层,必须得用CAOpenGLLayer而不是NSOpenGLView,由于在NSOpenGLView上添加任何 ...

  10. 16Flutter中的路由 基本路由 基本路由跳转传值(上)

    /* Flutter中的普通路由.普通路由传值.命名路由.命名路由传值 Flutter中的路由通俗的讲就是页面跳转.在Flutter中通过Navigator组件管理路由导航. 并提供了管理堆栈的方法. ...