zoj 2818 Root of the Problem(数学思维题)
题目链接:
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2818
题目描述:
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.
4 3
5 3
27 3
750 5
1000 5
2000 5
3000 5
1000000 5
0 0
1
2
3
4
4
4
5
16
/*问题 输入正整数b和n,找到一个正整数a满足a^n最靠近b
解题思路 a^n=b,那么a等于b的算数n次方根,即b的1/n次方等于a, 比较a^n和(a+1)^n谁更接近b */
#include<cstdio>
#include<cmath>
int main()
{
double b,n;
int a;
while(scanf("%lf%lf",&b,&n),b+n != )
{
a=(int)pow(b,/n);//强制类型转换时直接截取整数部分
if(b-pow(a,n) < pow(a+,n)-b)
printf("%d\n",a);
else
printf("%d\n",a+);
}
return ;
}
zoj 2818 Root of the Problem(数学思维题)的更多相关文章
- zoj 2818 Root of the Problem
Root of the Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Given positive integers B and ...
- PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记
PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...
- UVa10025 The ? 1 ? 2 ? ... ? n = k problem 数学思维+规律
UVa10025 ? 1 ? 2 ? ... ? n = k problem The problem Given the following formula, one can set operator ...
- 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 ...
- ZOJ Saddle Point 数学思维题
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5564 根据它的定义是行最小,列最大. 可以证明鞍点是唯一的. ...
- EOJ2018.10 月赛(B 数学+思维题)
传送门:Problem B https://www.cnblogs.com/violet-acmer/p/9739115.html 题意: 找到最小的包含子序列a的序列s,并且序列s是 p -莫干山序 ...
- EOJ2018.10 月赛(A 数学+思维题)
传送门:Problem A https://www.cnblogs.com/violet-acmer/p/9739115.html 题意: 能否通过横着排或竖着排将 1x p 的小姐姐填满 n x m ...
- HDU5742 It's All In The Mind 数学思维题
Problem Description Professor Zhang has a number sequence a1,a2,...,an. However, the sequence is not ...
- 【数学 思维题】HDU4473Exam
过程很美妙啊 Problem Description Rikka is a high school girl suffering seriously from Chūnibyō (the age of ...
随机推荐
- G 最水的一道
G - Here Be Dragons The Triwizard Tournament's third task is to negotiate a corridor of many segment ...
- 机器学习实战-ch2-有标签的聚类算法
本书中的这个聚类算法多少有些让人意外.通常的聚类算法是这样的: 给定一堆点: 给定一个距离计算的算法: 给定一个cluster之间的距离d,或者最小的cluster数目k: 初始化,每个点作为初始集群 ...
- MySQL--REPALCE INTO操作
REPLACE INTO语法是MySQL数据库独特的扩展语法,可以提供“不存在即插入,存在即更新”的操作,MySQL官方文档解析其算法为: 1.尝试进行INSER 操作 2.如果INSERT 失败,则 ...
- 扩展 StackExchange.Redis 支持实体
一.StackExchange.Redis StackExchange.Redis是由Stack Overflow开发的C#语言Redis客户端,使用广泛,本文针对 StackExchange.Red ...
- Ocelot入门实践
博主是第一次写技术文档,一是对这两年工作以来的一些技术和经验进行整理,二也是希望能和大家多多分享交流,如有写的不对的地方望大家多多指正.进入正题 Ocelot 概念就不说了,大家自行百度,今天做一个O ...
- JQuery Mobile - 导航栏选中状态代码
class="ui-btn-active" 参考: https://wizardforcel.gitbooks.io/w3school-jqmobile/content/8.htm ...
- javap 反汇编class文件
用法: javap 参数 class文件路径 其中, 可能的选项包括: -help --help -? 输出此用法消息 -version 版本信息 -v -verbose 输出附加信息 -l 输出行号 ...
- select2插件使用小记2 - 多选联动 - 笔记
这是select2插件使用的第二篇,可参考第一篇 select2插件使用小记.上一篇主要是关于基本的使用,这篇主要是关于多选,及联动的.侧重点不同. 效果图如下: 遵从W3C标准:结构.样式.行为.以 ...
- 一步步Cobol 400上手自学入门教程04 - 过程部
过程部的作用:编写程序要执行的语句,是程序的核心. 结构: 基本语句 INITIALIZE 设置数据项的初始值 ACCEPT 接收从键盘或指定设备上获得输入数据. 例子: 当批处理文件读到调用ACCP ...
- 【sping揭秘】11、Java 平台上的AOP实现机制
动态代理 Jdk1.3只有引入的动态代理机制,可以再运行期间,为相应的接口(必须得有接口)动态生成对应的代理对象 基于以上问题,我们可以将横切关注点逻辑封装到动态代理的invocationhandle ...