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 ...
随机推荐
- 蓝牙-b
最近智能家居比较火,好多公司开始开发通过蓝牙对智能家居进行连接控制!下面,我就把自己总结的蓝牙方面的知识分享一下!求吐槽!!!!O(∩_∩)O... 1.导入头文件#import <CoreBl ...
- GIve Me A Welcome Hug!
类似于初来乍到,和大家打个招呼,并矫情的希望路人也能回赠我一个welcome hug. 到了这种园子那一定是做CS相关的了,一直以为如果能够坚持写技术博客,那一定会对自己的内力有十足的提升.借用一位前 ...
- Fetcher类的工作流程
Fetcher类工作流程: FileInputFormat.addInputPath(job, new Path(segment, CrawlDatum.GENERATE_DIR_NAME)); jo ...
- LD1-K(求差值最小的生成树)
题目链接 /* *题目大意: *一个简单图,n个点,m条边; *要求一颗生成树,使得其最大边与最小边的差值是所有生成树中最小的,输出最小的那个差值; *算法分析: *枚举最小边,用kruskal求生成 ...
- 解读sample1
说明 理解被测试代码 理解测试代码 TEST宏 EXPECT_*断言和ASSERT_*断言 检查数值比较结果的断言 检查布尔值的断言 说明 被测试代码文件 sample1.h.sample1.cc 测 ...
- Hive学习笔记【转载】
本文转载自:http://blog.csdn.net/haojun186/article/details/7977565 1. HIVE结构 Hive 是建立在 Hadoop 上的数据仓库基础构架. ...
- Spring JDBC 随笔
Spring 框架,借助 JdbcTemplate 类来简化 java 访问 database. 完成一个增查改删(CRUD)的基本功能,借助下面 5 个角色来共同来完成. 1. object cla ...
- 最受欢迎linux命令
1. 以 root 帐户执行上一条命令 sudo !! 2. 利用 Python 搭建一个简单的 Web 服务器,可通过 http://$HOSTNAME:8000访问 python -m ...
- WIndows系统下mysql-noinstall安装配置
环境: Windowsmysql-noinstall-5.0.37-win32.zip 一.下载MySQL http://www.mysql.com/downloads 二.安装过程 1.解压缩mys ...
- powershell利用winform批量执行tsql语句
#加载.net的winform模块 [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $app= ...