POJ-1696 极坐标排序
来源:互联网 发布:apache io模型 编辑:程序博客网 时间:2024/05/22 17:30
先不会,后来看了discus才知道,用极坐标排序,换句话说,按着偏转的角度从小到大,相同的按距离从小到大。最后形成的路线是一个螺旋形的折线。
#include<cstdio>#include<algorithm>using namespace std;struct node {int id,x,y;}p[105];node rec[105];int pos,cnt;int Judge(node a,node b,node c){return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);}int dis(node a,node b){return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}bool cmp(node &a,node &b){int t;t=Judge(p[pos],a,b);if(t>0) return true;else if(!t&&dis(p[pos],a)<dis(p[pos],b)) return true;return false;}int main(){int t,n,i;scanf("%d",&t);while(t--){scanf("%d",&n);for(i=0;i<n;i++){scanf("%d %d %d",&p[i].id,&p[i].x,&p[i].y);if(p[i].y<p[0].y) swap(p[i],p[0]);}cnt=pos=0;sort(p+pos,p+n,cmp);rec[cnt++]=p[pos++];for(i=2;i<n;i++){sort(p+pos,p+n,cmp);rec[cnt++]=p[pos++];}rec[cnt++]=p[pos++];printf("%d",cnt);for(i=0;i<cnt;i++){printf(" %d",rec[i].id);}printf("\n");}return 0;}
- POJ-1696 极坐标排序
- 【POJ 2280】Amphiphilic Carbon Molecules(极角排序+坐标转换+扫描线)
- poj 1696 极角排序
- POJ 1696 极角排序
- poj 1696(极角排序)
- POJ 1696 极角排序
- poj-1696-Space Ant-极角排序
- poj 1696 :Space Ant (极角排序)
- Poj 1696 Space Ant 【极角排序】
- 坐标点排序问题
- 多点坐标排序算法
- sort 对坐标 排序
- 坐标点排序
- 四边形坐标顺时针排序
- 二维坐标排序
- poj 2007(极角排序)
- POJ 1106 极角排序
- POJ 2007 极角排序
- 如何判断windows程序是32还是64位
- Image editing techniques and algorithms using Qt
- 8月20日,看了些什么?
- WNR2200拆机图
- 20130820-J-LINK -V8掉固件,灯不亮,USB无法识别的解决办法
- POJ-1696 极坐标排序
- Java添加水印(图片水印,文字水印)
- Struts2与FCK整合 请求冲突的解决方法
- struts2 拦截器使用配置
- mysql 远程访问和绑定IP
- txt文件数据导入MYSQL数据库
- java xml读写操作--------读取
- 验证码验证不同步处理方法
- TOMCAT停止-删文件-启动