注意会超long long

开i次根号方法,te=(ll)pow(n,1.0/i);

Yukari's Birthday

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3262    Accepted Submission(s): 695

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 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.
 
Input
There are about 10,000 test cases. Process to the end of file. Each test consists of only an integer 18 ≤ n ≤ 1012.
 
Output
For each test case, output r and k.
 
Sample Input
18 111 1111
 
Sample Output
1 17 2 10 3 10
 
Source
 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<iostream>
#define maxi(a,b) (a)>(b)?(a):(b)
#define mini(a,b) (a)<(b)?(a):(b)
#define N 1000005
#define mod 10000
#define ll long long using namespace std; ll n;
ll ans;
ll r,k;
ll rr,kk; void ini()
{
ans=n-;
r=;
k=n-;
} void cal3(ll x)
{
ll te,d;
te=+*x;
d=sqrt(te);
if(d*d==te){
kk=(d-);
if(kk%==){
kk/=;
if(kk*<ans){
ans=kk*;
k=kk;r=;
}
}
}
} ll cal(ll a,ll cnt)
{
ll re=;
while(cnt)
{
if(cnt&){
re=(re*a);
cnt--;
}
cnt/=;
a=a*a;
}
return re;
} int cal2(ll a,ll en,ll now)
{
ll i;
for(i=en;i>=;i--){
now+=cal(a,i);
if(now>n) return ;
}
if(now<n-) return ;
if(now==n- || now==n){
if(a*(en+)<ans){
ans=a*(en+);
r=en+;
k=a;
}
else{
if(a*(en+)==ans && (en+)<r){
r=en+;
k=a;
}
}
}
return ;
} void solve()
{
ll te,temp;
cal3(n);
cal3(n-);
ll i;
for(i=;i<=;i++){
//temp=cal(2ll,i);
//if(temp>n) break;
te=(ll)pow(n,1.0/i);
for(kk=te;kk>=;kk--){
temp=cal(kk,i);
if(temp>n) continue;
if(cal2(kk,i-,temp)==){
break;
}
}
}
} void out()
{
printf("%I64d %I64d\n",r,k);
} int main()
{
//freopen("data.in","r",stdin);
//scanf("%d",&T);
// while(T--)
while(scanf("%I64d",&n)!=EOF)
{
ini();
solve();
out();
}
return ;
}

hdu 4430 Yukari's Birthday 枚举+二分的更多相关文章

  1. HDU - 4430 Yukari's Birthday(二分+枚举)

    题意:已知有n个蜡烛,过生日在蛋糕上摆蜡烛,将蜡烛围成同心圆,每圈个数为ki,蛋糕中心最多可摆一个蜡烛,求圈数r和看,条件为r*k尽可能小的情况下,r尽可能小. 分析:n最大为1012,k最少为2,假 ...

  2. HDU 4430 Yukari's Birthday(二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4430 题目大意:给定n个蜡烛,围绕蛋糕的中心插同心圆,从里往外分别是第1圈.第2圈....第r圈,第 ...

  3. HDU4430 Yukari's Birthday(枚举+二分)

    Yukari's Birthday  HDU4430 就是枚举+二分: 注意处理怎样判断溢出...(因为题目只要10^12) 先前还以为要用到快速幂和等比数列的快速求和(但肯定会超__int64) 而 ...

  4. HDU 4430 Yukari's Birthday (二分+枚举)

    题意:给定一个n(18 ≤ n ≤ 10^12),一个等比数列k + k^2 + .......+ k^r = n 或者 = n-1,求出最小的k*r,如果最小的不唯一,则取r更小的 分析:两个未知数 ...

  5. hdu 4430 Yukari's Birthday (简单数学 + 二分)

    Problem - 4430 题意是,给出蜡烛的数量,要求求出r和k,r是蜡烛的层数,k是每一层蜡烛数目的底数. 开始的时候,没有看清题目,其实中间的那根蜡烛是可放可不放的.假设放置中间的那根蜡烛,就 ...

  6. HDU 4430 Yukari's Birthday (二分)

    题意:有 n 个蜡烛,让你插到蛋糕上,每一层要插 k^i个根,第0层可插可不插,插的层数是r,让 r * k 尽量小,再让 r 尽量小,求r 和 k. 析:首先先列出方程来,一个是不插的一个是插的,比 ...

  7. 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 ...

  8. hdu 4430 Yukari's Birthday

    思路: 分析知道1<=r<40:所以可以枚举r,之后再二分k. 代码如下: #include<iostream> #include<stdio.h> #includ ...

  9. zoj 3665 Yukari's Birthday(枚举+二分)

    Yukari's Birthday Time Limit: 2 Seconds       Memory Limit: 32768 KB Today is Yukari's n-th birthday ...

随机推荐

  1. Hdoj—1789

    //大意理解 先排序 最早交的里面选最大值 扫描完了加没写的 排序后 应该是早交的和扣分多的在前 用结构体吧/*#include<stdio.h>#include<stdio.h&g ...

  2. robotframework接口测试实例

    *** Settings *** Library Collections Library RequestsLibrary *** Test Cases *** test Create Session ...

  3. CPP-基础:C++拷贝构造函数详解

    一. 什么是拷贝构造函数 首先对于普通类型的对象来说,它们之间的复制是很简单的,例如: ; int b = a; 而类对象与普通对象不同,类对象内部结构一般较为复杂,存在各种成员变量.下面看一个类对象 ...

  4. Codeforces 727C Guess the Array

    题目传送门 长度为\(n\)的数组,询问\(n\)次来求出数组中每一个数的值 我们可以先询问三次 \(a[1]+a[2]\) \(a[1]+a[3]\) \(a[2]+a[3]\) 然后根据这三次询问 ...

  5. Python操作微信跳一跳

    “跳一跳”这个东西还是今天刚接触到的,看到了python群中有人再问“微信跳一跳的外挂有人写了没”,“早就有了”,“github”,“等着出个更详细的教程教程没看懂,主要没有用过adb”. 不过没关系 ...

  6. 自动化运维工具Ansible

    一.简介 当下有许多的运维自动化工具( 配置管理 ),例如:Ansible.SaltStack.Puppet.Fabric 等. Ansible 一种集成 IT 系统的配置管理.应用部署.执行特定任务 ...

  7. C语言:哲学家吃饭问题

    //五个哲学家围坐在一起,两人之间都放有一个叉子,意大利面需要2个叉子吃,哲学家吃饭时候叉子只能拿左右手,哲学家除了吃饭时间其他时间都在思考 #include <stdio.h> #inc ...

  8. grunt---grunt_test 测试用例

    说明: http://www.gruntjs.net/getting-started --grunt快速入门(创建package.json和Gruntfile.js准备一份新的 Grunt 项目一般需 ...

  9. Leetcode 354.俄罗斯套娃信封问题

    俄罗斯套娃信封问题 给定一些标记了宽度和高度的信封,宽度和高度以整数对形式 (w, h) 出现.当另一个信封的宽度和高度都比这个信封大的时候,这个信封就可以放进另一个信封里,如同俄罗斯套娃一样. 请计 ...

  10. Working out (DP)

    Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the ...