ZOJ 3665 Yukari's Birthday (2012长春现场赛K题)
2012-10-14 20:19
489 查看
题意:把n只蜡烛插在蛋糕上,中间可以插1只蜡烛,也可以不插,,外面r层,每层为k^i只。k>1 问rk取何值时,可以把n只蜡烛都插上,。如果多种方法,取r最小的。。
思路:把r>3,r=2,r=1;分开考虑;
思路:把r>3,r=2,r=1;分开考虑;
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <queue> #include <stack> #include <map> using namespace std; #define LL long long LL X = 1000000000000ll; struct nod{ int r,k; } re[12000]; int cnt; LL oor0(int r,int k) { LL ret=0; for(int i=1;i<=r;i++) { ret+=pow(k,i); if(ret>X) return -1; } return ret; } map<LL,int> mp; void init() { for(int i=3;i<64;i++) { for(int j=2;j<10009;j++) { LL t = oor0(i,j); if(t<=0) break; re[cnt].r = i,re[cnt].k = j; mp[t] = cnt; cnt++; t++; } } } int main() { freopen("in.txt","r",stdin); init(); LL a; LL x,y; while(cin>>a) { if(mp.find(a)!=mp.end()) { int k = mp[a]; x = re[k].r,y=re[k].k; } else if(mp.find(a-1)!=mp.end()) { int k = mp[a-1]; x = re[k].r,y=re[k].k; }else{ LL k = (LL)sqrt(a);//cout<<k<<endl; if(k*(k+1)==a||k*(k+1)==a-1){ x = 2,y =k; }else{ x = 1,y=a-1; } } cout<<x<<" "<<y<<endl; } return 0; }
相关文章推荐
- ZOJ 3665 Yukari's Birthday (2012长春现场赛K题)
- hdu4430 Yukari's Birthday 2012 ACM_ICPC Asia ChangChun Regional Contest problem K
- TOJ 4373 HDU 4430 ZOJ 3665 Yukari's Birthday / 二分
- ZOJ 3665 Yukari's Birthday(12年长春区域赛-K题-二分)
- ZOJ 3657 The Little Girl who Picks Mushrooms(2012长春现场赛C题)
- ZOJ 3657The Little Girl..2012长春现场赛C题(简单思维+细心)
- zoj 3662 Math Magic 【dp】【2012 长春现场赛】
- zoj 3665 Yukari's Birthday(枚举+二分)
- zoj 3656 Bit Magic【2-sat】【2012 长春现场赛】
- HDU 4430 & ZOJ 3665 Yukari's Birthday(二分法+枚举)
- HDU 4430 Yukari's Birthday 枚举+二分
- HDU 4430 & ZOJ 3665 Yukari's Birthday(二分+枚举)
- HDOJ 4430 Yukari's Birthday 【枚举】+【二分】
- ZOJ Problem Set - 3665 Yukari's Birthda
- zoj 3659 Conquer a New Region【并查集】【2012长春现场赛】
- ZOJ3659,2012长春现场赛E题,并查集
- [ZOJ 3633]Alice's present 离线分块/线段树
- 长春现场赛E题 zoj 3659
- ZOJ 3633 Alice's present (STL set)
- hdu 4274 Spy's Work(2012 长春网络赛 树形DP)