Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这道题千万不要用printf,用了就WA,有哪位大牛解释一下为啥...using namespace std; #include <iostream> #include <iomanip> #include <algorithm> #include <cstdio> #include <cmath> #include <complex> //这道题pi后面加多少位都没关系 double pi = 3.141592653589793238462643383279502884197; typedef complex<double> CX; double circle_inter(CX o1, double r1, CX o2, double r2){ double d = sqrt( norm(o1-o2) ); if( d >= r1 + r2 ) return 0; if( d <= abs(r1 - r2) ) return min(pi * r1 * r1, pi * r2 * r2 ); double t1 = acos(( d*d + r1*r1 - r2*r2 ) / 2 / d / r1); double t2 = acos(( d*d + r2*r2 - r1*r1 ) / 2 / d / r2); double area = pi * r1 * r1 + pi * r2 * r2; area -= t1 * r1 * r1; area -= t2 * r2 * r2; double s = ( r1 + r2 + d )/2; area += sqrt( s * (s - r1 ) * (s - r2 ) * (s - d)) * 2; return pi*r1*r1 + pi*r2*r2 - area; } int main() { double x1, y1, x2, y2, r1, r2; while(cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2){ double area = circle_inter( CX(x1,y1), r1, CX(x2, y2), r2); // 使用这句就会WA // printf("%.3lf\n", circle_inter( CX(x1,y1), r1, CX(x2, y2), r2)); // 这句就AC了 cout<<setiosflags(ios::fixed)<<setprecision(3)<<area<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator