这题只能呵呵了。

东搞西搞,折腾快一天,最后用了一个800多行的代码AC了。

好好的题目你卡这种精度干啥。 还有要卡您就多卡点行不,为什么long double 又可以过。。。

废了N长时间写个了不管精度的解法,结果网上看别人都是几十行代码轻松搞定,真是要吐血。

不过 还是学了一些东西的。

第一个 :atan2() 函数

想当年sb的我还自己写了个,已知(x,y)的坐标求与x正半轴夹角的模板,但是在这题中精度就过不了了。

用法: 对于坐标(x,y),atan2(y,x) 返回 [-pi,pi] ,就是和x轴正半轴的夹角的弧度。

第二个: 为什么被卡了精度??

一开始我以为数据就10^4 ,精确的小数点后4-5就行了,后面画图分析了,根本就是扯淡。。。起码要到小数点后8-9位才行。

这样用long double  存角度,然后排序下统计下两个相邻间的夹角最小值即可,记住最前面(0)和最后面(n-1)还要加上。

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
using namespace std; struct point
{
long double angel;
int id;
}g[]; int cmp(point t,point t1)
{
return t.angel<t1.angel;
} int main()
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
{
double x,y;
cin>>x>>y;
g[i].angel = atan2(y,x);
g[i].angel = g[i].angel>?g[i].angel:g[i].angel+acos(-1.0)*;
g[i].id = i+;
}
sort(g,g+n,cmp);
long double mi=100000.0;
int a,b;
for(int i=;i<n;i++)
{
if( g[i].angel - g[i-].angel < mi )
{
mi=g[i].angel-g[i-].angel;
a=g[i].id;
b=g[i-].id;
}
}
if(g[].angel+acos(-1.0)*-g[n-].angel<mi)
{
a=g[].id;
b=g[n-].id;
}
printf("%d %d",a,b);
return ;
}

正常人的做法

接下来再看看脑残是怎么想的,还有怎么做的。。。

因为不知道有long double 这种事,(long double 在本机上测试竟然是128位的,惊呆!)

所以在多次尝试后发现精度被卡的太死了。于是换思路。。。

怎么样在不出现浮点数的情况下解决这道题。

有两个问题需要解决。

1. 极角排序

因为给出来的不是凸包,所以并不能用凸包模板,也不能直接用叉乘排序。

但是还是得排序的。。

我的做法是,把待排序的点以Y轴分成两块区域,这两块区域分别用叉乘判断排序。 这样一下就在不出现浮点数的情况下完成了极角排序。

2.得出最小角

因为之前只是排序了,并没有求出角度,所以这里也并不想求出角度。

由向量的叉积

a.b = |a||b|cos( shita )

所以对于向量a(x1,y1)和b(x2,y2),cos( shita )*cos( shita ) = (x1*x2+y1*y2)*(x1*x2+y1*y2)  /  (x1*x1+y1*y1)*(x2*x2+y2*y2)

设后面那个除式分母为 divup ,分子为divdown

则在计算两个向量的夹角可以用divup 和 divdown 代替。

这样就可以在不用浮点数的情况下得出最小夹角的那对向量。

但是可恶的是,divdown可能很大,long long 存不下。

于是。。。。。。。。

我找了个大数模板。

