POJ 3100 & ZOJ 2818 & HDU 2740 Root of the Problem(数学)
题目链接:
POJ: id=3100" style="font-size:18px">http://poj.org/problem? id=3100
ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1818 pid=2740">http://acm.hdu.edu.cn/showproblem.php?pid=2740
HDU:
Description
Given positive integers B and N, find an integer A such that AN is as close as possible to B. (The result A is an approximation to the Nth root of B.) Note that AN may be less than, equal to, or greater than B.
Input
The input consists of one or more pairs of values for B and N. Each pair appears on a single line, delimited by a single space. A line specifying the value zero for both B and N marks the end of the input. The value of B will be in the range 1 to 1,000,000
(inclusive), and the value of N will be in the range 1 to 9 (inclusive).
Output
For each pair B and N in the input, output A as defined above on a line by itself.
Sample Input
4 3
5 3
27 3
750 5
1000 5
2000 5
3000 5
1000000 5
0 0
Sample Output
1
2
3
4
4
4
5
16
Source
题意:
给定整数b和n,求整数a使得a^n最接近b。
代码例如以下:
#include <cstdio>
#include <cmath>
int main()
{
int b, n;
while(~scanf("%d%d",&b,&n))
{
if(b==0 && n==0)
break;
double tt = (double)pow(b,1.0/n);
int t1 = ceil(tt);//向上取整
int t2 = floor(tt);//向下取整
if(b-pow(t2,n)>pow(t1,n)-b)
printf("%d\n",t1);
else
printf("%d\n",t2);
}
return 0;
}
POJ 3100 & ZOJ 2818 & HDU 2740 Root of the Problem(数学)的更多相关文章
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- POJ 3652 & ZOJ 2934 & HDU 2721 Persistent Bits(数学 元)
主题链接: PKU:http://poj.org/problem?id=3652 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do? probl ...
- POJ 3654 & ZOJ 2936 & HDU 2723 Electronic Document Security(模拟)
题目链接: PKU:http://poj.org/problem?id=3654 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...
- POJ 3653 & ZOJ 2935 & HDU 2722 Here We Go(relians) Again(最短路dijstra)
题目链接: PKU:http://poj.org/problem? id=3653 ZJU:problemId=1934" target="_blank">http ...
- POJ 1325、ZOJ 1364、HDU 1150 Machine Schedule - from lanshui_Yang
Problem Description As we all know, machine scheduling is a very classical problem in computer scien ...
- poj 3100 (zoj 2818)||ZOJ 2829 ||ZOJ 1938 (poj 2249)
水题三题: 1.给你B和N,求个整数A使得A^n最接近B 2. 输出第N个能被3或者5整除的数 3.给你整数n和k,让你求组合数c(n,k) 1.poj 3100 (zoj 2818) Root of ...
- POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for UNIX / UVAlive 5418 A Plug for UNIX / SCU 1671 A Plug for UNIX (网络流)
POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for ...
- POJ 3100 Root of the Problem || 1004 Financial Management 洪水!!!
水两发去建模,晚饭吃跟没吃似的,吃完没感觉啊. ---------------------------分割线"水过....."--------------------------- ...
- HDU 4974 A simple water problem(贪心)
HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...
随机推荐
- jsp:include怎么设置才能正确显示包含的页面呢
1.项目的所有jsp都放在WEB-INF文件夹之下,使用的是SpirngMVC进行了过滤,jsp:include只能引入WEB-INF外部的jsp文件,对于改变后缀显示为htm的jsp的WEB-INF ...
- MySQL内存表(MEMORY)说明 | 一个PHP程序员的备忘录
MySQL内存表(MEMORY)说明 | 一个PHP程序员的备忘录 MySQL内存表(MEMORY)说明
- QT操作Excel(通过QAxObject使用了OLE,前提是本地安装了Excel)
新建QT GUI项目,在选择选项中勾选ActiveQT Container. #include <qaxobject.h> QAxObject *obj = new QAxObject(& ...
- ThinkPhp学习02
原文:ThinkPhp学习02 一.什么是MVC M -Model 编写model类 对数据进行操作 V -View 编写html文件,页面呈现 C -Controll ...
- iOS学习笔记(十五)——数据库操作(SQLite)
SQLite (http://www.sqlite.org/docs.html) 是一个轻量级的关系数据库.SQLite最初的设计目标是用于嵌入式系统,它占用资源非常少,在嵌入式设备中,只需要几百K的 ...
- Opencv各个版本的万能头文件
每次下载opencv的新版本时,都需要重新写头文件,更改链接库配置,很麻烦有木有?下面这个头文件是我在别人的代码中淘出来的,很不错,与大家分享~(具体作者忘记了,不好意思啊) 作者很巧妙地利用Open ...
- 微信支付.net官方坑太多,我们来精简
原文:微信支付.net官方坑太多,我们来精简 微信支付官方坑太多,我们来精简 我把官方的代码,打包成了 an.wxapi.dll. 里面主要替换了下注释.呵呵.然后修改了几个地方. 修改一.Confi ...
- oschina 手机/移动开发
手机/移动开发 Android UI 组件(167) React Native 相关(8) 网站客户端(16) NativeScript 插件(18) iPhone/iPad开发工具(16) WP7开 ...
- hdu1081(最大子矩阵)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1081 分析:a[i][j]代表第i行,前j个数据的和:那么由a[i][j]可得sum[k][long] ...
- mahout源码KMeansDriver分析之五CIMapper
接上文重点分析map操作: Vector probabilities = classifier.classify(value.get());// 第一行 Vector selections = pol ...