[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 ...
随机推荐
- PHP mysqli_character_set_name() 函数
返回数据库连接的默认字符集: <?php $con=mysqli_connect("localhost","my_user","my_passw ...
- 022_STM32中断优先级分组解析
(0)STM32有十六个优先级 (一)STM32分组为:组0-4 (二)分组配置在寄存器SCB->AIRCR中: (三)解析第二点 1. 组0就是4位都用来设置成响应优先级,2^4=16位都是响 ...
- @ControllerAdvice与@ControllerAdvice统一处理异常
https://blog.csdn.net/zzzgd_666/article/details/81544098(copy) 详细看此 所以结合上面我们可以知道,使用@ExceptionHandler ...
- learning express step(二)
install express-generator C:\Users\admin\WebstormProjects\learning-express-step2>npm install expr ...
- [Luogu] 软件包管理器
https://www.luogu.org/problemnew/show/P2146 几乎是一个裸题 #include<cstdio> #include<cstring> # ...
- CF917D Stranger Trees【矩阵树定理,高斯消元】
题目链接:洛谷 题目大意:给定一个$n$个节点的树$T$,令$ans_k=\sum_{T'}[|T\cap T'|=k]$,即有$k$条边重合.输出$ans_0,ans_1,\ldots,ans_{n ...
- 利用前端三大件(html+css+js)开发一个简单的“todolist”项目
一.介绍 todolist,即待办事项.在windows android ios上参考微软家出的那个To-Do应用,大概就是那样的.我这个更简单,功能只有“待办” “已完成”两项,并且是在浏览器打开的 ...
- 畅通工程续(HDU 1874)(简单最短路)
某省自从实行了很多年的畅通工程计划后,终于修建了很多路.不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多.这让行人很困扰. 现在 ...
- CodeForces - 999C Alphabetic Removals
C - Alphabetic Removals ≤k≤n≤4⋅105) - the length of the string and the number of letters Polycarp wi ...
- 数据分析之matplotlib使用
绘制折线图 参数详情 from matplotlib import pyplot as plt # 设置图片大小,dpi图片放大缩小时可以让其更清晰 plt.figure(figsize=(20,8) ...