1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| #include<algorithm> #include<iostream> #include<iomanip> #include<cstring> #include<cstdlib> #include<climits> #include<vector> #include<cstdio> #include<cmath> #include<queue> using namespace std;
inline const int Get_Int() { int num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num*bj; }
const int maxn=50005; const double eps=1e-12;
int dcmp(double x) { if(fabs(x)<=eps)return 0; return x>eps?1:-1; }
struct Point { double x,y; int id; Point(double _x=0,double _y=0,int _id=0):x(_x),y(_y),id(_id) {} Point operator - (const Point& b) const { return Point(b.x-x,b.y-y); } bool operator < (const Point& b) const { return x<b.x||(x==b.x&&y<b.y); } } p[maxn];
typedef Point Vector;
double Cross(const Vector& a,const Vector& b) { return a.x*b.y-a.y*b.x; }
int ConvexHull(int n,Point* p,Point* ans) { sort(p+1,p+n+1); int top=0; for(int i=1; i<=n; i++) { while(top>1&&dcmp(Cross(ans[top-1]-p[i],ans[top-1]-ans[top]))>=0)top--; ans[++top]=p[i]; } int k=top; for(int i=n-1; i>=1; i--) { while(top>k&&dcmp(Cross(ans[top-1]-p[i],ans[top-1]-ans[top]))>=0)top--; ans[++top]=p[i]; } if(n>1)top--; return top; }
int ansa,ansb;
double Rotating_Calipers(int n,Point* p) { double ans=0; p[n+1]=p[1]; int b=1; for(int a=1; a<=n; a++) { while(dcmp(fabs(Cross(p[a],p[b+1]))-fabs(Cross(p[a],p[b])))>=0)b=b%n+1; if(dcmp(fabs(Cross(p[a],p[b]))-ans)>0) { ans=fabs(Cross(p[a],p[b])); int tmpa=a,tmpb=b; if(Cross(p[a],p[b])<0)swap(tmpa,tmpb); ansa=p[tmpa].id; ansb=p[tmpb].id; } } b=n; p[0]=p[n]; for(int a=n; a>=1; a--) { while(dcmp(fabs(Cross(p[a],p[b-1]))-fabs(Cross(p[a],p[b])))>=0)b=b==1?n:b-1; if(dcmp(fabs(Cross(p[a],p[b]))-ans)>0) { ans=fabs(Cross(p[a],p[b])); int tmpa=a,tmpb=b; if(Cross(p[a],p[b])<0)swap(tmpa,tmpb); ansa=p[tmpa].id; ansb=p[tmpb].id; } } return ans; }
int n; Point ans[maxn];
int main() { n=Get_Int(); for(int i=1; i<=n; i++) { double m,c; scanf("%lf%lf",&m,&c); p[i]=Point(m*c,m,i); } int tot=ConvexHull(n,p,ans); Rotating_Calipers(tot,ans); printf("%d %d\n",ansa,ansb); printf("%d\n",tot); for(int i=1; i<=tot; i++)printf("%d ",ans[i].id); return 0; }
|