日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU 4430 amp; ZOJ 3665 Yukari#39;s Birthday(二分法+枚举)

發布時間:2024/4/17 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 4430 amp; ZOJ 3665 Yukari#39;s Birthday(二分法+枚举) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

主題鏈接:

HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4430

ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?

problemId=4888


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 2012 Asia ChangChun Regional Contest

題意:

要在一個蛋糕上放置 n 根蠟燭,擺成 r 個同心圓,每一個同心圓的蠟燭數為 k ^ i ,中間的圓心能夠放一根或者不放,使得 r * k 最小,若有多個答案輸出 r 最小的那個。


PS:

由于r是非常小的 !

枚舉r查找k。


代碼例如以下:(HDU,ZOJ上把64位換為long long就OK啦……)

#include <cstdio> #include <cmath> #include <cstring> #include <iostream> #include <algorithm> using namespace std; //typedef long long LL; typedef __int64 LL; #define ONLINE_JUDGE #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif LL n; LL findd(LL m) {LL l, r, mid;l = 2;r = n;while(l <= r){mid = (l+r)/2;LL sum = 0, tt = 1;for(LL i = 1; i <= m; i++){if(n/tt < mid)//注意可能溢出用除法推斷一下{//tt*mid > nsum = n+1;break;}tt*=mid;sum += tt; // if(sum > n)//防止溢出 // break;}if(sum == n-1 || sum == n){return mid;}if(sum < n-1){l = mid+1;}else if(sum > n){r = mid-1;}}return -1;//沒有符合的 }int main() {LL r, k, rr, kk;while(~scanf("%I64d",&n)){rr = r = 1;kk = k = n-1;for(LL i = 2; i <= 64; i++){LL tt = findd(i); // if(i >= n) // break; // printf("tt:%I64d>>>%I64d\n",i,tt);if(i*tt < rr*kk && tt != -1){r = i;k = tt;rr = i;kk = tt;}}printf("%I64d %I64d\n",r,k);}return 0; }/* 18 111 1111 1022 8190 134217726 34359738366 68719476734 */

版權聲明:本文博客原創文章,博客,未經同意,不得轉載。

轉載于:https://www.cnblogs.com/mfrbuaa/p/4734044.html

總結

以上是生活随笔為你收集整理的HDU 4430 amp; ZOJ 3665 Yukari#39;s Birthday(二分法+枚举)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。