hdu 4206 大水题
来源:互联网 发布:java设计界面美观 编辑:程序博客网 时间:2024/04/27 01:36
Treasure Map
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 335 Accepted Submission(s): 145
Problem Description
"Take 147 steps due north, turn 63 degrees clockwise, take 82 steps, ...". Most people don't realize how important accuracy is when following the directions on a pirate's treasure map. If you're even a tiny bit off at the start, you'll end up far away from the correct location at the end. Pirates therefore use very exact definitions. One step, for instance, has been defined by the 1670 Pirate Convention to be exactly two times the size of the wooden leg of Long John Silver, or 1.183 m in metricunits.
Captain Borbassa was thus not at all worried when he set sail to the treasure island, having a rope with knots in it, exactly one step apart, for accurately measuring distances. Of course he also brought his good old geotriangle, once given to him by his father when he was six years old.
However, on closer inspection of the map, he got an unpleasant surprise. The map was made by the famous captain Jack Magpie, who was notorious for including little gems into his directions.In this case, there were distances listed such as sqrt(33) steps. How do you measure that accurately? Fortunately, his first mate Pythagor came to the rescue. After puzzling for a few hours, he came up with the following solution: let pirate A go 4 steps into the perpendicular direction, and hold one end of the measuring rope there. Then pirate B goes into the desired direction while letting the rope slide through his fingers, until he is exactly 7 steps away from pirate A. Pythagor worked out a formula that states that pirate B has then traveled exactly sqrt(33) steps.
Captain Borbassa was impressed, but he revealed that there were more such distances on the map. Paranoid as he is, he refuses to let Pythagor see the map, or even tell him what other distances there are on it. They are all square roots of integers, that's all he gets to know. Only on the island itself will the captain reveal the numbers, and then he expects Pyhtagor to quickly work out the smallest two integer numbers of steps that can combine to create the desired distance, using the method described above.
Pythagor knows this is not easy, so he has asked your help. Can you help him by writing a program that can determine these two integers quickly? By the way, he did ask the captain how large the numbers inside the square root could get, and the captain replied "one billion". He was probably exaggerating, but you'd better make sure the program works.
If you can successfully help the pirates, you'll get a share of the treasure. It might be gold, it might be silver, or it might even be... a treasure map!
Captain Borbassa was thus not at all worried when he set sail to the treasure island, having a rope with knots in it, exactly one step apart, for accurately measuring distances. Of course he also brought his good old geotriangle, once given to him by his father when he was six years old.
However, on closer inspection of the map, he got an unpleasant surprise. The map was made by the famous captain Jack Magpie, who was notorious for including little gems into his directions.In this case, there were distances listed such as sqrt(33) steps. How do you measure that accurately? Fortunately, his first mate Pythagor came to the rescue. After puzzling for a few hours, he came up with the following solution: let pirate A go 4 steps into the perpendicular direction, and hold one end of the measuring rope there. Then pirate B goes into the desired direction while letting the rope slide through his fingers, until he is exactly 7 steps away from pirate A. Pythagor worked out a formula that states that pirate B has then traveled exactly sqrt(33) steps.
Captain Borbassa was impressed, but he revealed that there were more such distances on the map. Paranoid as he is, he refuses to let Pythagor see the map, or even tell him what other distances there are on it. They are all square roots of integers, that's all he gets to know. Only on the island itself will the captain reveal the numbers, and then he expects Pyhtagor to quickly work out the smallest two integer numbers of steps that can combine to create the desired distance, using the method described above.
Pythagor knows this is not easy, so he has asked your help. Can you help him by writing a program that can determine these two integers quickly? By the way, he did ask the captain how large the numbers inside the square root could get, and the captain replied "one billion". He was probably exaggerating, but you'd better make sure the program works.
If you can successfully help the pirates, you'll get a share of the treasure. It might be gold, it might be silver, or it might even be... a treasure map!
Input
The first line of the input contains a single number: the number of test cases to follow. Each test case has the following format:
1.One line with one integer N, satisfying 1 <= N <= 10^9.
1.One line with one integer N, satisfying 1 <= N <= 10^9.
Output
For every test case in the input, the output should contain two nonnegative integers, separated by a space, on a single line: the distance pirate A needs to head in the perpendicular direction, and the final distance between pirate A and B, such that pirate B has traveled sqrt(N) steps. If there are multiple solutions, give the one with the smallest numbers. If there are no solutions, the output should be "IMPOSSIBLE" (without the quotation marks) on a single line.
Sample Input
4331650101
Sample Output
4 70 4IMPOSSIBLE50 51
Source
BAPC 2011
Recommend
lcy
题意 :输入n
是否能找到2个最小的x y 使得 x*x-y*y=n
思路 (x-y)*(x+y)=n
a=x--y b=x+y
a*b=n
暴力a 求b 满足条件即可
#include<stdio.h>#include<math.h>int main(){int cas,m,n,x,y,a,b,flag;scanf("%d",&cas);while(cas--){flag=0;scanf("%d",&n);m=(int)sqrt(n*1.0);for(a=m;a>=1;a--){ if(n%a==0) { b=n/a; if((b-a)%2==0&&(a+b)%2==0) { flag=1; x=(a+b)/2; y=(b-a)/2; printf("%d %d\n",y,x); break; } }}if(flag==0) printf("IMPOSSIBLE\n");}return 0;}
- hdu 4206 大水题
- hdu 4247 大水题
- hdu 1575 矩阵大水题
- HDU 1028 DP 大水题
- hdu 2550 百步穿杨(大水题)
- hdu 2030 统计汉字个数 大水题
- HDU 1004 字符串处理 大水题啊
- hdu 4554 杭电超级大水题
- hdu 4548 美素数 超级大水题
- hdu 2161 Primes 筛法求素数 大水题
- hdu 1548 一维bfs大水题
- HDU 5365 Run(大水题)
- HDU 2547 无剑无我 (大水题)
- HDU 2008 数值统计(大水题)
- HDU-5504(逻辑if-else大水题)
- HDU 2564 词组缩写 标准大水题
- hdu 2094 产生冠军 模拟 大水题
- 大水题!!!
- Android GUI设计工具——DroidDraw
- 网络攻击工具yersinia
- c语言基本类型学习小结
- 使用Tomcat 和eclipse 进行jsp web编程更改代码后结果却没有改变
- ZJU 3633
- hdu 4206 大水题
- Miller-Rabin素数测试
- switch可接受的字符类型
- 【转】一个合格的程序员应该读过哪些书
- Yesterday once more
- 单击 label 触发 checkbox,checkbox 触发 click
- poj 1459 Power Network
- 移动硬盘或U盘总提示磁盘已满
- XCode4如何解决调试程序时,忽然崩溃,而找不到崩溃的代码