HDU 4430
来源:互联网 发布:手机图纸算量软件 编辑:程序博客网 时间:2024/04/28 18:05
HDU 4430
Description
Today isYukari's n-th birthday. Ran and Chen hold a celebration party for her. Nowcomes the most important part, birthday cake! But it's a big challenge for themto place n candles on the top of the cake. As Yukari has lived for such a longlong 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 placethem like r ≥ 1 concentric circles. They place k i candlesequidistantly on the i-th circle, where k ≥ 2, 1 ≤ i ≤ r. And it's optional toplace at most one candle at the center of the cake. In case that there are alot of different pairs of r and k satisfying these restrictions, they want tominimize r × k. If there is still a tie, minimize r.
Input
There are about10,000 test cases. Process to the end of file.
Each test consists of only an integer 18 ≤ n ≤ 10 12.
Output
For each testcase, output r and k.
Sample Input
18
111
1111
Sample Output
1 17
2 10
3 10
一.题意分析
蛋糕从内到外是一组同心圆,有r层,最中间放一个蜡烛,然后往外每一层放ki个蜡烛。要求r*k最小,并且输出最小时的r。
二.思路过程
先估算出r的大小范围,大概在40左右。然后对r的范围进行二分,最后枚举出结果。
三.代码
<span style="font-family:Courier New;font-size:18px;">#include <iostream>#include <cstdio>using namespace std;#define ll long long ll n; ll erfen(ll t){ ll i; ll left = 2, right = n, mid; while(left <= right) { ll sum = 1, ans = 0; mid = (left + right) / 2; for(i=1; i<=t; i++) { if(n/sum<mid) { ans = n + 1; break; } sum*=mid; ans+=sum; if(ans>n) break; } if(ans == n || ans == n-1) return mid; else if(ans < n-1) left = mid + 1; else right = mid -1; } return -1;} int main(){ ll i, left, right, mid, tmp; while(scanf("%lld", &n)!=EOF) { left = 1, right = n - 1; for(i=2; i<45; i++) { tmp = erfen(i); if(tmp!=-1 && i * tmp < left * right) { left = i, right = tmp; } } printf("%lld %lld\n", left, right); } return 0;}</span>
- hdu 4430
- HDU 4430
- HDU 4430
- HDU 4430
- hdu 4430 枚举+二分
- hdu 4430 二分+枚举
- HDU 4430 二分查找
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- 十分钟让你明白Objective-C的语法(和Java、C++的对比)
- Prim 模板 POJ 3625
- 初学python —— 备份文件脚本
- NYOJ 999 师傅又被妖怪抓走了(待续)
- Rust: 如何在Windows下Atom中配置Rust环境?
- HDU 4430
- AOP技术基础
- superLU 在VS2010中的配置
- thinkphp引入第三方类库
- android 颜色大全
- Linux set命令参数及用法详解--Linux设置环境变量命令
- 值得一看的GitHub源码
- SqlServer存储过程、函数、游标例子之函数(一)
- UVA 10006