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. Girls and Boys POJ - 1466 【(二分图最大独立集)】

    Problem DescriptionIn the second year of the university somebody started a study on the romantic rel ...

  2. 二进制学习——Blob,ArrayBuffer、File、FileReader和FormData的区别

    前言: Blob.ArrayBuffer.File.fileReader.formData这些名词总是经常看到,知道一点又好像不知道,像是同一个东西好像又不是,总是模模糊糊,最近终于下决心要弄清楚. ...

  3. redis数据存储--redis在Windows下的安装过程

    一.下载软件 1. 下载Redis windows版本,Redis官网下载地址为:https://redis.io/download: 这里下载的是Windows版本,下载地址为:https://gi ...

  4. 2019.7.9 校内测试 T2 极值问题

    这一次是交流测试?边交流边测试(滑稽 极值问题 乍一看这是一道数学题,因为1e9的数据让我暴力的心退却. 数学又不好,不会化简式子嘞,咋办? 不怕,咱会打表找规律.(考场上真的是打表找出了规律,打表打 ...

  5. servlet容器:jetty,Tomcat,JBoss

    一.几款servlet容器对比:jetty,Tomcat,JBoss 二.JBOSS相关问题解决 1.JBOSS下载安装 2.处理jboss-as-7.1.1.Final与jdk1.8及1.8以上版本 ...

  6. windows环境下启动mongodb服务

    方法一1.打开命令窗口,切换到mongodb安装目录下的“bin”目录中. 输入命令:cd E:\software\MongoDB\Server\3.4\bin 2.启动服务.输入命令:”mongod ...

  7. tomcat 启动报错org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].xxx

    今天在写完一个非常简单的servlet页面跳转的web项目后,启动tomcat报错org.apache.catalina.LifecycleException: Failed to start com ...

  8. 攻防世界RE1 writeup

    解题过程 将题目给出的exe文件拖入ida中,查看main函数. 分析函数的逻辑,发现用户需要输出一个字符串,存储到变量v9中.如果v9的值与v5的值相等则会打印unk_413e90中的值,否则打印a ...

  9. python定义接口继承类invalid syntax解决办法

    class s_all(metaclass=abc.ABCMeta): #python2.7用此方法定义接口继承 # __metaclass__ = abc.ABCMeta @abc.abstract ...

  10. Spark2.0协同过滤与ALS算法介绍

    ALS矩阵分解 一个 的打分矩阵 A 可以用两个小矩阵和的乘积来近似,描述一个人的喜好经常是在一个抽象的低维空间上进行的,并不需要把其喜欢的事物一一列出.再抽象一些,把人们的喜好和电影的特征都投到这个 ...