1768: Lovely Circular And Linear
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 520 Solved: 231
Submit Status Web Board
Description
求圆(圆心坐标:(x,y) 半径:r)与直线(A*x+B*y+C=0)交点的个数。
Input
多实例测试,处理到文件尾结束(EOF),输入包括一行 x, y, r ,A ,B, C ,所有数据均为浮点数,且绝对值小于等于1000。
Output
输出一个数字代表直线与圆交点个数。
Sample Input
0 0 2 1 -1 0
Sample Output
2
数学方面更多,其实就是把数学题写成程序。
#include<stdio.h>
#include<math.h>
int main()
{
double x, y, r ,A ,B, C,sum,d,l;
while(~scanf("%lf%lf%lf%lf%lf%lf",&x,&y,&r,&A,&B,&C))
{
sum=A*x+B*y+C;
if(sum<0)
sum=-sum;
d=sqrt(A*A+B*B);
l=sum/d;
if(l<r)
printf("2\n");
if(l==r)
printf("1\n");
if(l>r)
printf("0\n");
}
return 0;
}