牛吃草
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 441 Solved: 139
Description
农夫有一个长满草的(x0, y0)为圆心,r为半径的圆形牛栏,他要将一头牛栓在坐标(x1, y1)栏桩上,但只让牛吃到一半草,问栓牛鼻的绳子应为多长?
Input
输入一个T,表示T组测试数据
下面T行每行五个整数 x0, y0, x1, y1, r 所有数据的绝对值小于1e5
Output
每组测试数据输出绳子长度,保留4位小数
Sample Input
2 0 0 0 0 2 0 0 10 10 2
Sample Output
1.4142 14.1892
先计算公共面积,然后直接二分。
#include "cstdio" #include "algorithm" #include "cstring" #include "cmath" #define inf 0x3f3f3f using namespace std; ); double s0,s1,s2,s3,s4,d; double x0,x1,e,f,r; int P(double l ){ *d*r)); *l*d)); s0=r*r*a1+l*l*a2-d*r*sin(a1);//相交面积 s4=pi*r*r/; if(s0>s4){ ; } ; } int main(){ int t; scanf("%d",&t); while (t--){ scanf("%lf%lf%lf%lf%lf",&x0,&e,&x1,&f,&r); d=sqrt((x0-x1)*(x0-x1)+(e-f)*(e-f)); -sqrt()/)){//判断内含情况 printf()/); continue; } double R=sqrt(r*r+d*d); ; ; ;i<;i++){ ){ R=M; } else { L=M; } M=(L+R)/; } printf("%.4f\n",M); } ; }