ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 G. Garden Gathering
Problem G. Garden Gathering Input file: standard input Output file: standard output Time limit: 3 seconds Memory limit: 512 megabytes Many of you may have been to St. Petersburg, but have you visited Peterhof Palace? It is a collection of splendid palaces and gardens with spectacular fountains! Besides the beauty, it is huge, and you can easily get lost in one of the park labyrinths. Imagine that you are not a regular visitor, but one of the guides, and your group of tourists is scattered across one of the gardens — a complete disaster! To continue the tour, you need to collect them all in one place, and technologies of the XXI century could be very useful in this task. Each tourist has a smartphone with a GPS tracker which transmits data directly to your phone. Unfortunately, the application for Peterhof’s guides lacks in functionality. Actually, it has the only button which, when pressed, automatically selects one person at random and tells his or her coordinates to everyone in the group. After that, all tourists immediately start to move to this position using the shortest path, while the selected person stands still and waits for others. The only thing to worry about is that you can be late for the last train home, so you want to know the maximum possible time this gathering process could take. You have a map of this garden with you: -5 -5 -4 -4 -3 -3 -2 -2 -1 -1 0 1 1 2 2 3 3 4 4 5 5 Ox Oy Picture 1: Plan of garden trails Page 9 of 17 ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 All tourists from your group travel through the park with constant speed using only the trails shown on the picture 1. If in the end you will be late, then you can ask your boss to reimburse the money spent on Yandex.Taxi. To do so, you need to present a proof in the form of two numbers: ID of the person selected by the app and ID of the person who will be the last to arrive. As you have a lot of time while the tourists are gathering, calculate any possible pair for the worst case. Input The first line of the input contains a single integer n (2 ≤ n ≤ 200 000) — the size of your group. The i-th of the next n lines contains two integers xi and yi (|xi |, |yi | ≤ 107 ) — coordinates of the tourist with ID i (numbered from 1 to n). Initial positions of all tourists are guaranteed to be distinct. Output Output ID of the selected person and ID of the last person. If there are several possible answers, output any of them. Examples standard input standard output 4 0 0 2 0 0 1 2 1 1 4 Note Picture 2: Answer for the first sample In the sample the distance between the first and the fourth tourists is √ 2 + 1. Answers (4, 1), (2, 3), and (3, 2) are also considered correct.
题意:给出方格图上N个点,点都在格点上,每个点都可以沿着上下左右,斜着四个方向,总共八个方向移动,时间花费为线的长度,问N个点到其中一个点集中,每个点都沿着最短路移动,问最后到的点最晚的时候,起点和最后到的点是哪两个点。(任意一组答案)。
分析:显然答案就是最远点对。
所以我们要求曼哈顿距离下的最远点对。
按照曼哈顿生成树的思想来做。
八个方向,根据双向性,其实每个点只用处理四个方向。而这四个方向不妨选择上面的四个方向,这样我们可以通过坐标变换用相同的方法处理。
所以我们就只用考虑一个方向,不妨考虑y=0 到 y=x 这两条直线围成的那个方向。
首先,设现在这个点为(x0, y0),要找一个这个方向上的最远点。
这个点既然在这个方向上,首先就要有x1>x0,并且y1-y0<x1-x0
然后观察时间的表达式 time = sqrt(2)*y + (x-y)
所以我们现在要求的是,对于每个点(x0, y0),找出所有的x1>x0,y1-y0<x1-x0,询问它们之中的max{time}
要保证x1>x0,我们可以将x坐标排序,然后倒序计算点即可。
要保证y1-y0<x1-x0,变形
y1-x1<y0-x0,
即找到比y0-x0小的所有yi-xi,然后找它们的max{time},这个可以用树状数组做。
注意的是:我觉得,以吾之拙见,上述方法可能将不是这个方向上的点算进来,
因为如果x0,y0 -> (0, 0),x1,y1 -> (2, -3)这样的话,虽然不在这个方向上,
但是x1>x0,y1-y0<x1-x0,
虽然可能算多,但是这种方法是不可能将这个方向上的点算少的。
也就是说,在这个方向上的最大值必定有被考虑到。
所以不影响答案和复杂度。
每个点四个方向,即上述过程要做四次,所以要O(4*nlogn)
- /**
- Create By yzx - stupidboy
- */
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <cmath>
- #include <deque>
- #include <vector>
- #include <queue>
- #include <iostream>
- #include <algorithm>
- #include <map>
- #include <set>
- #include <ctime>
- #include <iomanip>
- using namespace std;
- typedef long long LL;
- typedef double DB;
- #define MIT (2147483647)
- #define INF (1000000001)
- #define MLL (1000000000000000001LL)
- #define sz(x) ((int) (x).size())
- #define clr(x, y) memset(x, y, sizeof(x))
- #define puf push_front
- #define pub push_back
- #define pof pop_front
- #define pob pop_back
- #define ft first
- #define sd second
- #define mk make_pair
- inline int Getint()
- {
- int Ret = ;
- char Ch = ' ';
- bool Flag = ;
- while(!(Ch >= '' && Ch <= ''))
- {
- if(Ch == '-') Flag ^= ;
- Ch = getchar();
- }
- while(Ch >= '' && Ch <= '')
- {
- Ret = Ret * + Ch - '';
- Ch = getchar();
- }
- return Flag ? -Ret : Ret;
- }
- const int N = ;
- const DB SQRT2 = sqrt(2.0);
- class Point
- {
- // private : static const double AAAAA = sqrt(234);
- public :
- int x, y, index;
- inline void Read()
- {
- x = Getint();
- y = Getint();
- }
- inline bool operator <(const Point &a) const
- {
- if(x != a.x) return x < a.x;
- return y < a.y;
- }
- static DB Dist(const Point &a, const Point &b)
- {
- int dx = abs(a.x - b.x), dy = abs(a.y - b.y);
- if(dx < dy) swap(dx, dy);
- return SQRT2 * dy + (dx - dy);
- }
- inline const DB Feature()
- {
- return SQRT2 * y + (x - y);
- }
- } data[N];
- int n;
- int st, far;
- DB ans;
- class Hash
- {
- private :
- int arr[N], length;
- public :
- inline void Clear()
- {
- length = ;
- }
- inline void Insert(int x)
- {
- arr[++length] = x;
- }
- inline void GoHash()
- {
- sort(arr + , arr + + length);
- length = unique(arr + , arr + + length) - (arr + );
- //for(int i = 1; i <= length; i++) printf("%d\n", arr[i]);
- }
- inline int GetIndex(int x)
- {
- int left = , right = length, mid;
- while(left <= right)
- {
- mid = (left + right) >> ;
- if(arr[mid] < x) left = mid + ;
- else if(arr[mid] > x) right = mid - ;
- else return mid;
- }
- return ;
- }
- inline int GetLength()
- {
- return length;
- }
- } ranks;
- class TreeArray
- {
- private :
- DB value[N];
- int index[N], n;
- public :
- inline void Clear()
- {
- n = ;
- }
- inline void SetLimit(int x)
- {
- n = x;
- for(int i = ; i <= n; i++) value[i] = -1.0 * INF;
- }
- inline int Lowbit(int x)
- {
- return x & (-x);
- }
- inline void Add(Point a)
- {
- int x = ranks.GetIndex(a.y - a.x);
- //printf("%d %d %d\n", a.y - a.x, x, n);
- DB val = a.Feature();
- for( ; x <= n; x += Lowbit(x))
- if(val > value[x])
- value[x] = val, index[x] = a.index;
- }
- inline void Query(const Point &a, DB &cnt, int &idx)
- {
- cnt = -1.0 * INF, idx = ;
- int x = ranks.GetIndex(a.y - a.x);
- for( ; x; x -= Lowbit(x))
- if(cnt < value[x])
- cnt = value[x], idx = index[x];
- }
- } Store;
- inline void Input()
- {
- n = Getint();
- for(int i = ; i <= n; i++)
- {
- data[i].Read();
- data[i].index = i;
- }
- }
- inline void Solve()
- {
- //puts("adf");
- ans = -1.0 * INF, st = far = ;
- for(int dir = ; dir < ; dir++)
- {
- //puts("asdfff");
- if(dir == || dir == )
- {
- for(int i = ; i <= n; i++)
- swap(data[i].x, data[i].y);
- }
- else if(dir == )
- {
- for(int i = ; i <= n; i++)
- data[i].x = -data[i].x;
- }
- ranks.Clear();
- for(int i = ; i <= n; i++)
- ranks.Insert(data[i].y - data[i].x);
- ranks.GoHash();
- sort(data + , data + + n);
- for(int i = ; i <= n; i++)
- Store.Clear();
- Store.SetLimit(ranks.GetLength());
- //puts("asdfffffx");
- for(int i = n; i >= ; i--)
- {
- //printf("%d", i);
- DB cnt;
- int idx;
- Store.Query(data[i], cnt, idx);
- //puts("xxx");
- if(idx)
- {
- cnt -= data[i].Feature();
- if(cnt > ans) ans = cnt, st = data[i].index, far = idx;
- }
- Store.Add(data[i]);
- //puts("yyy");
- }
- }
- printf("%d %d\n", st, far);
- }
- int main()
- {
- Input();
- Solve();
- return ;
- }
有人能够解答为何在类里面
private : static const double AAAAA = sqrt(234.0);
不可以吗?
ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 G. Garden Gathering的更多相关文章
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time
Problem D. Delay Time Input file: standard input Output file: standard output Time limit: 1 second M ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 I. Illegal or Not?
I. Illegal or Not? time limit per test 1 second memory limit per test 512 megabytes input standard i ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 K. King’s Rout
K. King's Rout time limit per test 4 seconds memory limit per test 512 megabytes input standard inpu ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 H. Hashing
H. Hashing time limit per test 1 second memory limit per test 512 megabytes input standard input out ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 C. Colder-Hotter
C. Colder-Hotter time limit per test 1 second memory limit per test 512 megabytes input standard inp ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 A. Anagrams
A. Anagrams time limit per test 1 second memory limit per test 512 megabytes input standard input ou ...
- hdu 5444 Elven Postman(二叉树)——2015 ACM/ICPC Asia Regional Changchun Online
Problem Description Elves are very peculiar creatures. As we all know, they can live for a very long ...
- 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)
队名:Unlimited Code Works(无尽编码) 队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...
- Moscow Subregional 2013. 部分题题解 (6/12)
Moscow Subregional 2013. 比赛连接 http://opentrains.snarknews.info/~ejudge/team.cgi?contest_id=006570 总叙 ...
随机推荐
- "稀奇古怪的"delete this
myClass::foo(){ delete this; } .. void func(){ myClass *a = new myClass(); a->foo(); ...
- NYOJ之奇偶数分离
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAscAAAJ8CAIAAACdmZvPAAAgAElEQVR4nO3dPVLjStsG4G8T5CyEFC
- Java中常见数据结构:list与map -底层如何实现
1:集合 2 Collection(单列集合) 3 List(有序,可重复) 4 ArrayList 5 底层数据结构是数组,查询快,增删慢 6 线程不安全,效率高 7 Vector 8 底层数据结构 ...
- MVC – 6.控制器 Action方法参数与返回值
6.1 Controller接收浏览器数据 a.获取Get数据 : a1:获取路由url中配置好的制定参数: 如配置好的路由: 浏览器请求路径为: /User/Modify/1 ,MVC框架获 ...
- 重温WCF之构建一个简单的WCF(一)(1)通过控制台和IIS寄宿服务
一.理解什么是WCFWCF就是.NET平台下各种分布式技术的集成,并提供了一套统一的编程接口 二.WCF的定义WCF(Windows Communication Foundation)是微软为构建面向 ...
- MYSQL的增删改查语句样码
慢慢来,慢慢来.. 增: INSERT INTO person (person_id, fname, lname, gender, birth_date) VALUES (null, 'William ...
- poj 2001:Shortest Prefixes(字典树,经典题,求最短唯一前缀)
Shortest Prefixes Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12731 Accepted: 544 ...
- Go 中的反射要点
简介 反射是元数据编程的一种形式,指的是程序获得本身结构的一种能力.不同语言的反射模型实现不一样,本文中的反射,仅仅指的是Go语言中的反射模型. 类型以及接口 这个基本概念需要清晰,这里不详细展开. ...
- html5 基本布局+新标签+新选择器 + 线性渐变
html5 基本布局+新标签 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- 2015最新移动App设计尺寸视觉规范【图文版】(转)
如今手机app的屏幕设计尺寸参差不齐,仿佛来到了移动界面尺寸战国时代,每家移动设备制造公司都为了迎合大众的口味,各家都在2014年大放光彩.2015年也将会是我们移动APP设计界快速发展的一年. 因为 ...