POJ 3175 Finding Bovine Roots
2011-08-06 15:29
453 查看
题目大意:输入一个L,接下来是一个L位的整数,代表一个数N的前L位小数,当然,排除完全平方数,求N。。。
之前用int取整数部分居然超时了。。。。。改用floor——16MS 过了。。。差距真大。。。
Description
The cows are trying to find their roots. They are not so smart as humans when they find square roots, the cows lose the integer portion of their square root calculation. Thus, instead of calculating the square root of 2 to be 1.4142135623730950488016887242096980785696,
they deduce that it is 0.4142135623730950488016887242096980785696. The square root of 16 is calculated to be 0 (obviously an error).
The erroneous ciphering does, however, lead to an interesting question. Given a string of digits of length L (1 <= L <= 9), what is the smallest integer whose bovine square root decimal part begins with those digits?
By way of example, consider the string "123". The square root of 17 is approximately 4.1231056256176605498214098559740770251472 so the bovine square root is: 0.1231056256176605498214098559740770251472 whose decimal part (just after the period) starts
with 123. It turns out that 17 is the smallest integer with this property.
Input
Line 1: A single integer, L
Line 2: L digits (with no spaces)
Output
Line 1: A single integer that is the smallest integer whose bovine square root starts with the supplied string
Sample Input
Sample Output
sqrt(17) ~= 4.1231056256176605498214098559740770251472
之前用int取整数部分居然超时了。。。。。改用floor——16MS 过了。。。差距真大。。。
Description
The cows are trying to find their roots. They are not so smart as humans when they find square roots, the cows lose the integer portion of their square root calculation. Thus, instead of calculating the square root of 2 to be 1.4142135623730950488016887242096980785696,
they deduce that it is 0.4142135623730950488016887242096980785696. The square root of 16 is calculated to be 0 (obviously an error).
The erroneous ciphering does, however, lead to an interesting question. Given a string of digits of length L (1 <= L <= 9), what is the smallest integer whose bovine square root decimal part begins with those digits?
By way of example, consider the string "123". The square root of 17 is approximately 4.1231056256176605498214098559740770251472 so the bovine square root is: 0.1231056256176605498214098559740770251472 whose decimal part (just after the period) starts
with 123. It turns out that 17 is the smallest integer with this property.
Input
Line 1: A single integer, L
Line 2: L digits (with no spaces)
Output
Line 1: A single integer that is the smallest integer whose bovine square root starts with the supplied string
Sample Input
3 123
Sample Output
17
Explanation of the sample:
sqrt(17) ~= 4.1231056256176605498214098559740770251472
/*eps 用于解决9,99,999……的情况*/
#include<stdio.h> #include<math.h> #define eps 1e-8 double a[11]={1,1e-1,1e-2,1e-3,1e-4,1e-5,1e-6,1e-7,1e-8,1e-9,1e-10}; int main(){ int n; int m; double p,q,x,y; while(scanf("%d",&n)!=EOF){ scanf("%d",&m); p=m*a ; q=(m+1)*a ; x=y=0; while(x==y){ p+=1; q+=1; x=floor(p*p); y=floor(q*q-eps); } printf("%.f\n",floor(y)); } return 0; }
相关文章推荐
- POJ 3175 Finding Bovine Roots(思路)
- POJ 3175 Finding Bovine Roots (暴力求解)
- POJ 3175 Finding Bovine Roots
- POJ 3175 Finding Bovine Roots (枚举)
- POJ 3175 Finding Bovine Roots
- (Relax ST1.15)POJ 3175 Finding Bovine Roots
- POJ 3175 Finding Bovine Roots
- 1617 Finding Bovine Roots 解题报告
- Finding Bovine Roots
- Ombrophobic Bovines POJ 2391
- POJ-2391 Ombrophobic Bovines 二分+最大流+拆点
- POJ 2391 Ombrophobic Bovines (二分+最短路+最大流)
- POJ 2391 Ombrophobic Bovines 二分最大流+拆点
- POJ 2391 Ombrophobic Bovines 不喜欢雨的奶牛 Floyd+二分枚举+最大流
- POJ 2391 Ombrophobic Bovines 网络流 建模
- poj2391 Ombrophobic Bovines 拆点+二分法+最大流
- poj 3740 Easy Finding dfs
- [POJ 2391]Ombrophobic Bovines[最大流][二分答案]
- Ombrophobic Bovines POJ - 2391 Floyd+ 二分+最大流
- poj 3175(根据给出的小数部分求最小的整数)