思维 Codeforces491B New York Hotel
来源:互联网 发布:查看图片软件哪个好 编辑:程序博客网 时间:2024/04/29 01:45
传送门:点击打开链接
题意:一个二维网状格点,先给一个n,然后有n个坐标,表示最开始n个人的坐标,然后给一个m,然后有m个坐标,现在要从m个坐标中选出一个坐标,使得这个坐标到n个坐标的最大距离最小输出最大距离最小是多少,以及最后选出的是m个点中的哪一个, n,m<=1e5,坐标有x和y,均<=1e9
思路:这题还真一下子转不过弯来了- -
首先,很明显答案应该是min{|N[i].x-M[j].x|+|N[i].y-M[j].y|},1<=i<=n,1<=j<=m
问题是,我们如何能快速求出,对于点(M[j].x,M[j].y),距离它最远的距离是多少
其实我们能够发现,|N[i].x-M[j].x|+|N[i].y-M[j].y|有4种去绝对值的方式。
然后我们能发现,加了绝对值是4种去绝对值方式中最大的。
所以我们直接维护4种取了绝对值的最大值,然后对于某次查询,直接取最大的不就行了- -
#include<map>#include<set>#include<cmath>#include<ctime>#include<stack>#include<queue>#include<cstdio>#include<cctype>#include<string>#include<vector>#include<cstring>#include<iomanip>#include<iostream>#include<algorithm>#include<functional>#define fuck(x) cout<<"["<<x<<"]"#define FIN freopen("input.txt","r",stdin)#define FOUT freopen("output.txt","w+",stdout)using namespace std;typedef long long LL;typedef pair<int, int>PII;const int MX = 1e5 + 5;const int mod = 1e9 + 7;const LL INF = 0x3f3f3f3f3f3f3f3f;int main() { //FIN; while(~scanf("%*d%*d")) { int n, m; scanf("%d", &n); LL Max[4], x, y; memset(Max, -INF, sizeof(Max)); for(int i = 1; i <= n; i++) { scanf("%I64d%I64d", &x, &y); Max[0] = max(Max[0], x + y); Max[1] = max(Max[1], x - y); Max[2] = max(Max[2], -x + y); Max[3] = max(Max[3], -x - y); } scanf("%d", &m); LL ans = INF; int id = 0; for(int i = 1; i <= m; i++) { scanf("%I64d%I64d", &x, &y); LL t = -INF; t = max(t, Max[0] - x - y); t = max(t, Max[1] - x + y); t = max(t, Max[2] + x - y); t = max(t, Max[3] + x + y); if(t < ans) ans = t, id = i; } printf("%I64d\n%d\n", ans, id); } return 0;}
0 0
- 思维 Codeforces491B New York Hotel
- Codeforces 491B New York Hotel 题解
- codeforces 491B New York Hotel(贪心,数学)
- Codeforces 491B. New York Hotel 最远曼哈顿距离
- New York city
- Nirvana:Unplugged In New York (1994)
- Nirvana-Unplugged in New York
- Running Median 2009 Greater New York Regional
- 电影 纽约黑帮 Gangs of New York
- 组队周赛_Greater New York 2004
- MobiCom 2016 --- 20161004 in New York, USA
- 【每天积累一点点】Humans of New York
- 【每天积累一点点】Humans of New York
- 【poj 1523】SPF 【Greater New York 2000】
- 【每天积累一点点】Humans of New York
- 3 New York residences raided in terrorism probe
- September 21 to 23 went to New York
- 8 27 组队赛 Greater New York 2012
- Unity3D研究院之异步加载游戏场景与异步加载游戏资源进度条(三十一)
- Java程序性能相关
- iOS_UITableView_不显示无内容部分的分割线
- Dinner(南阳oj218)(水题,主要是测试数据太弱了)
- Android studio安装过程
- 思维 Codeforces491B New York Hotel
- 黑马程序员——常用API详解之Object、Scanner、String
- Linux免密登陆
- Windows 8为何不受欢迎
- 盘点Win10优于Win8的十个地方
- Django使用Apache2.2通过Mod_wsgi搭建站点服务器
- Genymotion模拟器无法开启的解决方法——Unable to start the virtual device,The virtual device got no IP address
- 持续集成-Docker 与 DaoCloud 的实践(一)
- 程序优化