博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Yukari's Birthday 枚举+二分 过程注意数据的溢出问题 HDU4430
阅读量:5335 次
发布时间:2019-06-15

本文共 2886 字,大约阅读时间需要 9 分钟。

Yukari's Birthday

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1993    Accepted Submission(s): 404

Problem Description
Today is Yukari's n-th birthday. Ran and Chen hold a celebration party for her. Now comes the most important part, birthday cake! But it's a big challenge for them to place n candles on the top of the cake. As Yukari has lived for such a long long time, though she herself insists that she is a 17-year-old girl.
To make the birthday cake look more beautiful, Ran and Chen decide to place them like r ≥ 1 concentric circles. They place k
i candles equidistantly on the i-th circle, where k ≥ 2, 1 ≤ i ≤ r. And it's optional to place at most one candle at the center of the cake. In case that there are a lot of different pairs of r and k satisfying these restrictions, they want to minimize r × k. If there is still a tie, minimize r.
 

 

Input
There are about 10,000 test cases. Process to the end of file.
Each test consists of only an integer 18 ≤ n ≤ 10
12.
 

 

Output
For each test case, output r and k.
 

 

Sample Input
18 111 1111
 

 

Sample Output
1 17 2 10 3 10
 

 

Source
 

 

Recommend
zhuyuanchen520   |   We have carefully selected several similar problems for you:            
 
/* * Author:   * Created Time:  2013/10/25 20:10:41 * File Name: A.cpp * solve: A.cpp */#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//ios_base::sync_with_stdio(false);//#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define sz(v) ((int)(v).size())#define rep(i, a, b) for (int i = (a); i < (b); ++i)#define repf(i, a, b) for (int i = (a); i <= (b); ++i)#define repd(i, a, b) for (int i = (a); i >= (b); --i)#define clr(x) memset(x,0,sizeof(x))#define clrs( x , y ) memset(x,y,sizeof(x))#define out(x) printf(#x" %d\n", x)#define sqr(x) ((x) * (x))typedef long long LL;const LL INF = 100000000000000000;const double eps = 1e-8;const int maxn = 30000;int sgn(const double &x) { return (x > eps) - (x < -eps); }LL Pow(LL a,int b){ LL ans = 1; repf(i,1,b) ans*= a; return ans;}int main() { //freopen("in.txt","r",stdin); LL n; while(scanf("%I64d",&n) == 1) { LL k,r; LL Max = INF; LL ans1 = INF; LL ans2 = INF; repf(i,2,50) { r = i; LL L = 2; LL R = pow(n,1.0/i); k = -1; while(L <= R) { LL mid = (L + R)/2; LL temp = Pow(mid,i+1); if((temp - 1)%(mid - 1) == 0) { if((temp-1)/(mid-1) == n || (temp-1)/(mid-1) == n+1) { k = mid; break; } } if((temp-1)/(mid-1) <= n) L = mid + 1; if((temp-1)/(mid-1) >= n+1) R = mid - 1; } if(k == -1) { continue; } if(k*r < Max) { ans1 = r; ans2 = k; Max = k*r; } if(Max == k*r) { ans1 = min(ans1,r); } } if(ans1 == INF) { ans1 = 1; ans2 = n - 1; } cout<
<<" "<
<

 

转载于:https://www.cnblogs.com/DreamHighWithMe/p/3388568.html

你可能感兴趣的文章
2018.11.06 bzoj1040: [ZJOI2008]骑士(树形dp)
查看>>
2019.02.15 bzoj5210: 最大连通子块和(链分治+ddp)
查看>>
redis cluster 集群资料
查看>>
微软职位内部推荐-Sr. SE - Office incubation
查看>>
C#类与结构体究竟谁快——各种函数调用模式速度评测
查看>>
我到底要选择一种什么样的生活方式,度过这一辈子呢:人生自由与职业发展方向(下)...
查看>>
poj 题目分类
查看>>
windows 安装yaml支持和pytest支持等
查看>>
读书笔记:季羡林关于如何做研究学问的心得
查看>>
面向对象的优点
查看>>
套接口和I/O通信
查看>>
阿里巴巴面试之利用两个int值实现读写锁
查看>>
浅谈性能测试
查看>>
Winform 菜单和工具栏控件
查看>>
CDH版本大数据集群下搭建的Hue详细启动步骤(图文详解)
查看>>
巧用Win+R
查看>>
浅析原生js模仿addclass和removeclass
查看>>
Python中的greenlet包实现并发编程的入门教程
查看>>
java中遍历属性字段及值(常见方法)
查看>>
深入理解jQuery框架-框架结构
查看>>