poj.2109
来源:互联网 发布:精品php源码 编辑:程序博客网 时间:2024/06/11 00:58
下面提供了各种浮点类型数据的范围:
类型 长度 (bit) 有效数字 绝对值范围
float 32 6~7 10^(-37) ~ 10^38
double 64 15~16 10^(-307) ~10^308
long double 128 18~19 10^(-4931) ~ 10 ^ 4932
由于double精度高于题目中的最高精度10^101所以可以直接用double来保存数据
那么这题就可以用二分法解决了。
下面是二分法代码:
#include <cmath>#include <stdio.h>#include <stdlib.h>#define Max 1000000000double head,rear,p,temp;double n; /*double Power(double value,int num){int i;double temp=value;for(i=1;i<num;i++)value*=temp;return value;}*/int main(){while(scanf("%lf%lf",&n,&p)!=EOF){/*if(pow(1.0,n)==p){printf("1\n");continue;}if(pow(p,n)==p){printf("%.0lf\n",p);continue;}*/ head=0,rear=Max+1;while(head<rear){temp=int((int(head)+int(rear))>>1);if(pow(temp,n)==p){printf("%.0lf\n",temp);break;}if(pow(temp,n)<p)head=temp;elserear=temp;}}return 0;}
看了一下discuss有人用pow(p,1/n)一步做出来,很神奇。
#include <cmath>#include <stdio.h>#include <stdlib.h>double n,pint main(){while(scanf("%lf%lf",&n,&p)!=EOF)printf("%.0lf\n",pow(p,1/n));return 0;}
- POJ 2109
- POJ 2109
- poj 2109
- POJ 2109
- poj 2109
- POJ 2109
- POJ 2109
- poj.2109
- POJ 2109
- poj-2109
- poj 2109
- POJ 2109
- POJ-2109
- poj 2109
- POJ 2109
- poj 2109
- POJ 2109
- poj 2109
- linux-3.2.36内核启动4-setup_arch中的内存初始化3(arm平台 bootmem_init源码分析)
- ffmpeg深入研究
- 《Oracle Applications DBA 基础》- 10 Custom Application Integration
- QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connect
- git send-email (multiple patches)
- poj.2109
- unity3d协同
- 《Oracle Applications DBA 基础》 - 11 - 12 FNDCPASS ,FND_STATS 和 FNDLOAD
- 任意输入两个数,求出它们的和差积商
- 后缀数组模板
- windows下gdb单步调试
- 2014 百度前端二面
- SQL Server 2008 取得登录用户密码使用天数(转帖+亲自实践)
- Apple Push Notification Services in iOS 6 Tutorial