POJ 3175 Finding Bovine Roots
来源:互联网 发布:淘宝开店交保证金流程 编辑:程序博客网 时间:2024/05/18 00:34
Finding Bovine Roots
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4546 Accepted: 931
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.
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)
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
3123
Sample Output
17
这道题目是给定一个指定数位L的整数N。寻找一个最小的整数,对他求平方根,令小数点后的L位与N相等。
第一次做的时候暴力列举的时候TL,显然方法不对。采用枚举的方法,直接将输入的整数化作小数,每一次加1,递增。看它的平方取整之后与它+(1e+L)平方取整的大小,以此作为+1的结束条件。类似于sqrt(16) 与sqrt(17) 两者的平方根取整都为4,但是他们本身的值不同。
#include<cstdio>#include<math.h>#include <iostream>#define eps 1e-8using namespace std;typedef long long ll;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[n]; q=(m+1)*a[n]; x=y=0; while(x==y){ p+=1; q+=1; x=(ll)(p*p); y=(ll)(q*q-eps);//使用long long 取整,防止溢出 } printf("%.f\n",(y)); } return 0;}
0 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
- POJ 3175 Finding Bovine Roots (枚举)
- POJ 3175 Finding Bovine Roots(思路)
- POJ 3175 Finding Bovine Roots 笔记
- (Relax ST1.15)POJ 3175 Finding Bovine Roots
- Finding Bovine Roots
- Finding Bovine Roots
- 1617 Finding Bovine Roots 解题报告
- binary search -- finding roots
- poj 3407 Bovine Birthday
- poj 3047 Bovine Birthday
- POJ - 2183 Bovine Math Geniuses
- Poj 2183 Bovine Math Geniuses
- poj 2183 Bovine Math Geniuses
- Oracle数据库、实例、用户、表空间、表之间的关系
- 注册: 加密 + 城市 + 提示 + 发送验证码
- java 23种设计模式
- 自适应辛普森(近似求积分模板)
- CSDN——hello world。
- POJ 3175 Finding Bovine Roots
- Catalan Square----卡特兰数
- 在ogg中手动同步数据遇到列映射的情况
- 基于 rbd nbd 的支持抢锁的 rbd docker volume plugin
- 字节流操作媒体文件
- 如何present出一个透明导航控制器NavigationController + UIVisualEffectView实现模糊效果、毛玻璃效果
- 苹果ios用js的Date()出现NaN问题解决办法
- 五分钟学GIS | BIM与三维GIS的融合
- JS数据类型