//
// main.cpp
// ecr1.c
//
// Created by 陈加寿 on 15/11/17.
// Copyright (c) 2015年 陈加寿. All rights reserved.
// #include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std; struct point
{
int x,y;
int id;
}g[]; int cmp(point t,point t1)
{
//分成两个象限
if(t.y== && t1.y==)
{
return t.x>t1.x;
}else
if(t.y>= && t1.y>=)
{
int tmp=t.x*t1.y-t.y*t1.x;
return tmp>;
}
else if( t.y< && t1.y< )
{
int tmp = t.x*t1.y - t.y*t1.x;
return tmp>;
}
else
{
return t.y>t1.y;
}
} //并不能这样做。
/**
向量A(x1,y1) B(x2,y2)
点乘 A.B = x1*x2 + y1*y2
叉乘 A*B = (x1*y2 - x2*y1)C(C是与AB向量平面垂直的向量)
A.B = |A||B|COS( shita ) //用来求夹角
A*B
*/ #define DIGIT 4 //四位隔开,即万进制
#define DEPTH 10000 //万进制
#define MAX 10 //题目最大位数/4,要不大直接设为最大位数也行
typedef int bignum_t[MAX+]; /************************************************************************/
/* 读取操作数,对操作数进行处理存储在数组里 */
/************************************************************************/
int read(bignum_t a,istream&is=cin)
{
char buf[MAX*DIGIT+],ch ;
int i,j ;
memset((void*)a,,sizeof(bignum_t));
if(!(is>>buf))return ;
for(a[]=strlen(buf),i=a[]/-;i>=;i--)
ch=buf[i],buf[i]=buf[a[]--i],buf[a[]--i]=ch ;
for(a[]=(a[]+DIGIT-)/DIGIT,j=strlen(buf);j<a[]*DIGIT;buf[j++]='');
for(i=;i<=a[];i++)
for(a[i]=,j=;j<DIGIT;j++)
a[i]=a[i]*+buf[i*DIGIT--j]-'' ;
for(;!a[a[]]&&a[]>;a[]--);
return ;
} void write(const bignum_t a,ostream&os=cout)
{
int i,j ;
for(os<<a[i=a[]],i--;i;i--)
for(j=DEPTH/;j;j/=)
os<<a[i]/j% ;
} int comp(const bignum_t a,const bignum_t b)
{
int i ;
if(a[]!=b[])
return a[]-b[];
for(i=a[];i;i--)
if(a[i]!=b[i])
return a[i]-b[i];
return ;
} int comp(const bignum_t a,const int b)
{
int c[]=
{ }
;
for(c[]=b;c[c[]]>=DEPTH;c[c[]+]=c[c[]]/DEPTH,c[c[]]%=DEPTH,c[]++);
return comp(a,c);
} int comp(const bignum_t a,const int c,const int d,const bignum_t b)
{
int i,t=,O=-DEPTH* ;
if(b[]-a[]<d&&c)
return ;
for(i=b[];i>d;i--)
{
t=t*DEPTH+a[i-d]*c-b[i];
if(t>)return ;
if(t<O)return ;
}
for(i=d;i;i--)
{
t=t*DEPTH-b[i];
if(t>)return ;
if(t<O)return ;
}
return t> ;
}
/************************************************************************/
/* 大数与大数相加 */
/************************************************************************/
void add(bignum_t a,const bignum_t b)
{
int i ;
for(i=;i<=b[];i++)
if((a[i]+=b[i])>=DEPTH)
a[i]-=DEPTH,a[i+]++;
if(b[]>=a[])
a[]=b[];
else
for(;a[i]>=DEPTH&&i<a[];a[i]-=DEPTH,i++,a[i]++);
a[]+=(a[a[]+]>);
}
/************************************************************************/
/* 大数与小数相加 */
/************************************************************************/
void add(bignum_t a,const int b)
{
int i= ;
for(a[]+=b;a[i]>=DEPTH&&i<a[];a[i+]+=a[i]/DEPTH,a[i]%=DEPTH,i++);
for(;a[a[]]>=DEPTH;a[a[]+]=a[a[]]/DEPTH,a[a[]]%=DEPTH,a[]++);
}
/************************************************************************/
/* 大数相减(被减数>=减数) */
/************************************************************************/
void sub(bignum_t a,const bignum_t b)
{
int i ;
for(i=;i<=b[];i++)
if((a[i]-=b[i])<)
a[i+]--,a[i]+=DEPTH ;
for(;a[i]<;a[i]+=DEPTH,i++,a[i]--);
for(;!a[a[]]&&a[]>;a[]--);
}
/************************************************************************/
/* 大数减去小数(被减数>=减数) */
/************************************************************************/
void sub(bignum_t a,const int b)
{
int i= ;
for(a[]-=b;a[i]<;a[i+]+=(a[i]-DEPTH+)/DEPTH,a[i]-=(a[i]-DEPTH+)/DEPTH*DEPTH,i++);
for(;!a[a[]]&&a[]>;a[]--);
} void sub(bignum_t a,const bignum_t b,const int c,const int d)
{
int i,O=b[]+d ;
for(i=+d;i<=O;i++)
if((a[i]-=b[i-d]*c)<)
a[i+]+=(a[i]-DEPTH+)/DEPTH,a[i]-=(a[i]-DEPTH+)/DEPTH*DEPTH ;
for(;a[i]<;a[i+]+=(a[i]-DEPTH+)/DEPTH,a[i]-=(a[i]-DEPTH+)/DEPTH*DEPTH,i++);
for(;!a[a[]]&&a[]>;a[]--);
}
/************************************************************************/
/* 大数相乘,读入被乘数a,乘数b,结果保存在c[] */
/************************************************************************/
void mul(bignum_t c,const bignum_t a,const bignum_t b)
{
int i,j ;
memset((void*)c,,sizeof(bignum_t));
for(c[]=a[]+b[]-,i=;i<=a[];i++)
for(j=;j<=b[];j++)
if((c[i+j-]+=a[i]*b[j])>=DEPTH)
c[i+j]+=c[i+j-]/DEPTH,c[i+j-]%=DEPTH ;
for(c[]+=(c[c[]+]>);!c[c[]]&&c[]>;c[]--);
}
/************************************************************************/
/* 大数乘以小数,读入被乘数a,乘数b,结果保存在被乘数 */
/************************************************************************/
void mul(bignum_t a,const int b)
{
int i ;
for(a[]*=b,i=;i<=a[];i++)
{
a[i]*=b ;
if(a[i-]>=DEPTH)
a[i]+=a[i-]/DEPTH,a[i-]%=DEPTH ;
}
for(;a[a[]]>=DEPTH;a[a[]+]=a[a[]]/DEPTH,a[a[]]%=DEPTH,a[]++);
for(;!a[a[]]&&a[]>;a[]--);
} void mul(bignum_t b,const bignum_t a,const int c,const int d)
{
int i ;
memset((void*)b,,sizeof(bignum_t));
for(b[]=a[]+d,i=d+;i<=b[];i++)
if((b[i]+=a[i-d]*c)>=DEPTH)
b[i+]+=b[i]/DEPTH,b[i]%=DEPTH ;
for(;b[b[]+];b[]++,b[b[]+]=b[b[]]/DEPTH,b[b[]]%=DEPTH);
for(;!b[b[]]&&b[]>;b[]--);
}
/**************************************************************************/
/* 大数相除,读入被除数a,除数b,结果保存在c[]数组 */
/* 需要comp()函数 */
/**************************************************************************/
void div(bignum_t c,bignum_t a,const bignum_t b)
{
int h,l,m,i ;
memset((void*)c,,sizeof(bignum_t));
c[]=(b[]<a[]+)?(a[]-b[]+): ;
for(i=c[];i;sub(a,b,c[i]=m,i-),i--)
for(h=DEPTH-,l=,m=(h+l+)>>;h>l;m=(h+l+)>>)
if(comp(b,m,i-,a))h=m- ;
else l=m ;
for(;!c[c[]]&&c[]>;c[]--);
c[]=c[]>?c[]: ;
} void div(bignum_t a,const int b,int&c)
{
int i ;
for(c=,i=a[];i;c=c*DEPTH+a[i],a[i]=c/b,c%=b,i--);
for(;!a[a[]]&&a[]>;a[]--);
}
/************************************************************************/
/* 大数平方根,读入大数a,结果保存在b[]数组里 */
/* 需要comp()函数 */
/************************************************************************/
void sqrt(bignum_t b,bignum_t a)
{
int h,l,m,i ;
memset((void*)b,,sizeof(bignum_t));
for(i=b[]=(a[]+)>>;i;sub(a,b,m,i-),b[i]+=m,i--)
for(h=DEPTH-,l=,b[i]=m=(h+l+)>>;h>l;b[i]=m=(h+l+)>>)
if(comp(b,m,i-,a))h=m- ;
else l=m ;
for(;!b[b[]]&&b[]>;b[]--);
for(i=;i<=b[];b[i++]>>=);
}
/************************************************************************/
/* 返回大数的长度 */
/************************************************************************/
int length(const bignum_t a)
{
int t,ret ;
for(ret=(a[]-)*DIGIT,t=a[a[]];t;t/=,ret++);
return ret>?ret: ;
}
/************************************************************************/
/* 返回指定位置的数字,从低位开始数到第b位,返回b位上的数 */
/************************************************************************/
int digit(const bignum_t a,const int b)
{
int i,ret ;
for(ret=a[(b-)/DIGIT+],i=(b-)%DIGIT;i;ret/=,i--);
return ret% ;
}
/************************************************************************/
/* 返回大数末尾0的个数 */
/************************************************************************/
int zeronum(const bignum_t a)
{
int ret,t ;
for(ret=;!a[ret+];ret++);
for(t=a[ret+],ret*=DIGIT;!(t%);t/=,ret++);
return ret ;
} void comp(int*a,const int l,const int h,const int d)
{
int i,j,t ;
for(i=l;i<=h;i++)
for(t=i,j=;t>;j++)
while(!(t%j))
a[j]+=d,t/=j ;
} void convert(int*a,const int h,bignum_t b)
{
int i,j,t= ;
memset(b,,sizeof(bignum_t));
for(b[]=b[]=,i=;i<=h;i++)
if(a[i])
for(j=a[i];j;t*=i,j--)
if(t*i>DEPTH)
mul(b,t),t= ;
mul(b,t);
}
/************************************************************************/
/* 组合数 */
/************************************************************************/
void combination(bignum_t a,int m,int n)
{
int*t=new int[m+];
memset((void*)t,,sizeof(int)*(m+));
comp(t,n+,m,);
comp(t,,m-n,-);
convert(t,m,a);
delete[]t ;
}
/************************************************************************/
/* 排列数 */
/************************************************************************/
void permutation(bignum_t a,int m,int n)
{
int i,t= ;
memset(a,,sizeof(bignum_t));
a[]=a[]= ;
for(i=m-n+;i<=m;t*=i++)
if(t*i>DEPTH)
mul(a,t),t= ;
mul(a,t);
} #define SGN(x) ((x)>0?1:((x)<0?-1:0))
#define ABS(x) ((x)>0?(x):-(x)) int read(bignum_t a,int&sgn,istream&is=cin)
{
char str[MAX*DIGIT+],ch,*buf ;
int i,j ;
memset((void*)a,,sizeof(bignum_t));
if(!(is>>str))return ;
buf=str,sgn= ;
if(*buf=='-')sgn=-,buf++;
for(a[]=strlen(buf),i=a[]/-;i>=;i--)
ch=buf[i],buf[i]=buf[a[]--i],buf[a[]--i]=ch ;
for(a[]=(a[]+DIGIT-)/DIGIT,j=strlen(buf);j<a[]*DIGIT;buf[j++]='');
for(i=;i<=a[];i++)
for(a[i]=,j=;j<DIGIT;j++)
a[i]=a[i]*+buf[i*DIGIT--j]-'' ;
for(;!a[a[]]&&a[]>;a[]--);
if(a[]==&&!a[])sgn= ;
return ;
}
struct bignum
{
bignum_t num ;
int sgn ;
public :
inline bignum()
{
memset(num,,sizeof(bignum_t));
num[]= ;
sgn= ;
}
inline int operator!()
{
return num[]==&&!num[];
}
inline bignum&operator=(const bignum&a)
{
memcpy(num,a.num,sizeof(bignum_t));
sgn=a.sgn ;
return*this ;
}
inline bignum&operator=(const int a)
{
memset(num,,sizeof(bignum_t));
num[]= ;
sgn=SGN (a);
add(num,sgn*a);
return*this ;
}
;
inline bignum&operator+=(const bignum&a)
{
if(sgn==a.sgn)add(num,a.num);
else if
(sgn&&a.sgn)
{
int ret=comp(num,a.num);
if(ret>)sub(num,a.num);
else if(ret<)
{
bignum_t t ;
memcpy(t,num,sizeof(bignum_t));
memcpy(num,a.num,sizeof(bignum_t));
sub (num,t);
sgn=a.sgn ;
}
else memset(num,,sizeof(bignum_t)),num[]=,sgn= ;
}
else if(!sgn)
memcpy(num,a.num,sizeof(bignum_t)),sgn=a.sgn ;
return*this ;
}
inline bignum&operator+=(const int a)
{
if(sgn*a>)add(num,ABS(a));
else if(sgn&&a)
{
int ret=comp(num,ABS(a));
if(ret>)sub(num,ABS(a));
else if(ret<)
{
bignum_t t ;
memcpy(t,num,sizeof(bignum_t));
memset(num,,sizeof(bignum_t));
num[]= ;
add(num,ABS (a));
sgn=-sgn ;
sub(num,t);
}
else memset(num,,sizeof(bignum_t)),num[]=,sgn= ;
}
else if
(!sgn)sgn=SGN(a),add(num,ABS(a));
return*this ;
}
inline bignum operator+(const bignum&a)
{
bignum ret ;
memcpy(ret.num,num,sizeof (bignum_t));
ret.sgn=sgn ;
ret+=a ;
return ret ;
}
inline bignum operator+(const int a)
{
bignum ret ;
memcpy(ret.num,num,sizeof (bignum_t));
ret.sgn=sgn ;
ret+=a ;
return ret ;
}
inline bignum&operator-=(const bignum&a)
{
if(sgn*a.sgn<)add(num,a.num);
else if
(sgn&&a.sgn)
{
int ret=comp(num,a.num);
if(ret>)sub(num,a.num);
else if(ret<)
{
bignum_t t ;
memcpy(t,num,sizeof(bignum_t));
memcpy(num,a.num,sizeof(bignum_t));
sub(num,t);
sgn=-sgn ;
}
else memset(num,,sizeof(bignum_t)),num[]=,sgn= ;
}
else if(!sgn)add (num,a.num),sgn=-a.sgn ;
return*this ;
}
inline bignum&operator-=(const int a)
{
if(sgn*a<)add(num,ABS(a));
else if(sgn&&a)
{
int ret=comp(num,ABS(a));
if(ret>)sub(num,ABS(a));
else if(ret<)
{
bignum_t t ;
memcpy(t,num,sizeof(bignum_t));
memset(num,,sizeof(bignum_t));
num[]= ;
add(num,ABS(a));
sub(num,t);
sgn=-sgn ;
}
else memset(num,,sizeof(bignum_t)),num[]=,sgn= ;
}
else if
(!sgn)sgn=-SGN(a),add(num,ABS(a));
return*this ;
}
inline bignum operator-(const bignum&a)
{
bignum ret ;
memcpy(ret.num,num,sizeof(bignum_t));
ret.sgn=sgn ;
ret-=a ;
return ret ;
}
inline bignum operator-(const int a)
{
bignum ret ;
memcpy(ret.num,num,sizeof(bignum_t));
ret.sgn=sgn ;
ret-=a ;
return ret ;
}
inline bignum&operator*=(const bignum&a)
{
bignum_t t ;
mul(t,num,a.num);
memcpy(num,t,sizeof(bignum_t));
sgn*=a.sgn ;
return*this ;
}
inline bignum&operator*=(const int a)
{
mul(num,ABS(a));
sgn*=SGN(a);
return*this ;
}
inline bignum operator*(const bignum&a)
{
bignum ret ;
mul(ret.num,num,a.num);
ret.sgn=sgn*a.sgn ;
return ret ;
}
inline bignum operator*(const int a)
{
bignum ret ;
memcpy(ret.num,num,sizeof (bignum_t));
mul(ret.num,ABS(a));
ret.sgn=sgn*SGN(a);
return ret ;
}
inline bignum&operator/=(const bignum&a)
{
bignum_t t ;
div(t,num,a.num);
memcpy (num,t,sizeof(bignum_t));
sgn=(num[]==&&!num[])?:sgn*a.sgn ;
return*this ;
}
inline bignum&operator/=(const int a)
{
int t ;
div(num,ABS(a),t);
sgn=(num[]==&&!num [])?:sgn*SGN(a);
return*this ;
}
inline bignum operator/(const bignum&a)
{
bignum ret ;
bignum_t t ;
memcpy(t,num,sizeof(bignum_t));
div(ret.num,t,a.num);
ret.sgn=(ret.num[]==&&!ret.num[])?:sgn*a.sgn ;
return ret ;
}
inline bignum operator/(const int a)
{
bignum ret ;
int t ;
memcpy(ret.num,num,sizeof(bignum_t));
div(ret.num,ABS(a),t);
ret.sgn=(ret.num[]==&&!ret.num[])?:sgn*SGN(a);
return ret ;
}
inline bignum&operator%=(const bignum&a)
{
bignum_t t ;
div(t,num,a.num);
if(num[]==&&!num[])sgn= ;
return*this ;
}
inline int operator%=(const int a)
{
int t ;
div(num,ABS(a),t);
memset(num,,sizeof (bignum_t));
num[]= ;
add(num,t);
return t ;
}
inline bignum operator%(const bignum&a)
{
bignum ret ;
bignum_t t ;
memcpy(ret.num,num,sizeof(bignum_t));
div(t,ret.num,a.num);
ret.sgn=(ret.num[]==&&!ret.num [])?:sgn ;
return ret ;
}
inline int operator%(const int a)
{
bignum ret ;
int t ;
memcpy(ret.num,num,sizeof(bignum_t));
div(ret.num,ABS(a),t);
memset(ret.num,,sizeof(bignum_t));
ret.num[]= ;
add(ret.num,t);
return t ;
}
inline bignum&operator++()
{
*this+= ;
return*this ;
}
inline bignum&operator--()
{
*this-= ;
return*this ;
}
;
inline int operator>(const bignum&a)
{
return sgn>?(a.sgn>?comp(num,a.num)>:):(sgn<?(a.sgn<?comp(num,a.num)<:):a.sgn<);
}
inline int operator>(const int a)
{
return sgn>?(a>?comp(num,a)>:):(sgn<?(a<?comp(num,-a)<:):a<);
}
inline int operator>=(const bignum&a)
{
return sgn>?(a.sgn>?comp(num,a.num)>=:):(sgn<?(a.sgn<?comp(num,a.num)<=:):a.sgn<=);
}
inline int operator>=(const int a)
{
return sgn>?(a>?comp(num,a)>=:):(sgn<?(a<?comp(num,-a)<=:):a<=);
}
inline int operator<(const bignum&a)
{
return sgn<?(a.sgn<?comp(num,a.num)>:):(sgn>?(a.sgn>?comp(num,a.num)<:):a.sgn>);
}
inline int operator<(const int a)
{
return sgn<?(a<?comp(num,-a)>:):(sgn>?(a>?comp(num,a)<:):a>);
}
inline int operator<=(const bignum&a)
{
return sgn<?(a.sgn<?comp(num,a.num)>=:):(sgn>?(a.sgn>?comp(num,a.num)<=:):a.sgn>=);
}
inline int operator<=(const int a)
{
return sgn<?(a<?comp(num,-a)>=:):
(sgn>?(a>?comp(num,a)<=:):a>=);
}
inline int operator==(const bignum&a)
{
return(sgn==a.sgn)?!comp(num,a.num): ;
}
inline int operator==(const int a)
{
return(sgn*a>=)?!comp(num,ABS(a)): ;
}
inline int operator!=(const bignum&a)
{
return(sgn==a.sgn)?comp(num,a.num): ;
}
inline int operator!=(const int a)
{
return(sgn*a>=)?comp(num,ABS(a)): ;
}
inline int operator[](const int a)
{
return digit(num,a);
}
friend inline istream&operator>>(istream&is,bignum&a)
{
read(a.num,a.sgn,is);
return is ;
}
friend inline ostream&operator<<(ostream&os,const bignum&a)
{
if(a.sgn<)
os<<'-' ;
write(a.num,os);
return os ;
}
friend inline bignum sqrt(const bignum&a)
{
bignum ret ;
bignum_t t ;
memcpy(t,a.num,sizeof(bignum_t));
sqrt(ret.num,t);
ret.sgn=ret.num[]!=||ret.num[];
return ret ;
}
friend inline bignum sqrt(const bignum&a,bignum&b)
{
bignum ret ;
memcpy(b.num,a.num,sizeof(bignum_t));
sqrt(ret.num,b.num);
ret.sgn=ret.num[]!=||ret.num[];
b.sgn=b.num[]!=||ret.num[];
return ret ;
}
inline int length()
{
return :: length(num);
}
inline int zeronum()
{
return :: zeronum(num);
}
inline bignum C(const int m,const int n)
{
combination(num,m,n);
sgn= ;
return*this ;
}
inline bignum P(const int m,const int n)
{
permutation(num,m,n);
sgn= ;
return*this ;
}
}; /*
int main()
{
bignum a,b,c;
cin>>a>>b;
cout<<"加法:"<<a+b<<endl;
cout<<"减法:"<<a-b<<endl;
cout<<"乘法:"<<a*b<<endl;
cout<<"除法:"<<a/b<<endl;
c=sqrt(a);
cout<<"平方根:"<<c<<endl;
cout<<"a的长度:"<<a.length()<<endl;
cout<<"a的末尾0个数:"<<a.zeronum()<<endl<<endl;
cout<<"组合: 从10个不同元素取3个元素组合的所有可能性为"<<c.C(10,3)<<endl;
cout<<"排列: 从10个不同元素取3个元素排列的所有可能性为"<<c.P(10,3)<<endl;
return 0 ;
}
*/ int main(int argc, const char * argv[]) {
// insert code here...
printf("%d\n",sizeof(long double));
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&g[i].x,&g[i].y);
g[i].id=i+;
}
sort(g,g+n,cmp); int flag=-;
bignum up,dn;
int x,y;
for(int i=;i<=n;i++)
{
int tflag=-;
bignum tup;
tup = ( g[i].y*g[i-].y + g[i].x*g[i-].x);
bignum tdn;
tdn = ( g[i].x*g[i].x + g[i].y*g[i].y );
bignum tdn1;
tdn1=( g[i-].x*g[i-].x + g[i-].y*g[i-].y);
tdn *= tdn1;
if(i==n)
{
tup = (g[n-].y*g[].y+g[n-].x*g[].x);
tdn = (g[n-].x*g[n-].x + g[n-].y*g[n-].y);
tdn1= (g[].x*g[].x + g[].y*g[].y);
tdn *= tdn1;
}
if(tup >= ) //角度在0-90
{
tup *= tup;
tflag = ;
if(tflag >= flag)
{
if(tflag > flag)
{
flag=tflag;
up=tup;
dn=tdn;
if(i==n)
{
x=g[n-].id;
y=g[].id;
}
else
{
x=g[i].id;
y=g[i-].id; }
}
else
{
if( tup*dn > tdn*up )
{
up=tup;
dn=tdn;
if(i==n)
{
x=g[n-].id;
y=g[].id;
}
else
{
x=g[i].id;
y=g[i-].id; }
}
} }
}
else //角度>90
{
tup=tup*tup;
tflag=;
if(tflag>=flag)
{
if(tflag>flag)
{
flag=tflag;
up=tup;
dn=tdn;
if(i==n)
{
x=g[n-].id;
y=g[].id;
}
else
{
x=g[i].id;
y=g[i-].id; }
}
else
{
if( tup*dn < tdn*up )
{
up=tup;
dn=tdn;
if(i==n)
{
x=g[n-].id;
y=g[].id;
}
else
{
x=g[i].id;
y=g[i-].id; }
}
} }
}
}
printf("%d %d",x,y);
return ;
}

