HDOJ 5605 geometry

来源:互联网 发布:您的java版本不安全 编辑:程序博客网 时间:2024/06/06 13:04


geometry

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 65    Accepted Submission(s): 49


Problem Description
There is a point P at coordinate (x,y).
A line goes through the point, and intersects with the postive part of
X,Y axes at point A,B.
Please calculate the minimum possible value of
|PA||PB|.
 

Input
the first line contains a positive integer T,means the numbers of the test cases.

the next T lines there are two positive integers X,Y,means the coordinates of P.

T=500,0<X,Y10000.
 

Output
T lines,each line contains a number,means the answer to each test case.



 

Sample Input
12 1
 

Sample Output
4in the sample $P(2,1)$,we make the line $y=-x+3$,which intersects the positive axis of $X,Y$ at (3,0),(0,3).$|PA|=\sqrt{2},|PB|=2\sqrt{2},|PA|*|PB|=4$,the answer is checked to be the best answer.
 

题意:直接给中文题面链接吧:点击打开链接

题解:我是凭直觉判断出k=1时是正解的,化了两组数,就直接写了。
贴出BC上给的证明吧:

只用计算2*x*y就行了,我写的啰嗦,代码如下:

#include<cstdio>#include<cstring>#include<cmath>int main(){int x,y,b,t,x1,x2,y1,y2;scanf("%d",&t);while(t--){scanf("%d%d",&x,&y);b=y-x;y2=b; x2=0;y1=0; x1=-b;double ans=sqrt((x1-x)*(x1-x)*1.0+(y1-y)*(y1-y)*1.0)*sqrt((x2-x)*(x2-x)*1.0+(y2-y)*(y2-y)*1.0);        printf("%.0f\n",ans); }return 0;} 

0 0
原创粉丝点击