hdu 4430 Yukari's Birthday 枚举+二分
2014-10-17 20:12
381 查看
注意会超long long
开i次根号方法,te=(ll)pow(n,1.0/i);
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
There are about 10,000 test cases. Process to the end of file. Each test consists of only an integer 18 ≤ n ≤ 1012.
[align=left]Output[/align]
For each test case, output r and k.
[align=left]Sample Input[/align]
18 111 1111
[align=left]Sample Output[/align]
1 17 2 10 3 10
[align=left]Source[/align]
2012 Asia ChangChun Regional Contest
开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[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
There are about 10,000 test cases. Process to the end of file. Each test consists of only an integer 18 ≤ n ≤ 1012.
[align=left]Output[/align]
For each test case, output r and k.
[align=left]Sample Input[/align]
18 111 1111
[align=left]Sample Output[/align]
1 17 2 10 3 10
[align=left]Source[/align]
2012 Asia ChangChun Regional Contest
#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-1; r=1; k=n-1; } void cal3(ll x) { ll te,d; te=1+4*x; d=sqrt(te); if(d*d==te){ kk=(d-1); if(kk%2==0){ kk/=2; if(kk*2<ans){ ans=kk*2; k=kk;r=2; } } } } ll cal(ll a,ll cnt) { ll re=1; while(cnt) { if(cnt&1){ re=(re*a); cnt--; } cnt/=2; a=a*a; } return re; } int cal2(ll a,ll en,ll now) { ll i; for(i=en;i>=1;i--){ now+=cal(a,i); if(now>n) return 0; } if(now<n-1) return 2; if(now==n-1 || now==n){ if(a*(en+1)<ans){ ans=a*(en+1); r=en+1; k=a; } else{ if(a*(en+1)==ans && (en+1)<r){ r=en+1; k=a; } } } return 2; } void solve() { ll te,temp; cal3(n); cal3(n-1); ll i; for(i=3;i<=45;i++){ //temp=cal(2ll,i); //if(temp>n) break; te=(ll)pow(n,1.0/i); for(kk=te;kk>=2;kk--){ temp=cal(kk,i); if(temp>n) continue; if(cal2(kk,i-1,temp)==2){ 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 0; }
相关文章推荐
- HDU 4430 Yukari's Birthday 二分
- hdu 4430 Yukari's Birthday(二分+枚举)
- K - Yukari's Birthday HDU - 4430 (二分)
- HDU 4430 Yukari's Birthday二分查找
- HDU 4430 Yukari's Birthday (二分+枚举)
- TOJ 4373 HDU 4430 ZOJ 3665 Yukari's Birthday / 二分
- hdu 4430 Yukari's Birthday(二分)
- 二分——hdu 4430 Yukari's Birthday
- HDU 4430 Yukari's Birthday(二分)
- HDU 4430 Yukari's Birthday (二分)
- hdu 4430 Yukari's Birthday (简单数学 + 二分)
- HDU 4430 Yukari's Birthday 枚举+二分
- HDU 4430 Yukari's Birthday (二分+枚举)
- HDU 4430 Yukari\'s Birthday
- HDU 4430 Yukari's Birthday (枚举 二分)
- HDU ~ 4430 ~ Yukari's Birthday(二分or数学)
- HDU 4430 Yukari's Birthday【二分+枚举】
- HDU 4430 Yukari's Birthday 二分
- hdu 4430 Yukari's Birthday(二分+枚举)
- HDU - 4430(二分)