Codeforces Round #319 (Div. 2)E Points on Plane
来源:互联网 发布:数据库地址 编辑:程序博客网 时间:2024/04/28 15:35
题意:给出n个点,要求排序后,相邻两点的欧拉距离之和小于等于2.5e9
做法:由于0≤ xi, yi ≤ 1e6,所以可以将x<=1000的点分成一份,1000<x<=2000的点分成第二份,以此类推,分成一千份。
然后每一份中的点都按照y单调排序。拿任意一份点做实验,如果从最小的y开始往上走,那么y的贡献最多1e6,那么一千份就总共最多贡献1e9。
做法:由于0≤ xi, yi ≤ 1e6,所以可以将x<=1000的点分成一份,1000<x<=2000的点分成第二份,以此类推,分成一千份。
然后每一份中的点都按照y单调排序。拿任意一份点做实验,如果从最小的y开始往上走,那么y的贡献最多1e6,那么一千份就总共最多贡献1e9。
最后考虑x的贡献,在某一份点中,从一个点走到另一个点最多贡献1e3,那么这份总共最多贡献1e9,也就是所有点都在这一份里面,那么考虑所有点集,那x总共贡献1e9。如果分散在其它点集中,那么总共贡献大概想想也是1e9。加起来是2e9,必然满足要求。
所以,排个序就可以做了。
#include<bits\stdc++.h>using namespace std;struct point{int id,x,y;bool operator < (point a)const{return y<a.y;}};vector<point> p[1005];int main(){ int n;cin >> n;for(int i = 1;i<=n;i++){point t;scanf("%d%d",&t.x,&t.y);t.id = i;p[t.x/1000].push_back(t);}int flag = 0;for(int i = 0;i<=1000;i++){sort(p[i].begin(),p[i].end());if(p[i].size()){int len = p[i].size();if(!flag)for(int j = 0;j<len;j++)printf("%d ",p[i][j].id);else for(int j = len-1;j>=0;j--)printf("%d ",p[i][j].id);flag^=1;}}}
0 0
- Codeforces Round #319 (Div. 2)E Points on Plane
- Codeforces Round #319 (Div. 2) E - Points on Plane, 第一次做“构造法”
- Codeforces Round #170 (Div. 1) E.Binary Tree on Plane
- [Codeforces 277E][Round #170 div.1 E]Binary Tree on Plane
- Codeforces Round #170 (Div. 1) E. Binary Tree on Plane(费用流)
- 【Codeforces Round #170】Codeforces 277E Binary Tree on Plane
- codeforces 576C Points on Plane
- Codeforces Round #149 (Div. 2) E. XOR on Segment
- Codeforces Round #149 (Div. 2) E - XOR on Segment
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)C. Five Dimensional Points
- Codeforces Round #440 Div. 2 E:Points, Lines and Ready-made Titles
- Codeforces Round #232 (Div. 2) A. On Segment's Own Points
- Codeforces Round #232 (Div. 2) A.On Segment's Own Points(区间统计)
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E
- Codeforces Round #454 (Div. 2, based on Technocup 2018 Elimination Round 4) E
- [构造 分块] Codeforces #576C. Points on Plane
- Codeforces Round #319 (Div. 2)(A,B,C,E)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Android 自定义View (一)
- Codeforces Round #319 (Div. 2) B Modulo Sum
- V
- scala学习之Map、Tuple、zip
- 第四届河南省程序设计大赛
- Codeforces Round #319 (Div. 2)E Points on Plane
- LeetCode:Letter Combinations of a Phone Number
- 调整基于HAAR特征的AdaBoost级联分类器的物体识别的参数
- 解决python画图标签中文乱码
- Android购物车初步实现2(功能篇)
- CentOS系统配置.ssh遇到port 22:No route to host问题的解决方法
- Android Agera 框架简单使用
- C++ vector 用法
- 21. Merge Two Sorted Lists(Linked List)