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="">题目链接 ...
随机推荐
- C++ 载入dll
1.新建一个项目生成dll 首先我们新建一个项目生成一个Dynamic Library(动态链接库) dll 里面非常简单,只有一个add方法.等下我们就要在其他项目里尝试载入这个dll,调用里面的这 ...
- QSqlDatabase::addDatabase第一次运行的时候,生成SQLite文件的同时会产生一个默认连接
QSqlDatabase::addDatabase第一次运行的时候,生成SQLite文件的同时会产生一个默认连接: QSqlDatabase database = QSqlDatabase::addD ...
- c# in depth 之泛型实参的类型推断
调用泛型方法时,指定类型实参常常会显得很多余.为简化工作,c#2编译器被赋予了一定的“智能”,让你在调用方法时,不需要显式声明类型实参. 在深入讨论这个主题之前,必须强调一下:类型推断只适用于泛型方法 ...
- All consistent reads within the same transaction read the snapshot established by the first read.
Session 1: Session 2: mysql> show variables like '%tx_isolation%'; +---------------+------------- ...
- HDU 1242——Rescue(优先队列)
题意: 一个天使a被关在迷宫里,她的很多小伙伴r打算去救她.求小伙伴就到她须要的最小时间.在迷宫里有守卫.打败守卫须要一个单位时间.假设碰到守卫必须要杀死他 思路: 天使仅仅有一个,她的小伙伴有非常多 ...
- [Android学习笔记]继承自ViewGroup的控件的过程学习
ViewGroup文档 http://developer.android.com/training/index.html 继承自ViewGroup需要重写onLayout方法用来为子View设定位置信 ...
- 3.1.2 MVC模式和URL访问
本节课大纲: 一.什么是MVC //了解 M -Model 编写model类 对数据进行操作 使用Model类 来操作数据 V -View 编写html文件,页面呈现 C -Controller 编写 ...
- Ajenti 1.0 发布,服务器管理系统 - 开源中国社区
Ajenti 1.0 发布,服务器管理系统 - 开源中国社区 Ajenti 1.0 发布,服务器管理系统
- 【MongoDB】The description of index(一)
From this blog, we start to talk about the index in mongo Database, which is similar to the traditio ...
- form表单中的 action=./?> 是什么意思
./代表当前目录,?代表查询字符串为空 action="" //一般可以为空的,这里的双引号都要有的,表示提单提交给自己(也就是当前页处理)action="a.php&q ...