标签:
二分边长,判断最后内角和是否为2pi,注意l与r的选取,保证能组成三角形
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #define MOD 1000000007 10 const int INF=0x3f3f3f3f; 11 typedef long long ll; 12 #define cl(a) memset(a,0,sizeof(a)) 13 #define ts printf("*****\n"); 14 const int MAXN=1005; 15 int n,m,tt; 16 const double eps = 1e-8; 17 const double pi = acos(-1.0); 18 double a[MAXN]; 19 int main() 20 { 21 int i,j,k; 22 #ifndef ONLINE_JUDGE 23 freopen("1.in","r",stdin); 24 #endif 25 scanf("%d",&tt); 26 int ca=1; 27 while(tt--) 28 { 29 scanf("%d",&n); 30 for(i=0;i<n;i++) 31 { 32 scanf("%lf",&a[i]); 33 } 34 a[n]=a[0]; 35 bool flag=0; 36 double l=0,r=20000; 37 double mid; 38 for(i=1;i<=n;i++) 39 { 40 r = min(r,a[i]+a[i-1]); 41 l = max(l,fabs(a[i]-a[i-1])); 42 } 43 while(r-l>eps) 44 { 45 mid=(l+r)/2.0; 46 double s,sum=0; 47 for(i=1;i<=n;i++) 48 { 49 s=(a[i]*a[i]+a[i-1]*a[i-1]-mid*mid)/(2.0*a[i]*a[i-1]); 50 sum+=acos(s); 51 } 52 if(fabs(sum-2*pi)<eps) 53 { 54 flag=1; 55 break; 56 } 57 else if(sum>2*pi) 58 { 59 r=mid; 60 } 61 else l=mid; 62 } 63 printf("Case %d: ",ca++); 64 if(flag) 65 printf("%.3f\n",mid); 66 else 67 printf("impossible\n"); 68 } 69 }
hdu 4033 2011成都赛区网络赛 余弦定理+二分 **
标签:
原文地址:http://www.cnblogs.com/cnblogs321114287/p/4705929.html