Space Ant
Space Ant
- It can not turn right due to its special body structure.
- It leaves a red path while walking.
- It hates to pass over a previously red colored path, and never does that.
The pictures transmitted by the Discovery space ship depicts that plants in the Y1999 grow in special points on the planet. Analysis of several thousands of the pictures have resulted in discovering a magic coordinate system governing the grow points of the plants. In this coordinate system with x and y axes, no two plants share the same x or y.
An M11 needs to eat exactly one plant in each day to stay alive. When it eats one plant, it remains there for the rest of the day with no move. Next day, it looks for another plant to go there and eat it. If it can not reach any other plant it dies by the end of the day. Notice that it can reach a plant in any distance.
The problem is to find a path for an M11 to let it live longest.
Input is a set of (x, y) coordinates of plants. Suppose A with the coordinates (xA, yA) is the plant with the least y-coordinate. M11 starts from point (0,yA) heading towards plant A. Notice that the solution path should not cross itself and all of the turns should be counter-clockwise. Also note that the solution may visit more than two plants located on a same straight line.
Input
Output
Sample Input
2 10 1 4 5 2 9 8 3 5 9 4 1 7 5 3 2 6 6 3 7 10 10 8 8 1 9 2 4 10 7 6 14 1 6 11 2 11 9 3 8 7 4 12 8 5 9 20 6 3 2 7 1 6 8 2 13 9 15 1 10 14 17 11 13 19 12 5 18 13 7 3 14 10 16
Sample Output
10 8 7 3 4 9 5 6 2 1 10 14 9 10 11 5 12 8 7 6 13 4 14 1 3 2
题目大意就是,在二维平面是找出一条路径,满足:
1.只能向左弯折;
2.弯折的地方只能是给定的点集中的点;
3.路径不能与之前的有相交;
4.要求经过给定的点越多越好.
这一题用到的是凸包的思想,却不是凸包.先说结论:我们每次以前一次到达的点为最下方的点(同时为基准点),旋转这个图,下一个到达的点就是新图中最最右边,且距离x轴最近的点(先满足前一个要求).
那么这个其实就是运用到凸包的排序思想,对于上述的条件,其实只需要运用叉积做cmp来排序就好啦.由于n很小,所以这题就能稳稳地过了.
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<stack>
using namespace std;
int n,nowpos;
];
point operator - (point u,point v){point ret; ret.x=u.x-v.x,ret.y=u.y-v.y; return ret;}
int dis(point u,point v){return (u.x-v.x)*(u.x-v.x)+(u.y-v.y)*(u.y-v.y);}
int cross(point u,point v){return u.x*v.y-v.x*u.y;}
inline int read(){
,f=; char ch=getchar();
'){if (ch=='-') f=-f; ch=getchar();}
+ch-',ch=getchar();
return x*f;
}
bool cmp(const point &P,const point &Q){
||cross(P-a[nowpos],Q-a[nowpos])==&&dis(a[nowpos],P)<dis(a[nowpos],Q);
}
int main(){
for (int T=read(); T; T--){
n=read(),memset(a,,sizeof a);
; i<=n; i++) a[i].index=read(),a[i].x=read(),a[i].y=read();
; i<=n; i++) ].y||a[i].y==a[].y&&a[i].x<a[].x) swap(a[],a[i]);
nowpos=;
; i<=n; i++){
sort(a+i,a+n+,cmp); nowpos++;
}
printf("%d",n);
; i<=n; i++) printf(" %d",a[i].index);
puts("");
}
;
}
Space Ant的更多相关文章
- poj 1696 Space Ant (极角排序)
链接:http://poj.org/problem?id=1696 Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- POJ 1696 Space Ant(极角排序)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2489 Accepted: 1567 Descrip ...
- poj 1696 Space Ant(模拟+叉积)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3840 Accepted: 2397 Descrip ...
- POJ 1696 Space Ant 卷包裹法
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3316 Accepted: 2118 Descrip ...
- POJ 1696 Space Ant(点积的应用)
Space Ant 大意:有一仅仅蚂蚁,每次都仅仅向当前方向的左边走,问蚂蚁走遍全部的点的顺序输出.開始的点是纵坐标最小的那个点,開始的方向是開始点的x轴正方向. 思路:从開始点開始,每次找剩下的点中 ...
- poj1696 Space Ant【计算几何】
含极角序排序模板. Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5334 Accepted: ...
- Space Ant(极角排序)
Space Ant http://poj.org/problem?id=1696 Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...
- 2018.07.04 POJ 1696 Space Ant(凸包卷包裹)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Description The most exciting space discovery occu ...
- poj 1696:Space Ant(计算几何,凸包变种,极角排序)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2876 Accepted: 1839 Descrip ...
随机推荐
- 一个 xxx is not defined 引发的爬坑之路
出处 https://www.cnblogs.com/daysme/ - 2018-01-06 昨晚找了一个代码解决了我对配置的需求.高兴的拿到手机上测试却发现点击没有效果,电脑上是可以的呀,电脑上的 ...
- hihoCoder 1145 幻想乡的日常(树状数组 + 离线处理)
http://hihocoder.com/problemset/problem/1145?sid=1244164 题意: 幻想乡一共有n处居所,编号从1到n.这些居所被n-1条边连起来,形成了一个树形 ...
- HDU 1512 Monkey King(左偏树模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=1512 题意: 有n只猴子,每只猴子一开始有个力量值,并且互相不认识,现有每次有两只猴子要决斗,如果认识,就不打了 ...
- 蚂蚁金服首席数据科学家漆远:AI技术开放,与业界融合共创
小蚂蚁说: 11月8日,在第五届世界互联网大会-<人工智能:融合发展新机遇>论坛上,蚂蚁金服副总裁.首席数据科学家漆远认为AI具有控制风险.降本增效和提升用户体验三大作用. 11月8日,第 ...
- strip函数
f=open('a.txt',)for l in f.readlines(): print(l.strip()) # 默认清除字符串l的首尾位的\n或空格,如果是l.strip("a&qu ...
- 全排列问题(c语言实现)
问题描述: 假设有数组里面存放26个字母,取出n个,以m个排列,计算排列的总数! 注意: (1) m<n (2) 里面的元素不能重复排列 (3)"遇零则止" 核心代码如下: ...
- Codeforces 833 C - Ever-Hungry Krakozyabra
思路: 首先,inedible tails 的个数最多为C(18+9,9)个(用隔板法),所以我们暴力出所有的 inedible tails,然后检查一下在[L, R]这段区间是否存在这个inedib ...
- mui 访问系统相册将图片显示到网页
访问系统相返回值为一个对象,通过转换为字符串可以查看,path.files[0]为返回路径去除路径赋值到src 调用摄像头返回的相片的path为一个路径通过 plus.io.resolveLocalF ...
- Python学习笔记之参数解析
python提供了两种方法进行命令行的参数解析,分别是getopt和optparse类中的模块OptionParser,下面分别详细了解这两个模块: 1.getopt模块 首先复习C语言的命令行解析: ...
- v891 安卓平板的root
看了 油管的视频,标题:Onda V891 - Root Android 4.4.4 (Kit Kat) 2)下载工具,照着做就行了. 3)root完之后,安装 [钛备份](TitaniumBacku ...