poj 2109 Power of Cryptography 贪心 暑假第四题
来源:互联网 发布:et鼠标 知乎 编辑:程序博客网 时间:2024/05/16 18:46
看了这道题的discuss,就想笑了,说是专坑不看评论的老手们,许多人打了二分+高精度,wr了,但最后一句话ac了。。。
这题怎么能分到贪心,我也是醉了。
1<=n<= 200, 1<=p<10101,1<=k<=109
我个人认为最保险的思路应该是log:
k^n=p;
ln(k)=ln(p)/n;
k=exp( ln(p)/n );
代码如下:
#include<iostream>#include<cmath>#include<iomanip>using namespace std;int main(){ double n,p; while(cin>>n>>p) { double c=exp(log(p)/n); cout<<setiosflags(ios::fixed)<<setprecision(0)<<c<<endl; } return 0;}
即使p再大,ln(p)也不会太大;
二:还有一种思路是pow函数;
代码如下:
#include<iostream>#include<cmath>#include<iomanip>using namespace std;int main(){ double n,p; while(cin>>n>>p) { double c=pow(p,1/n); cout<<setiosflags(ios::fixed)<<setprecision(0)<<c<<endl; } return 0;}double的精度是15位有效数字,取值范围是10的-308次方到10的308次方,double占用8字节空间;
有一些精度问题还没搞清楚,明白了会上传。
0 0
- poj 2109 Power of Cryptography 贪心 暑假第四题
- POJ 2109 Power of Cryptography 贪心
- poj 2109 Power of Cryptography
- poj 2109 Power of Cryptography
- POJ 2109 Power of Cryptography
- poj 2109 : Power of Cryptography
- POJ 2109 Power of Cryptography
- poj 2109 Power of Cryptography
- poj 2109 Power of Cryptography
- POJ 2109 Power of Cryptography
- POJ 2109 Power of Cryptography
- POJ 2109 Power of Cryptography
- poj 2109 Power of Cryptography
- POJ 2109 Power of Cryptography
- POJ 2109 Power of Cryptography
- poj 2109 Power of Cryptography
- POJ 2109 Power of Cryptography
- poj-2109 Power of Cryptography
- 微信公众号第三方平台全网发布测试程序
- DELL R430安装WINDOWS 2008 R2 RAID卡无驱动
- TCP服务端和客户端程序示例
- the file “XXX” could not be opened because you don't have permission to view it
- 表单验证概述
- poj 2109 Power of Cryptography 贪心 暑假第四题
- Mina 起源和作者简介
- 什么是Ajax
- Linux 忘记密码处理方法
- 每天一个linux命令(13):less 命令
- App Extensions 基本学习 iOS8
- SPOJ 375 Query on a tree(初学树链剖分)
- 每个人都懂得敏捷开发 (软件工程), 为何产品开发的效率与质量还是这么的烂?
- 跳表的一种实现