USC newweek2 G

Problem Description

For national security, the coordinate systems of public map service are all in an encryption system. This means that when you got the latitude and longitude coordinates from a GPS device, you cannot finger out the real place at a public map with that coordinates.
We know an encryption system, which works as:
x1 = x – sqrt(y)
y1 = y – sqrt(x)
Now, we got some coordinates of POIs (point of interest, http://en.wikipedia.org/wiki/Point_of_interest, which you can just think as some points)
But even we have that formulations of how to encrypt coordinates, still we cannot decrypt any POI coordinate. Can you help us to decrypt all the POI coordinates?

Input

The first line contains a single integer T, indicating the number of test cases.
Each test case consists of two float number(x, y) in a single line.

Technical Specification

1. 1 <= T <= 10000
2. 0 <= x, y <= 10000

Output

For each test case, output the case number first, then the decrypted coordinates with six decimal digits.
If multiply answer exists, output the one which has minimal x.

Sample Input

4
500.116 5000
0 0
10000 10000
5000 5000

Sample Output

Case 1: 570.995444 5023.895511
Case 2: 0.000000 0.000000
Case 3: 10100.501250 10100.501250
Case 4: 5071.212446 5071.212446



题意:

找到一对数x,y;使满足上述式子,并且要求x最小。
 
方法:
 
     迭代;
    
     很神奇的一个方法,每次都使x1,y1迭代进x,y;直到前后两次得到的差极小,也就是说,迭代到增量非常小时,就停止迭代。
 
    得到的x1,y1为要求的x,y
 
     暂时木有搞懂为什么。。。
 
 
代码实现:
 
 
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main()
{
int test;
scanf("%d",&test); 
double x1,y1; 
int cas=1; 
while(test--)
{
  scanf("%lf%lf",&x1,&y1);
  double x,y;
  double sx=x1,sy=y1; 
  do
   {
     x=x1,y=y1;
     x1=sx+sqrt(y);
     y1=sy+sqrt(x);
   }while(x1-x>0.00000001||y1-y>0.00000001);
   printf("Case %d: %.6lf %.6lf\n",cas++,x1,y1);             
} 
return 0;} 

 

posted on 2012-08-23 17:29  yumao  阅读(160)  评论(0)    收藏  举报

导航