[UVA][二分] 10649 - Danger Point@Morris' Blog|PChome Online 人新台
2013-06-26 13:53:10| 人526| 回0 | 上一篇 | 下一篇

[UVA][二分] 10649 - Danger Point

0 收藏 0 0 站台

 

Danger Point
Input: standard input
Output: standard output
Time Limit: 1 second

 

Jamal and Kamal were two friends. They were renowned for their friendship in their area. Once Jamal lend a big amount from Kamal and didn’t back that within time. At first Kamal didn’t say anything to Jamal but after few days when he understood that he was not going to give his money, he became rough on him. And the result is they are now enemies to each other. After 3 months there came another two friends to live, Rahim and Karim. Their houses stood such a way that the lines connecting Jamal's and Kamal's houses with Rahim areperpendicular; the same applies to Karim. Not only this, the line joining Rahim and Karim’s houses madeangle ‘Pi/4’ radians with the line joining Jamal and Kamal’s houses. Intersection of both of the joining lines was known as “Danger Point”. Know why? Same thing happened with Rahim and Karim! Money had done the damage in their friendship and when the four meet, surprisingly it is in that “Danger Point”, there arise a long quarrel. And others feel really annoyed with them. So, you a good programmer and neighbor of them decided to discontinue this situation. To solve this main problem, first you have to solve a little problem: Find out the distance of Rahim or Karim’s house from the “Danger Point”.

 

Input

 

You know the two data only, the distance between Jamal and Kamal’s house, and one distance from “Danger Point” to Rahim or Karim’s house. And you know you will stop when you find both of them zero. That is they will stay together.

 

Output

 

Output is a single-lined single value (6 digits after the decimal point) representing distance from “Danger Point” to Rahim or Karim’s house (other one's without the given one) for correct input set and for incorrect input set just print "INCORRECTINFORMATION !!!".

 

Sample Input

333.25 101.154
50.50 10.10
10.10 50.50
0 0
 

Sample Output/span>

212.827746
34.250766
INCORRECT INFORMATION !!!


Problem setter: Enamul Haque
Thanks to Derek Kisman for his alternate solution.

 

 “It takes two to make a quarrel - it's clear two is the lower limit here, but the upper limit is unknown to me :)” 


目描述:

Jamal Kamal 位在直上的端, Karim Rahim 是上的,
直交一 D (Danger Point), D Karim 的距你,
求 D 到 Rahim 的距。

目解法:

在, 直接算有繁。

另心 (0, 0) => x*x + y*y = r*r
而直是 y = -x + b
交有, 取左的 Karim 的所在, 二分查找 b 得答案,
然後就可以直接算的距了


其他人在 (r, 0) (-r, 0)
danger point 在 (b, 0)


#include <stdio.h>
#include <math.h>

int main() {
    double R, a;
    while(scanf("%lf %lf", &R, &a) == 2) {
        if(R == 0)  break;
        double r = R/2;
        double low = -r, upp = r, b;
        double cnt = 0, tmp;
        double x, y;
        if(r*r*2 < a*a) {
            puts("INCORRECT INFORMATION !!!");
            continue;
        }
        while(cnt <= 50 && low <= upp) {
            b = (low+upp)/2;
            x = (2*b - sqrt(8*r*r-4*b*b))/4;
            y = (-x) + b;
            tmp = hypot(x-b, y);
            if(tmp < a)
                low = b;
            else
                upp = b;
            cnt++;
        }
        x = (2*b + sqrt(8*r*r-4*b*b))/4;
        y = (-x) + b;
        printf("%.6lf\n", hypot(x-b, y));
    }
    return 0;
}

台: Morris
人(526) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 不分 | 人分: UVA |
此分下一篇:[UVA] 11012 - Cosmic Cabbages
此分上一篇:[UVA] 10301 - Rings and Glue

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86