首页 > 代码库 > 水题日记

水题日记

一定要相信水题真的很水

POJ-2546

 1 #include<iostream> 2 #include<stdio.h> 3 #include<cmath> 4  5 using namespace std; 6  7 #define PI acos(double(-1)) 8  9 int main()10 {11     double x1, y1, r1, x2, y2, r2;12     cin>>x1>>y1>>r1>>x2>>y2>>r2;13     double l = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));14     double r = r1>r2? r2:r1;15     if(l<=abs(r1-r2))16         printf("%.3lf\n",r*r*PI);17     else if(l>=r1+r2)18         printf("%.3lf\n",0);19     else20     {21         double ang1 = acos((r1*r1+l*l-r2*r2)/(2*r1*l));22         double ss1 = r1*r1*ang1;23         double ang2 = acos((r2*r2+l*l-r1*r1)/(2*r2*l));24         double ss2 = r2*r2*ang2;25         double s1 = ss1 - r1*sin(ang1)*l/2;26         double s2 = ss2 - r2*sin(ang2)*l/2;27         printf("%.3lf",s1+s2);28     }29     return 0;30 }

单纯的靠高中数学就切掉了。