HDU 4430 Yukari's birthday enumeration + binary

Source: Internet
Author: User

It will be too long.

Open the I root number method, 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 descriptiontoday 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 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. inputthere are about 10,000 test cases. process to the end of file. each test consists of only an integer 18 ≤ n ≤ 1012. outputfor each test case, output R and K. sample input18 111 1111 sample output1 17 2 10 3 10 source2012 Asia Changchun Regional Contest

 

  1 #include<cstdio>  2 #include<cstdlib>  3 #include<cmath>  4 #include<cstring>  5 #include<string>  6 #include<iostream>  7 #define maxi(a,b) (a)>(b)?(a):(b)  8 #define mini(a,b) (a)<(b)?(a):(b)  9 #define N 1000005 10 #define mod 10000 11 #define ll long long 12  13 using namespace std; 14  15 ll n; 16 ll ans; 17 ll r,k; 18 ll rr,kk; 19  20 void ini() 21 { 22     ans=n-1; 23     r=1; 24     k=n-1; 25 } 26  27 void cal3(ll x) 28 { 29     ll te,d; 30     te=1+4*x; 31     d=sqrt(te); 32     if(d*d==te){ 33         kk=(d-1); 34         if(kk%2==0){ 35             kk/=2; 36             if(kk*2<ans){ 37                 ans=kk*2; 38                 k=kk;r=2; 39             } 40         } 41     } 42 } 43  44 ll cal(ll a,ll cnt) 45 { 46     ll re=1; 47     while(cnt) 48     { 49         if(cnt&1){ 50             re=(re*a); 51             cnt--; 52         } 53         cnt/=2; 54         a=a*a; 55     } 56     return re; 57 } 58  59 int cal2(ll a,ll en,ll now) 60 { 61     ll i; 62     for(i=en;i>=1;i--){ 63         now+=cal(a,i); 64         if(now>n) return 0; 65     } 66     if(now<n-1) return 2; 67     if(now==n-1 || now==n){ 68         if(a*(en+1)<ans){ 69             ans=a*(en+1); 70             r=en+1; 71             k=a; 72         } 73         else{ 74             if(a*(en+1)==ans && (en+1)<r){ 75                 r=en+1; 76                 k=a; 77             } 78         } 79     } 80     return 2; 81 } 82  83 void solve() 84 { 85     ll te,temp; 86     cal3(n); 87     cal3(n-1); 88     ll i; 89     for(i=3;i<=45;i++){ 90         //temp=cal(2ll,i); 91         //if(temp>n) break; 92         te=(ll)pow(n,1.0/i); 93         for(kk=te;kk>=2;kk--){ 94             temp=cal(kk,i); 95             if(temp>n) continue; 96             if(cal2(kk,i-1,temp)==2){ 97                 break; 98             } 99         }100     }101 }102 103 void out()104 {105     printf("%I64d %I64d\n",r,k);106 }107 108 int main()109 {110     //freopen("data.in","r",stdin);111     //scanf("%d",&T);112    // while(T--)113     while(scanf("%I64d",&n)!=EOF)114     {115         ini();116         solve();117         out();118     }119     return 0;120 }

 

HDU 4430 Yukari's birthday enumeration + binary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.