POJ-3100-Root of the Problem,原来是水题,暴力求解~~~
Time Limit: 1000MS | Memory Limit: 65536K | |
![]() ![]() ![]() ![]() |
![]() ![]() ![]() ![]() |
http://poj.org/problem?id=3100 已AK;
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,K,求A^K最接近B的那个A是多少,当时想了一会,没什么思路,,差点用快速幂求了,不过认真看题发现数据范围并不大,B才在百万级内,完全可以用暴力解决, 要知道2^20等于1024*1024>1000000,即最大只需for遍历到20就可以了;
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
int x,k,i;
while(~scanf("%d%d",&x,&k)&&x&&k)
{
if(k==1)
printf("%d\n",x);
else if(k>=x)//如果相等,2^k次方肯定远大于x;
printf("1\n");
else
{
for(i=1;;i++)//遍历求出满足条件A的范围;
if((int)pow(i*1.0,k)<=x&&x<=(int)pow((i+1)*1.0,k))
break;
if(abs((int)pow(i*1.0,k)-x)<=abs((int)pow((i+1)*1.0,k)-x))
printf("%d\n",i);
else
printf("%d\n",i+1);
}
}
}
POJ-3100-Root of the Problem,原来是水题,暴力求解~~~的更多相关文章
- POJ 3100 Root of the Problem || 1004 Financial Management 洪水!!!
水两发去建模,晚饭吃跟没吃似的,吃完没感觉啊. ---------------------------分割线"水过....."--------------------------- ...
- POJ 3100:Root of the Problem
Root of the Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12060 Accepted: 6 ...
- HDU 5832 A water problem(某水题)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- CODE FESTIVAL 2017 qual B B - Problem Set【水题,stl map】
CODE FESTIVAL 2017 qual B B - Problem Set 确实水题,但当时没想到map,用sort后逐个比较解决的,感觉麻烦些,虽然效率高很多.map确实好写点. 用map: ...
- zoj 2818 Root of the Problem(数学思维题)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2818 题目描述: Given positive integer ...
- POJ 2342 &&HDU 1520 Anniversary party 树形DP 水题
一个公司的职员是分级制度的,所有员工刚好是一个树形结构,现在公司要举办一个聚会,邀请部分职员来参加. 要求: 1.为了聚会有趣,若邀请了一个职员,则该职员的直接上级(即父节点)和直接下级(即儿子节点) ...
- hdu 5427 A problem of sorting 水题
A problem of sorting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contest ...
- train problem I (栈水题)
杭电1002http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/ ...
- Gym 101194A / UVALive 7897 - Number Theory Problem - [找规律水题][2016 EC-Final Problem A]
题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem J. Joke 水题
Problem J. Joke 题目连接: http://codeforces.com/gym/100714 Description The problem is to cut the largest ...
随机推荐
- 529 Minesweeper 扫雷游戏
详见:https://leetcode.com/problems/minesweeper/description/ C++: class Solution { public: vector<ve ...
- STM32CUBEMX使用注意:
一 注意堆栈大小,简单来说,栈空间用于局部变量空间(size=0x400一般够用),堆(size=0x200一般够用)空间用于 alloc 或者 malloc函数动态申请变量空间
- Python 版本对比
python2 与 python3可认为代码不通用,你也可以点击Python2.x与3.x版本区别来查看两者的不同 python3.6以上支持f-string,一种很方便的变量替换方式 高版本可能 ...
- Mysql多表联合更新、删除
UPDATE snyts_user u INNER JOIN snyts_order o ON u.user_id = o.user_id INNER JOIN snyts_refund_order ...
- git常用命令图解 & 常见错误
Git 常用命令 基本命令 git clone.这是一种较为简单的初始化方式,当你已经有一个远程的Git版本库,只需要在本地克隆一份 git clone git://github.com/someon ...
- obj.style 和currentstyle 等区别
版权声明:本文为博主原创文章,未经博主允许不得转载. 获取样式 obj.style 和currentstyle 等区别 obj.style只能获得内嵌样式(inline Style)就是写 ...
- windows session logoff时进行处理动作
目标:Windows session logoff时得到通知,进行一些记录/清理工作 测试平台: win7 x64 logoff时系统会发送WM_ENDSESSION消息,如果某个应用对这个消息的处理 ...
- Java 游戏报错 看不懂求教
Java 飞机小游戏 报错 看不懂求救 at java.awt.Component.dispatchEvent(Unknown Source)at java.awt.EventQueue.dispat ...
- 一篇文章搞懂高级程序员、架构师、技术总监、CTO从薪资到技能的区别
一篇文章搞懂高级程序员.架构师.技术总监.CTO从薪资到技能的区别 http://youzhixueyuan.com/senior-programmers-architects-technical-d ...
- java程序在一个电脑上只启动一次,只开一个进程
方案1: 单进程程序可以用端口绑定.程序启动的时候可以尝试看该端口是否已经被占用,如果占用则程序已经启动. 方案2:你可以在java程序中创建一个隐藏文件,程序退出的时候删除这个文件.这样在程序启动的 ...