https://vjudge.net/problem/2198221/origin
https://vjudge.net/problem/2198221/origin
逆向思维,原题是人出来,我们处理成人进去,算出来每个人的曼哈顿距离,然后从大到小排序,距离长的先入。走的距离+这个人从队伍中走到入口的距离的最小值就是答案
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 5000010
#define For(i,a,b) for(int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
int n,m,r,mid,k,ans; struct node{
int x,y,d;
bool operator < (const node &a)const{
return d>a.d;
}
}a[N]; void in(int &x){
int y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(int x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
}
int main(){
in(n);in(m);in(r);
For(i,,r){
in(a[i].x);in(a[i].y);
if(a[i].y>m)
a[i].d=a[i].y-m+n-a[i].x+;
else
a[i].d=m-a[i].y+n-a[i].x+;
}
sort(a+,a+r+);
For(i,,r)
ans=max(ans,(k++)+a[i].d); o(ans);
return ;
}
https://vjudge.net/problem/2198221/origin的更多相关文章
- https://vjudge.net/problem/2198220/origin
https://vjudge.net/problem/2198220/origin枚举等差数列第一个和第二个,然后二分确定数列后面是否存在,复杂度比较玄学,卡过了. #include<iostr ...
- C# webkit 内核浏览器 访问https 网站 提示 Problem with the SSL CA cert (path? access rights?)
C# webkit 内核浏览器 访问https 网站 提示 Problem with the SSL CA cert (path? access rights?) 解决方法: 陈凯文11112014- ...
- https://vjudge.net/contest/321565#problem/C 超时代码
#include <iostream> #include <cstdio> #include <queue> #include <algorithm> ...
- LOJ [#115. 无源汇有上下界可行流](https://loj.ac/problem/115)
#115. 无源汇有上下界可行流 先扔个板子,上下界的东西一点点搞,写在奇怪的合集里面 Code: #include <cstdio> #include <cstring> # ...
- POJ 2516:Minimum Cost(最小费用流)
https://vjudge.net/problem/11079/origin 题意:有N个商店和M个供应商和K种物品,每个商店每种物品有一个需求数,每个供应商每种物品有一个供应量,供应商到商店之间的 ...
- UVa 10934 Dropping water balloons:dp(递推)
题目链接:https://vjudge.net/problem/27377/origin 题意: 有一栋n层高的楼,并给你k个水球.在一定高度及以上将水球扔下,水球会摔破:在这个高度以下扔,水球不会摔 ...
- 一道简单的dp题 --- Greenhouse Effect CodeForces - 269B
题目链接: https://vjudge.net/problem/36696/origin 题目大意: 要求从1到m升序排列,点可以随意移动,问最少需要移动多少次, 思路: 动态规划 可以推出转移方程 ...
- STL复习之 map & vector --- disney HDU 2142
题目链接: https://vjudge.net/problem/40913/origin 大致题意: 这是一道纯模拟题,不多说了. 思路: map模拟,vector辅助 其中用了map的函数: er ...
- 一道dfs和dp结合的好题 --- Longest Run on a SnowboardUVA-10285
题目链接: https://vjudge.net/problem/19213/origin 大致题意: 一个滑雪者想知道自己在固定高度的山坡中最多能滑的距离是多少. 思路: 首先想到的就是dfs,但是 ...
随机推荐
- 2019 CCPC 湖南全国邀请赛
A. Chessboard 做法1 单纯形. 做法2 最大费用可行流问题,行列模型. 对每行建一个点,每列建一个点.物品 \(i\) 在 \((r,c)\),那么 \(r\) 向 \(c\) 连流量为 ...
- 《代码整洁之道》ch5~ch9读书笔记 PB16110698(~3.15) 第二周
<代码整洁之道>ch5~ch9读书笔记 本周我阅读了本书的第5~9章节,进一步了解整洁代码需要注意的几个方面:格式.对象与数据结构.错误处理.边界测试.单元测试和类的规范.以下我将分别记录 ...
- JS规则 给变量取个名字(变量命名) 必须以字母、下划线或美元符号开头;区分大小写;不允许使用JS关键字或保留字
给变量取个名字(变量命名) 我们为了区分盒子,可以用BOX1,BOX2等名称代表不同盒子,BOX1就是盒子的名字(也就是变量的名字). 我们赶快给变量取个好名字吧!变量名字可以任意取,只不过取名字要遵 ...
- 【笔记篇】C#笔记3
笔记目录:http://blog.csdn.net/enzymii/article/details/77169928 C#的接口有点意思,我们说过可以用来多重继承.. using System; na ...
- C++ 系列:基础知识储备
Copyright © 2000-2017, NORYES, All Rights Reserved. http://www.cnblogs.com/noryes/ ----------------- ...
- leetcode-109-有序链表转二叉搜索树
---恢复内容开始--- 题目描述: 方法一:O(n) O(n) class Solution: def sortedListToBST(self, head: ListNode) -> Tre ...
- String类型_static成员_动态内存分配_拷贝构造函数_const关键字_友元函数与友元类
1:String类型 #include <iostream> using namespace std; int main() { //初始化方法 string s1 = "hel ...
- [原创]新版PageOffice V4.0为什么用弹出窗口的方式打开文件?
前的包含文档处理功能的Web办公系统,在打开文档的时候,一部分系统是采用Office文档嵌入到主窗口页面中右侧工作区域的方式,另一部分系统采用的是弹出新的浏览器窗口,里面完整的嵌入Office文件的打 ...
- Django的日常-视图层
目录 Django的日常-3 JsonResponse form表单上传文件 CBV的源码分析 视图层 模板传值 过滤器 标签 自定义过滤器和标签 Django的日常-3 JsonResponse 在 ...
- 表格Table好看的样式表
caption { padding: 0 0 5px 0; width: 700px; font: italic 11px "Trebuchet MS" , Verdana, Ar ...