Prob_Solve 板


LINE

題目敘述網址: http://code.google.com/codejam/contest/544101/dashboard#s=p2 雖然小弟的 algorithm 也能在限定時間內跑完 small set 及 large set, 但是看了前幾名的 algorithm, 似乎都有用到 (sqrt(5.0) + 1.0) / 2.0, 有高手可以解釋一下這個神秘的數字是什麼意思嗎? [第一名解答 in C++, <_.._>] #include <iostream> #include <sstream> #include <string> #include <vector> #include <deque> #include <queue> #include <set> #include <map> #include <algorithm> #include <functional> #include <utility> #include <cmath> #include <cstdlib> #include <ctime> #include <cstdio> using namespace std; #define REP(i,n) for((i)=0;(i)<(int)(n);(i)++) #define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++) template <class T> inline string itos(T n) {return (n)<0?"-"+itos(-(n)):(n)<10?(string)("")+(char)('0'+(n)):itos((n)/10)+itos((n)%10);} typedef long long ll; int case_number; #define printg case_number++, printf("Case #%d: ",case_number), printf #define gout case_number++, printf("Case #%d: ",case_number), cout double golden = (sqrt(5.0) + 1.0) / 2.0; ll main2(int A1, int A2, int B1, int B2){ // A * golden < B ll ans = 0; for(int A=A1;A<=A2;A++){ int x = (int)(A * golden) + 1; x = max(x,B1); if(x <= B2) ans += B2 - x + 1; } return ans; } int main(void){ int number_of_test_cases,i; scanf("%d",&number_of_test_cases); REP(i,number_of_test_cases){ int A1,A2,B1,B2; scanf("%d%d%d%d",&A1,&A2,&B1,&B2); ll ans = main2(A1,A2,B1,B2) + main2(B1,B2,A1,A2); gout << ans << endl; } return 0; } [小弟的解答 in Java, 或許還有可以改進的空間, 互相漏氣求進步囉…] import java.io.*; class GCJ_2010_1A_C { private static final int MAX_NUMBER = 1000000; private static int[] loseBegin = new int[MAX_NUMBER + 1]; private static int[] loseEnd = new int[MAX_NUMBER + 1]; public static void calculateLoseRange() { loseBegin[1] = 1; loseEnd[1] = 1; loseBegin[2] = 2; loseEnd[2] = 3; for (int i = 3; i <= MAX_NUMBER; i++) { int begin = loseBegin[i - 1]; while (loseEnd[begin] < i) { begin++; } loseBegin[i] = begin; loseEnd[i] = begin + i - 1; } } public static void main(String[] args) { try { BufferedReader input = new BufferedReader(new FileReader(args[0])); BufferedWriter output = new BufferedWriter(new FileWriter(args[1])); calculateLoseRange(); String line = input.readLine(); int T = Integer.parseInt(line); for (int i = 1; i <= T; i++) { line = input.readLine(); int A1 = Integer.parseInt(line.substring(0, line.indexOf(' '))); line = line.substring(line.indexOf(' ') + 1); int A2 = Integer.parseInt(line.substring(0, line.indexOf(' '))); line = line.substring(line.indexOf(' ') + 1); int B1 = Integer.parseInt(line.substring(0, line.indexOf(' '))); line = line.substring(line.indexOf(' ') + 1); int B2 = Integer.parseInt(line); long count = 0; for (int j = A1; j <= A2; j++) { int lose = Math.max(0, Math.min(B2, loseEnd[j]) - Math.max(B1, loseBegin[j]) + 1); int win = (B2 - B1 + 1) - lose; count += win; } String result = "Case #" + i + ": " + count; System.out.println(result); // output.write(result); output.newLine(); } input.close(); output.close(); } catch (Exception e) { e.printStackTrace(); } } } --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.126.30.95
1F:推 scwg:golden ratio 02/20 00:58
2F:→ RockLee:感謝 S 大迅速的回覆. 有人可以進一步開示一下, 02/20 06:14
3F:→ RockLee:這個題目是如何推導到用 golden ratio 來解的嗎? 02/20 06:14
4F:→ RockLee:<_.._> 02/20 06:15
5F:→ LPH66:或者可以搜尋「歐氏對局」 02/20 15:09
6F:→ RockLee:感謝 L 大的開示, 我找到相關的說明了 02/20 15:46







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Gossiping站內搜尋

TOP