HDU 2876 Ellipse, again and again

转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2876


 

Ellipse, again and again

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 537    Accepted Submission(s): 200


Problem Description
There is an ellipse in the plane, its formula is   . We denote the focuses by F1 and F2. There is a point P in the plane. Draw a segment to associate the origin and P, which intersect the ellipse at point Q. Then draw a tangent of the ellipse which passes Q. Denote the distance from the center of the ellipse to the tangent by d. Calculate the value of   .
HDU 2876 Ellipse, again and again_第1张图片
 

Input
The first line contains a positive integer n that indicates number of test cases.
And each test case contains a line with four integers. The value of parameters of the ellipse a, b(0<|a|,|b|<=100),and the coordinates x, y of P(|x|<=100,|y|<=100) are given successively.
 

Output
For each test case, output one line. If the given point P lies inside the given ellipse, print "In ellipse" otherwise print the value of d*d*QF1*QF2 rounded to the nearest integer.
 

Sample Input
       
       
1 1 1 1 1
 

Sample Output
       
       
1
 

Source
 

Recommend
gaojie

  求距离!

#include <stdio.h>
#include <math.h>
int main()
{
	double xQ,yQ;
	double k1;
	int a,b,x0,y0,T;
	while(~scanf("%d",&T))//FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
	{
		while(T--)//FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
		{
			scanf("%d%d%d%d",&a,&b,&x0,&y0);
			k1=y0/(x0*1.0);//FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
			xQ=sqrt((a*a*b*b*1.0)/(a*a*k1*k1+b*b));//FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
			yQ=k1*xQ;int flag= 0;//FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
			int w=a*a-b*b;//FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
			if((x0*x0)/(a*a)+(y0*y0)/(b*b)<1)//FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
			{
				printf("In ellipse\n");//FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
				continue;
			}
			if(w < 0)//标记焦点所在轴
			{
				flag =1;
				w=-w;
			}
			double F1,F2;//FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
			double c =sqrt(w*1.0);//FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
			if(flag == 0)
			{
				 F1 = sqrt((xQ+c)*(xQ+c)+(yQ*yQ));//FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
				 F2 = sqrt((xQ-c)*(xQ-c)+yQ*yQ);//FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
			}
			else
			{ 
				F1 = sqrt(xQ*xQ+(yQ+c)*(yQ+c));//FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
				F2 = sqrt(xQ*xQ+(yQ-c)*(yQ-c));//FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
			}
			double t = (sqrt)((xQ*xQ*b*b*b*b)*1.0+(yQ*yQ*a*a*a*a)*1.0);//FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
			double d =a*a*b*b/(t*1.0);
			double D=d*d*F1*F2;//化简后D==a*a*b*b FUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCKFUCK
			 D = a*a*b*b;
			printf("%.0lf\n",D);
		}
	}
	return 0;
}

以下给出证明:

HDU 2876 Ellipse, again and again_第2张图片

至此D=d*d*F1*F2可化简为D=a*a*b*b

所以给出简短代码:

#include<cstdio>
int main()
{
	int a,b,x0,y0;
	int T;
	while(~scanf("%d",&T))
	{
		while(T--)
		{
			scanf("%d%d%d%d",&a,&b,&x0,&y0);
			if(x0*x0/(a*a)+y0*y0/(b*b)<1)
				printf("In ellipse\n");
			else
				printf("%d\n",a*a*b*b);
		}
	}
	return 0;
}



你可能感兴趣的:(HDU)