极角排序合集
来源:互联网 发布:传真服务器软件 编辑:程序博客网 时间:2024/06/07 07:33
poj 2007
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <algorithm>using namespace std;struct point{ int x,y; bool operator<(point k)const{ int t=k.y*x-k.x*y; return t>0?true:false; }}p[100];int main(){ int n=0; while(scanf("%d%d",&p[n].x,&p[n].y)!=EOF)n++; sort(p+1,p+n); for(int i=0;i<n;i++){ printf("(%d,%d)\n",p[i].x,p[i].y); } return 0;}
lightoj 1285
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <algorithm>using namespace std;const int maxn=2000+5;struct point{ int x,y,id; bool operator<(point b)const{ return x==b.x?y<b.y:x<b.x; }}p[maxn];int len(int x,int y){ return x*x+y*y;}bool cmp(point z,point k){ int t=(k.y-p[0].y)*(z.x-p[0].x)-(k.x-p[0].x)*(z.y-p[0].y); if(t==0)return len(z.x-p[0].x,z.y-p[0].y)<len(k.x-p[0].x,k.y-p[0].y); return t>0;}int main(){ int t; scanf("%d",&t); for(int cas=1;cas<=t;cas++){ int n; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d%d",&p[i].x,&p[i].y); p[i].id=i; } sort(p,p+n); sort(p+1,p+n,cmp); printf("Case %d:\n",cas); point tt=p[n-1]; int pos=n-1; for(int i=n-2;i>=0;i--){ int tmp=(tt.y-p[0].y)*(p[i].x-p[0].x)-(tt.x-p[0].x)*(p[i].y-p[0].y); if(tmp!=0){ break; } pos=i; } if(pos==0){ printf("Impossible\n");continue; } reverse(p+pos,p+n); for(int i=0;i<n;i++){ printf("%d",p[i].id); if(i < n-1)printf(" "); else printf("\n"); } //printf("\n"); } return 0;}
poj 1696 Space Ant
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <algorithm>using namespace std;const int maxn=60+5;int res[maxn];int pos;struct point{ int x,y,id; bool operator<(point b)const{ return y==b.y?x<b.x:y<b.y; }}p[maxn];int len(int x,int y){ return x*x+y*y;}bool cmp(point z,point k){ int t=(k.y-p[pos].y)*(z.x-p[pos].x)-(k.x-p[pos].x)*(z.y-p[pos].y); if(t==0)return len(z.x-p[pos].x,z.y-p[pos].y)<len(k.x-p[pos].x,k.y-p[pos].y); return t>0;}int main(){ int t; scanf("%d",&t); for(int cas=1;cas<=t;cas++){ int n; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d%d%d",&p[i].id,&p[i].x,&p[i].y); } sort(p,p+n); pos=0;int k=0; for(int i=1;i<n;i++){ sort(p+i,p+n,cmp); res[pos++]=p[k++].id; } res[pos++]=p[k++].id; printf("%d",k); for(int i=0;i<pos;i++){ printf(" %d",res[i]); } printf("\n"); } return 0;}
0 0
- 极角排序合集
- 排序算法合集
- 排序合集
- 排序算法合集
- 排序算法合集
- 排序算法合集
- 排序问题合集
- 排序算法合集
- 排序算法合集
- 排序算法合集
- 排序合集
- hadoop二次排序(合集)
- 经典排序算法合集
- PHP数组排序函数合集
- PHP:数组排序函数合集
- 排序算法合集(Java)
- 史上最强排序算法合集
- C++实现排序算法合集
- java基础学习(7)浅析final,private,public,protected,static等关键以及它们的区别的联系
- C++中的句柄
- [HDU 5729] Rigid Frameworks (二分图联通方案计数)
- maven启动 cannot be cast to javax.servlet.Filter/cannot be cast to javax.servlet.Servlet 报错
- java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
- 极角排序合集
- 简单dp算法——百炼05:切割回文
- 类之间的关系
- mysql使用(2)
- Android的Window和WindowManager
- Linux数据流重定向
- 数据结构实验之链表一:顺序建立链表
- ofbiz连接mysql并创建独立数据库
- JS最佳实践