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,原来是水题,暴力求解~~~的更多相关文章

  1. POJ 3100 Root of the Problem || 1004 Financial Management 洪水!!!

    水两发去建模,晚饭吃跟没吃似的,吃完没感觉啊. ---------------------------分割线"水过....."--------------------------- ...

  2. POJ 3100:Root of the Problem

    Root of the Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12060   Accepted: 6 ...

  3. HDU 5832 A water problem(某水题)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  4. CODE FESTIVAL 2017 qual B B - Problem Set【水题,stl map】

    CODE FESTIVAL 2017 qual B B - Problem Set 确实水题,但当时没想到map,用sort后逐个比较解决的,感觉麻烦些,虽然效率高很多.map确实好写点. 用map: ...

  5. zoj 2818 Root of the Problem(数学思维题)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2818 题目描述: Given positive integer ...

  6. POJ 2342 &&HDU 1520 Anniversary party 树形DP 水题

    一个公司的职员是分级制度的,所有员工刚好是一个树形结构,现在公司要举办一个聚会,邀请部分职员来参加. 要求: 1.为了聚会有趣,若邀请了一个职员,则该职员的直接上级(即父节点)和直接下级(即儿子节点) ...

  7. hdu 5427 A problem of sorting 水题

    A problem of sorting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contest ...

  8. train problem I (栈水题)

    杭电1002http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/ ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. JAVA常用知识总结(五)——Linux

    简单介绍一下 Linux 文件系统? 在Linux操作系统中,所有被操作系统管理的资源,例如网络接口卡.磁盘驱动器.打印机.输入输出设备.普通文件或是目录都被看作是一个文件. 也就是说在LINUX系统 ...

  2. 使用Appache部署WEB服务器

    Apache的起源(这个就不说了,百度下就都有了) 简介:Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行, ...

  3. sql子查询的例子

    1.单行子查询        select ename,deptno,sal        from emp        where deptno=(select deptno from dept ...

  4. (一)Mybatis之初步接触

    Maven的安装及环境配置 安装及配置只需按照以下三个链接的步骤走 撸帝的博客https://www.funtl.com/zh/maven/Maven-%E5%AE%89%E8%A3%85%E9%85 ...

  5. Oracle逻辑备份与恢复(Data Pump)

    1. 备份的类型 按照备份方式的不同,可以把备份分为两类: 1.1 逻辑备份:指通过逻辑导出对数据进行备份.将数据库中的用户对象导出到一个二进制文件中,逻辑备份使用导入导出工具:EXPDP/IMPDP ...

  6. Android(java)学习笔记171:服务(service)之绑定服务调用服务里面的方法

    1.绑定服务调用服务里面的方法,图解: 步骤: (1)在Activity代码里面绑定 bindService(),以bind的方式开启服务 :                     bindServ ...

  7. 技术抄录_Java高级架构师教程

    1.B2C商城项目实战     2.高性能架构专题     3.架构筑基与开源框架解析专题     4.团队协作开发专题     5.微服务架构专题     6.设计模式     附上[架构资料]   ...

  8. docker 应用数据的管理

    容器数据存储的三种方式 docker volume docker管理素质及文件系统的一部分,保存数据最佳方式 bind mounts   将宿主机的文件映射到容器里 tmpfs   存储在宿主机的内存 ...

  9. JS将时间戳转换为刚刚、N分钟前、今天几点几分、昨天几点几分等表示法

    使用Javascript语言,将时间戳转换为类似新浪微博的时间的表示方法. 要求转换规则: 1分钟以内显示为:刚刚 1小时以内显示为:N分钟前 当天以内显示为:今天 N点N分(如:今天 22:33) ...

  10. largest rectangle in histogram leetcode

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...