标签:style blog http color io for div 代码
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=773
思路:最近学习二分思想和三分思想,三分还是不太会。这个题可以用二分思想做。
代码
#include <stdio.h> #include <math.h> int n; double p; int cal(double a)//计算加判断 { double cmpnum = 1; for(int i=1;i<=n;i++) { cmpnum *= a; } if(cmpnum >=p) return 1; else return 0; } int main() { double r; double l; double mid; //二分思想 while(scanf("%d %lf",&n,&p)&&n) { l = 0; r = 1000000000; mid = (l+r)/2; while(l+0.1<r) { if(cal(mid)==1) { r = mid; } else { l = mid; } mid = (r+l)/2; } printf("%.0lf\n",l); } return 0; }
标签:style blog http color io for div 代码
原文地址:http://www.cnblogs.com/ltwy/p/3910768.html