首页 > 代码库 > HDU 2876 Ellipse, again and again
HDU 2876 Ellipse, again and again
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2876
<marquee width="600"> HDU集训队选拔赛地点:3教3楼机房,时间:5月10日(周六)12:00開始,请相互转告,谢谢~ 百度之星编程大赛——您报名了吗? </marquee> |
Ellipse, again and againTime 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 . 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
Sample Output
Source 2009 Multi-University Training Contest 8 - Host by BJNU 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; }
以下给出证明:
至此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; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。