hdu4430 Yukari's Birthday 枚举+二分
来源:互联网 发布:协同过滤 共现矩阵 编辑:程序博客网 时间:2024/05/16 15:57
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.
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.
嗯,题意就是紫妈要过生日了,所以蓝和橙要给她买蛋糕,然后插对应年龄的蜡烛(明明应该只插17个的,式神们都不要命了。。。)
然后蜡烛插 r 圈 每圈插k^n个蜡烛,中心可以插一只蜡烛或者不插,问最后r*k最小的插法是什么,如果有相同就输出r最小的。
2的39次方就是5e12了,从2扫到40即可
枚举r,对k进行二分找到满足条件的k值,注意一下r的初值不能太大,否则会wa,原因不明
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<iostream>#include<vector>#include<string>#include<cmath>#include<stack>using namespace std;const long long inf=1e16;typedef long long ll;ll n;int calc(ll mid,int num){ll ansav=mid;ll ans=0;for(int i=1;i<=num;i++){ans+=ansav;//if(ansav==17) printf("ans=%lld\n",ans);ansav*=mid;}if(ans<0) return 1;else if(ans==n||ans+1LL==n) return 2;else if(ans < n) return 0;else return 1;}//long long ans=(mid-powLL(mid,i+1))/(1-mid);int main(){ //printf("%lld\n",1LL<<39); while(scanf("%lld",&n)!=EOF){ll savr=1,savk=n-1;ll ans=n-1;for(int i=2;i<=40;i++){ll l=2,r=(long long)pow(n,1.0/i);while(l<=r){ll mid=(l+r)/2;//if(i==5) printf("%lld %lldmid=%lld\n",l,r,mid);if(calc(mid,i)==2){if(ans>mid*i){ans=mid*i;savr=i;savk=mid;//printf("%lld %lld %lld\n",savr,savk,ans);}break;}else if(calc(mid,i)==0) l=mid+1;else r=mid-1;}} //printf("%d\n",17); 紫妹永远17岁printf("%I64d %I64d\n",savr,savk);} return 0;}
//紫大人我喜欢你啊
1 0
- hdu4430 Yukari's Birthday 枚举+二分
- HDU4430:Yukari's Birthday(二分)
- HDU4430 Yukari's Birthday 二分
- hdu4430 Yukari's Birthday(二分)
- HDU4430 ——Yukari's Birthday (二分,快速幂)
- hdu 4430 Yukari's Birthday 枚举+二分
- hdu 4430 Yukari's Birthday(二分+枚举)
- Hdu 4430 Yukari's Birthday 枚举+二分
- HDU 4430 Yukari's Birthday (二分+枚举)
- zoj 3665 Yukari's Birthday(枚举+二分)
- HDU 4430 Yukari's Birthday 枚举+二分
- HDOJ 4430 Yukari's Birthday 【枚举】+【二分】
- HDU 4430 Yukari's Birthday(枚举+二分)
- HDU 4430 Yukari's Birthday【二分+枚举】
- HDU 4430 Yukari's Birthday (枚举 二分)
- HDU 4430 & ZOJ 3665 Yukari's Birthday(二分+枚举)
- HDU 4430 Yukari's Birthday(枚举+二分)
- hdu 4430 Yukari's Birthday(二分)
- jquey版本问题
- Android常用的组件间通信方式
- POJ-1363 Rails (栈)
- play framework route地址错误
- gulp
- hdu4430 Yukari's Birthday 枚举+二分
- Torch7学习(六)——学习神经网络包的用法(4)——利用optim进行训练
- vs2013 + opencv 3.1
- Android自定义相机定点聚焦
- 玩转iOS开发:《iOS设计模式 — 单例模式》
- Struts2返回JSON对象的方法总结
- Android——2016新技术Rxjava
- Android 6.0开发的权限注意事项
- BZOJ 1226: [SDOI2009]学校食堂Dining