脑残做法

最后还有一点疑问???

前面那个AC是用的long double ,下面那个AC是我用大数模板做的。 为什么时间相差这么多??? 我怀疑是long double 搞得鬼。。。

最后再收藏一个超长精度的PI

const long double pi = 3.1415926535897932384626433832795028841971;

 第三种做法 大神是在怎么写代码的。。。

看了大神的代码,顿时又觉得自己简直就是头猪。

在进行第二步,记录最小夹角的时候完全可以把夹角表示成一个向量。

具体方法是:

假设要求向量a和向量b的夹角,那么把向量a投影到向量b上得到x,投影到与向量b垂直的方向得到y

其实就是(|a||b|cos( shita ) ,| |a||b|sin( shita ) |),就是点积和叉积

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std; const long double pi=acos(-1.0); struct point{
long long x,y;
long double angle;
int id;
}g[]; int cmp(point t,point t1)
{
return t.angle<t1.angle;
} long long cross(point a,point b)
{
return a.x*b.y-a.y*b.x;
} long long dot(point a,point b)
{
return a.x*b.x + a.y*b.y;
} long long mabs(long long x)
{
if(x<) return -x;
return x;
} int main()
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
{
cin>>g[i].x>>g[i].y;
g[i].angle = atan2(g[i].y,g[i].x);
g[i].id = i+;
g[i].angle = g[i].angle > ? g[i].angle:g[i].angle+*pi;
}
sort(g,g+n,cmp);
point mi;
int a,b;
mi.x = -;
mi.y = ; //最开始初始化,最大pi
for(int i=;i<n;i++)
{
point tmp;
tmp.x = dot(g[i],g[(i+)%n]);
tmp.y = mabs( cross(g[i],g[(i+)%n]) );
if( cross(tmp,mi) < ) continue;
mi=tmp;
a=g[i].id;
b=g[(i+)%n].id;
}
printf("%d %d\n",a,b);
return ;
}

