极角排序合集
2016-07-24 09:03
197 查看
poj 2007
lightoj 1285
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;
}
#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 .x,&p .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;
}
相关文章推荐
- POJ 2007 Scrambled Polygon(极角排序)
- UVALive 4617 Simple Polygon(顺/逆时针输出所有点/极角排序)
- POJ1696-Space Ant
- hdu 5738 Eureka 极角排序 计数
- HDU 5032 Always Cook Mushroom(极角排序, 树状数组)
- BZOJ 1914: [Usaco2010 OPen]Triangle Counting 数三角形
- 极角排序
- hdoj 5784 && 极角排序
- hdu 5784 How Many Triangles 极角排序计算锐角直角钝角
- HDU-3629-Convex-计算几何
- 极角排序(主要用于凸包问题)
- hdu6127-!!多校7&极角排序&问题转化-Hard challenge
- (2017多校训练第七场)HDU - 6127 Hard challenge 极角排序+尺取法
- 2017杭电多校第七场1008 Hard challenge(级角排序)HDU 6127
- 简单dp算法——百炼05:切割回文
- java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
- maven启动 cannot be cast to javax.servlet.Filter/cannot be cast to javax.servlet.Servlet 报错
- ButterKnife-5.1.2.jar(较低版本的ButterKnife)使用方法
- get last dirname/filename in a file path argument
- netstat命令详解