poj 3100 && zoj 2818 ( Root of the Problem ) (睡前一水)

链接:click here

题意:

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.

.给你B和N,求个整数A使得A^n最接近B

不解释,代码:

//zoj 2818  poj 3100

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;
int main()
{
    double b,n;
    while(cin>>b>>n&&b&&n)
    {
        int a=(int )pow(b,1/n);
        //cout<<pow(a,n)<<endl;
        if(b-pow(a,n)<pow(a+1,n)-b) cout<<a<<endl;
        else cout<<a+1<<endl;
    }
    return 0;
}
时间: 2024-10-25 20:52:23

poj 3100 && zoj 2818 ( Root of the Problem ) (睡前一水)的相关文章

POJ 3100 &amp; ZOJ 2818 &amp; HDU 2740 Root of the Problem(数学)

题目链接: POJ:http://poj.org/problem?id=3100 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1818 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2740 Description Given positive integers B and N, find an integer A such that AN is as close as

zoj 2818 Root of the Problem

Root of the Problem Time Limit: 2 Seconds      Memory Limit: 65536 KB 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

ZOJ 1938 Binomial &amp;&amp;poj 2249 (Binomial Showdown )(睡前一水)

链接:click here 题意: In how many ways can you choose k elements out of n elements, not taking order into account?  Write a program to compute this number. 给你整数n和k,让你求组合数c(n,k). 代码: #include <cstdio> #include <cstring> #include <math.h> type

NYOJ 707 A Simple Problem(结构体排序) 睡前一水~~

链接:click here 题意: A Simple Problem 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 You know, just as the title imply, this is a simple problem. In a contest, given the team-id, solved, penalty of all the teams, tell me the champion.If the numbers of solved pr

ZOJ 2829 Beautiful Number(睡前一水)

链接:click here 题意:输出第N个能被3或者5整除的数,注意是||而不是&&. 代码: <pre name="code" class="cpp">//zoj 2829 #include <stdio.h> #include <stdlib.h> #include <iostream> #include <string.h> #include <math.h> using

POJ 1128 &amp; ZOJ 1083 Frame Stacking (拓扑排序)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=83 http://poj.org/problem?id=1128 Frame Stacking Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4102   Accepted: 1378 Description Consider the following 5 picture frames placed

POJ 2777 &amp;&amp; ZOJ 1610 &amp;&amp;HDU 1698 --线段树--区间更新

直接将这3题 放一起了  今天在做线段树的东西 这3个都是区间更新的 查询方式互相不同 反正都可以放到一起吧 直接先上链接了 touch me touch me touch me 关于涉及到区间的修改 -- 区间更新的话 分为 增减 或者 修改 主要就是个 laze 标记 就是延迟更新 对于区间更新的写法 一般是有2种 其一 仔细划分到每个细小的区间    另一 粗略划分 反正 ==我的代码里会给出2种写法 看自己喜好 hdu 1 //线段树 成段更新 ---> 替换 根结点的查询 2 3 #i

poj 1094 / zoj 1060 Sorting It All Out

Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26876   Accepted: 9271 Description An ascending sorted sequence of distinct values is one in which some form of a less-than operator is used to order the elements from sm

POJ 1459 &amp; ZOJ 1734 Power Network (网络最大流)

http://poj.org/problem?id=1459 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1734 Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 22674   Accepted: 11880 Description A power network consists of nodes (power s