Root of the Problem(求a,a^n接近b)
来源:互联网 发布:java写游戏代码 编辑:程序博客网 时间:2024/04/30 02:31
看到这道题我的思路就是开for循环一直直到找到i^n接近于b,但是超时,看了别人的博客发现逆向思维真的简单。
先对b开n次方,上下取整去找a,而且我学到了两个函数,
floor 向下取整
ceil 向上取整代码:#include<stdio.h>#include<math.h>int main(){ int b,n; double z; int p,q; while(~scanf("%d%d",&b,&n)) { if(n==0&&b==0) break; z=pow(b*1.0,1.0/n); p=floor(z); q=ceil(z); if(b-pow(p,n)>pow(q,n)-b)//判断向上取整后的值与向下取整的值哪个更接近b,这个值就是a printf("%d\n",q); else printf("%d\n",p); } return 0;}转自:http://www.cnblogs.com/xiaohongmao/archive/2012/04/23/2466952.html
0 0
- Root of the Problem(求a,a^n接近b)
- POJ 3100 Root of the Problem(我的水题之路——取A^N最接近B的A)
- a的n次幂 —— POJ 3100 Root of the Problem
- Problem B: 求Sn=a+aa+aaa+…+aa…aaa(有n个a)之值
- 求A*f(A,B,n-1)+B*f(A,B,n-2))%7;
- Root of the Problem
- A lot of people suffer A + B problem
- the minimum value of |A - a| + |B - b| + |C - c|
- A+B Problem(V)
- A+B Problem(水)
- (1)A+B Problem
- A+B Problem(V)
- A+B Problem(V)
- A+B Problem(高精加)
- A+B Problem(V)
- A+B Problem(V)
- A/B Problem(大数)
- a+b problem(EOF)
- CSS3颜色渐变练习
- android多选按钮(CheckBox)
- 选夫婿1
- eclipse里启动rabbitmq报错 java.net.SocketException: Connection reset
- ICS proxy lab总结
- Root of the Problem(求a,a^n接近b)
- 交换排序模板
- 如何在java中插入音乐
- 使用 rosmsg时碰到的一个问题
- 英文金曲大赛
- 关于java字节码框架ASM的学习
- 带着崇高与赞美,献给活在计算机里的神灵
- JavaScript基础系列14---面向对象入门
- Codeforces 659E New Reform【思维+Dfs】