POJ_3100_Root of the Problem(暴力)
来源:互联网 发布:高性能网络编程2 编辑:程序博客网 时间:2024/06/06 00:53
题型:数论
题意:给出B和N,求出一个A,使得A^N最接近B
分析:
由于B是int型,所以A的范围不会很大,所以暴力可以接受,从1找起,到刚好大于B的时候break,比较A与A-1哪一个是更加接近的答案。
因为pow()函数中的参数均为double型,而时间复杂度与手写一样,所以手写一个比较保险
代码:
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>using namespace std;int fun(int a,int n){ int mul=1; for(int i=1;i<=n;i++){ mul*=a; } return mul;}int main(){ int a,b,n; while(1){ scanf("%d%d",&b,&n); if(b==0 && n==0) break; int a=1; int ans; while(1){ ans=fun(a,n); if(ans>=b) break; a++; } if(ans-b<b-fun(a-1,n)){ printf("%d\n",a); } else printf("%d\n",a-1); } return 0;}
- POJ_3100_Root of the Problem(暴力)
- POJ-3100-Root of the Problem,原来是水题,暴力求解~~~
- The problem of UDP
- The problem of Titanium
- The problem of UDP
- Root of the Problem
- uva 105 - The Skyline Problem(暴力)
- UVA 105 - The Skyline Problem(暴力枚举)
- [UVA10245] The Closest Pair Problem && 暴力版本
- hdu 4627 The Unsolvable Problem(暴力)
- HDU 5443 The Water Problem RMQ/暴力
- 1394. Root of the Problem
- The problem of Memory Leak
- TJU Root of the Problem
- The problem of Money Changes
- Root of the Problem-3100
- The problem of Zigzag pattern
- 1394. Root of the Problem
- 游戏服务器架构
- SensorManager与Sensor交互
- 第11周项目5--歌手大奖赛积分系统(最低级的)
- CGLayer和CALayer区别
- 黑马程序员——Java 常用类库
- POJ_3100_Root of the Problem(暴力)
- 疯狂java java反射机制
- Ubuntu12.04+eclipse下cocos2d-x2.2环境的搭建
- 2007word如何转PDF
- kernel 选项详解(stlinux2.3) 2-2
- 数据类型、值传递和引用传递有什么区别,String是什么传递?
- 线程的属性和 线程特定数据 Thread-specific Data
- malloc和new的区别
- 黑马程序员——Java IO流