大神的做法

Educational Codeforces Round 1 (C) (atan2 + long double | 大数)的更多相关文章

  1. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  3. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  4. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  5. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  6. Educational Codeforces Round 32

    http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...

  7. Educational Codeforces Round 34 (Rated for Div. 2) A B C D

    Educational Codeforces Round 34 (Rated for Div. 2) A Hungry Student Problem 题目链接: http://codeforces. ...

  8. CodeForces 837F - Prefix Sums | Educational Codeforces Round 26

    按tutorial打的我血崩,死活挂第四组- - 思路来自FXXL /* CodeForces 837F - Prefix Sums [ 二分,组合数 ] | Educational Codeforc ...

  9. Educational Codeforces Round 41

    Educational Codeforces Round 41  D. Pair Of Lines 考虑先把凸包找出来,如果凸包上的点数大于\(4\)显然不存在解,小于等于\(2\)必然存在解 否则枚 ...

  10. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

随机推荐

  1. ubuntu14.04安装 chrome

    安装谷歌浏览器,只需要三行代码: 打开终端,输入 cd /tmp 对于谷歌Chrome32位版本,使用如下链接: wget https://dl.google.com/linux/direct/goo ...

  2. 最长公共字串算法, 文本比较算法, longest common subsequence(LCS) algorithm

    ''' merge two configure files, basic file is aFile insert the added content of bFile compare to aFil ...

  3. Java高级特性—JVM

    1).java监控工具使用 jconsole是一种集成了上面所有命令功能的可视化工具,可以分析jvm的内存使用情况和线程等信息 visualvm 提供了和jconsole的功能类似,提供了一大堆的插件 ...

  4. angular 中的$event 对象包含了浏览器原生的event对象

    ou can pass the $event object as an argument when calling the function. The $event object contains t ...

  5. zabbix web监测

    web monitoring(监测)属于业务监控,用来监控Web站点多方面的可用性,可以监控Web站点的下载速度.返回码和响应时间.Zabbix能够检测HTML中包含的预先定义的字符串,也可以模拟登录 ...

  6. 为什么JVM指定-Xmx参数后占用内存会变少?

    嘿,你能顺便过来看看这个奇怪的事情吗?” 就是让我提供支持的这个事情,驱使我写下这篇博客的.这个特殊的问题是,不同工具给出的可用内存的报告是不一样的. 简而言之,工程师正在调查特定应用程序的内存使用. ...

  7. vue slot slot-scope

    https://segmentfault.com/a/1190000012996217 插槽,也就是slot,是组件的一块HTML模板,这块模板显示不显示.以及怎样显示由父组件来决定. 实际上,一个s ...

  8. ES6 动态计算属性名

    在ES5之前,如果属性名是个变量或者需要动态计算,则只能通过 对象.[变量名] 的方式去访问. <script type="text/javascript"> var ...

  9. Effective C++ Item 25 考虑写出一个不抛异常的swap函数

    本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 经验:当std::swap对你的类型效率不高时,提供一个swap成员函数,并确定这个函数不抛 ...

  10. 微软在GitHub上开放源代码

    https://github.com/MSOpenTech 点击链接:openFrameworks :https://github.com/openframeworks/openFrameworks ...