poj 1696Space Ant
来源:互联网 发布:小学语文课文配音软件 编辑:程序博客网 时间:2024/05/21 17:03
学习网站:
http://www.cnblogs.com/Booble/archive/2011/02/28/1967179.html
http://blog.csdn.net/lyy289065406/article/details/6648614
卷包裹算法
#include <cstdio>#include <cstring>using namespace std;struct point{ int x,y;};int dis(point a,point b){ return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}int det(int x1,int y1,int x2,int y2){ return x1*y2-x2*y1;}int cor(point b,point a,point d,point c){ return det(b.x-a.x,b.y-a.y,d.x-c.x,d.y-c.y);}int main(){ //freopen("D:\\INPUT.txt","r", stdin); int cas,n,fi,miny,minx; cin>>cas; while(cas--){ int num; miny=101; minx=101; cin>>n; point p[51];//point* p=new point[n+1]; int line[51];//int* line=new int[n+1]; int fii; bool vis[51];//bool* vis=new bool[n+1]; memset(vis,0,sizeof(vis)); int i,j,k; for(i=0;i<n;i++){ cin>>num; cin>>p[i].x>>p[i].y; if(p[i].y<miny||(p[i].y==miny&&minx>p[i].x)){ miny=p[i].y; minx=p[i].x; fi=i; } } line[1]=fi; //cout<<"fi: "<<fi<<endl; vis[fi]=true; line[0]=1; while(n!=line[0]){ for(i=0;i<n;i++){ if(!vis[i]){ fii=i; break; } } //cout<<"基准点: "<<i-1<<' '<<fii<<' '; for(i=0;i<n;i++){ if(i!=fii&&!vis[i]){ int temp=cor(p[fii],p[fi],p[i],p[fi]); if(temp<0||(!temp&&dis(p[fi],p[fii])>dis(p[fi],p[i]))){ fii=i; } } } //cout<<"新基准点: "<<i-1<<' '<<fii<<' '; line[++line[0]]=fi=fii; vis[fii]=true; //cout<<fii+1<<' '<<line[0]<<' '<<line[]<<endl; } //cout<<'!'<<vis[8]<<endl; cout<<line[0]; for(i=1;i<=n;i++){ cout<<' '<<line[i]+1; } cout<<endl; //delete p; //delete vis; //delete line; } return 0;}
0 0
- POJ 1696 Space Ant
- POJ 1696 Space Ant
- poj 1696 Space Ant
- POJ 1696 Space Ant
- poj 1696 Space Ant
- poj 1696Space Ant
- Poj-1696-Space Ant
- POJ 1696Space Ant
- POJ 1696 Space Ant
- POJ 1696 Space Ant 贪心
- Space Ant - POJ 1696 叉积
- zoj 1429 || poj 1696 Space Ant
- poj 1696 Space Ant--有关极角
- POJ 1696 Space Ant (点积)
- Poj 1696 Space Ant (凸包卷包裹)
- poj 1696 Space Ant(计算几何)
- poj-1696-Space Ant-极角排序
- POJ 1696 Space Ant(卷包裹)
- hdu 1054 树形dp
- Cocos2d-x内存管理机制
- Linux命令之uname -r
- Linux学习笔记(六)
- 精妙Sql语句(转)
- poj 1696Space Ant
- nginx 配置优化的几个参数
- HDU 1003 Max Sum 动态规划
- hdu 4981 Goffi and Median(水题)
- 反动的收费热发电
- XE6生成EXE图标修改不生效解决方案
- 杭电2700 Parity(睡前一水)
- hdu 4982 Goffi and Squary Partition(构造)
- __call()函数