这道题wa了一晚上 原因是
1.没看到多组样例,本人写的时候也从来没有习惯写多组样例
2.double类型只能用%lf读,用%f写啊!我两个都用了%lf。。。。。。。。。。。。。。话说写的时候还有点犹豫。。。。。。
不说了 我是个傻孩子orz
Circular Area
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6455 | Accepted: 2432 |
Description
Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after decimal point.
Input
In the single line of input file there are space-separated real numbers x1 y1 r1 x2 y2 r2. They represent center coordinates and radii of two circles.
Output
The output file must contain single real number - the area.
Sample Input
20.0 30.0 15.0 40.0 30.0 30.0
Sample Output
608.366
上代码
#include<iostream> #include<cmath> #include<cstdio> using namespace std; double x1,yy,r1,x2,y2,r2; double l; double pi = acos(-1); double dis(){ double m = (x1-x2)*(x1-x2) + (yy-y2)*(yy-y2); return sqrt(m); } int main(){ // cout << pi <<endl; while(scanf("%lf%lf%lf%lf%lf%lf",&x1,&yy,&r1,&x2,&y2,&r2) != EOF){ l = dis(); if(l >= r1 + r2){ printf("0.000\n"); } else{ int minr = r1; if(r1 > r2) minr = r2; int maxr = r1 + r2 - minr; if(maxr - l >= minr){ printf("%.3lf\n",pi*minr*minr); } else{ double alpha1,alpha2,s,s1,s2; alpha1 = acos((r1*r1 + l*l - r2*r2)/(2*r1*l)); alpha2 = acos((r2*r2 + l*l - r1*r1)/(2*r2*l)); s1 = alpha1*r1*r1; s2 = alpha2*r2*r2; s = s1 + s2 - l*r1*sin(alpha1); printf("%.3lf\n",s); } } } return 0; }