hdu4430 枚举+二分
Yukari's Birthday
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4934 Accepted Submission(s): 1163
To make the birthday cake look more beautiful, Ran and Chen decide to place them like r ≥ 1 concentric circles. They place ki 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.
Each test consists of only an integer 18 ≤ n ≤ 1012.
111
1111
2 10
3 10
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef __int64 ll;
ll n;
int main()
{
while(scanf("%I64d",&n)!=EOF)
{
ll r=,k=n-;
int i,j;
for(i=;i<=;i++)
{
ll kl=,kr=n;
while(kl<=kr)
{
ll sum=;
ll mid=(kl+kr)>>;
ll sum_now=;
for( j=;j<=i;j++)
{
if(sum>n)
{
sum=n+;
break;
}
if(n/sum_now<mid)
{
sum=n+;
break;
}
sum_now*=mid;
sum+=sum_now;
}
if(sum==n||sum==n-)
{
if(mid*i<k*r)
{
k=mid,r=i;
}
else if(mid*i==k*r&&i<r)
{
k=mid,r=i;
}
break;
}
if(sum>n||sum<) kr=mid-;
else kl=mid+;
}
}
printf("%I64d %I64d\n",r,k);
}
}
hdu4430 枚举+二分的更多相关文章
- HDU4430 Yukari's Birthday(枚举+二分)
Yukari's Birthday HDU4430 就是枚举+二分: 注意处理怎样判断溢出...(因为题目只要10^12) 先前还以为要用到快速幂和等比数列的快速求和(但肯定会超__int64) 而 ...
- CSU OJ PID=1514: Packs 超大背包问题,折半枚举+二分查找。
1514: Packs Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 61 Solved: 4[Submit][Status][Web Board] ...
- 4 Values whose Sum is 0(枚举+二分)
The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute ...
- hdu4430之枚举+二分
Yukari's Birthday Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分
C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...
- HDU 4282 A very hard mathematic problem --枚举+二分(或不加)
题意:问方程X^Z + Y^Z + XYZ = K (X<Y,Z>1)有多少个正整数解 (K<2^31) 解法:看K不大,而且不难看出 Z<=30, X<=sqrt(K) ...
- Subset---poj3977(折半枚举+二分查找)
题目链接:http://poj.org/problem?id=3977 给你n个数,找到一个子集,使得这个子集的和的绝对值是最小的,如果有多种情况,输出子集个数最少的: n<=35,|a[i]| ...
- hdu 5288 OO’s Sequence 枚举+二分
Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...
- codeforces 613B B. Skills(枚举+二分+贪心)
题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
随机推荐
- [转]C# FileSystemWatcher监控指定文件或目录的文件的创建、删除、改动、重命名等活动
觉得这个很常用..比如一些软件. http://www.rabbit8.cn/DoNet/407.html FileSystemWatcher控件主要功能: 监控指定文件或目录的文件的创建.删 ...
- Chrome extension
PageSpeed Tincr SpriteMe JSONView FireMobileSimulator for Google Chrome™
- Preventing Web Attacks with Apache
http://www.boyunjian.com/do/article/snapshot.do?uid=net.csdn.blog/wurangy050/article/details/5287235
- XML SAX解析
SAX是一种占用内存少且解析速度快的解析器,它采用的是事件驱动,它不需要解析完整个文档,而是按照内容顺序,看文档某个部分是否符合xml语法,如果符合就触发相应的事件.所谓的事件就是些回调方法( cal ...
- INKDIE
ink die是指分割出来的芯片未能达到原装芯片要求的那些U盘芯片,也就是俗称的黑片. 一整块圆硅分割制成芯片之后需要对其质量进行筛选,根据筛选的要求不同分为三个等级:原装的(Original).白片 ...
- [Delphi]检查URL是否有效的函数
function CheckUrl(url: string): boolean; var hSession, hfile, hRequest: hInternet; dwindex, dwcodele ...
- 【HDOJ】2416 Treasure of the Chimp Island
bfs().题目的数据乱码.应该如下: *****#********* *.......$...* *..***.......* *....*****..* *....******37A *****. ...
- 多线程爬虫Java调用wget下载文件,独立线程读取输出缓冲区
写了个抓取appstore的,要抓取大量的app,本来是用httpclient,但是效果不理想,于是直接调用wget下载,但是由于标准输出.错误输出的原因会导致卡住,另外wget也会莫名的卡住. 所以 ...
- IBM Intel 微软
IBM是全球IT第一巨头,也是一个很奇特也很强大强大的公司,从螺丝钉键盘鼠标到CPU硬盘内存到大型机巨型机,它都可以制造,从软件到硬件到服务,它都可以提供,这在IT历史上,是否绝后我不敢说,空前应该是 ...
- Scala 编程(三)基本类型和操作
一些基本类型 值类型 范围 Byte 8位有符号补码整数(-27-27-1) Short 16位有符号补码整数(-215-215-1) Int 32位有符号补码整数(-231-231-1) Long ...