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 ...
随机推荐
- FPGA同步复位异步复位
今天看了篇博客, 是拿altera的芯片和软件作例子的,讲同步异步复位的: http://blog.sina.com.cn/s/blog_bff0927b0101aaii.html 还有一个博客, h ...
- [工具]sublime text2-前端开发利器
之前在知乎上搜索好用的前端开发工具,投票最多的是webStrom,试用过后发现果真好用,代码补全,代码检查,支持主流的版本控制,比如git,svn等等.但是毕竟是一款集成的IDE,启动速度慢.吃内存是 ...
- poj 1275 Cashier Employment
http://poj.org/problem?id=1275 #include <cstdio> #include <cstring> #include <algorit ...
- JS线程模型&Web Worker
js线程模型 客户端javascript是单线程,浏览器无法同时运行两个事件处理程序 设计为单线程的理论是,客户端的javascript函数必须不能运行太长时间,否则会导致web浏览器无法对用户输入做 ...
- 如何创建WIN服务
sc create ServiceName binPath= "XXXX.exe" displayName= "中文xxxx"binpath和displayna ...
- B - Networking - poj 1287
有一些地方需要铺盖电缆,这些地方两点间的路可能不止一条,需要求出来至少需要多少电缆才能让所有的点都连接起来,当然,间接连接也算. /////////////////////////////////// ...
- 什么是券商PB业务
PB业务(Prime Broker,主经纪商业务).所谓PB业务就是指向对冲基金等高端机构客户提供集中托管清算.后台运营.研究支持.杠杆融资.证券拆借.资金募集等一站式综合金融服务的统称.而该业务的基 ...
- Highcharts下载与使用_数据报表图2
- springmvc实现REST中的GET、POST、PUT和DELETE
spring mvc 支持REST风格的请求方法,GET.POST.PUT和DELETE四种请求方法分别代表了数据库CRUD中的select.insert.update.delete,下面演示一个简单 ...
- 这是一个在Windows live 上实验的文章
这是一个windows 实验用的文章,希望一次成功