[ACM] 100題

看板C_and_CPP (C/C++)作者 (Struggle in the mud)時間15年前 (2010/11/08 04:31), 編輯推噓0(005)
留言5則, 5人參與, 最新討論串1/1
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 ) ( 未必需要依照此格式,文章條理清楚即可 ) 題號: 100 遇到的問題: Time limit exceeded 中文題目 link http://www.tcgs.tc.edu.tw/~sagit/luckycat/q100.htm 有問題的code: (請善用置底文的標色功能) #include <iostream> #include <vector> using namespace std; int main(){ while(true) { unsigned long i,j,t,n,temp,max,s; vector<unsigned long> x(1000000,0); cin>>i>>j; temp=0; if(i>j){ temp=i; i=j; j=temp; temp=1; } if(i>0 && j<= 1000000){ max=0; for(n=i;n<=j;n++){ s=0; t=n; while (t!=1){ s++; if (t%2==1) t=3*t+1; else t=t/2; if (t<x.size() && x[t]){ s+= x[t]; break;} } x[n]=s; if (max<s) max=s; } if(temp==1){ temp=i; i=j; j=temp; } cout<<i<<" "<<j<<" "<<max+1<<endl; } } return 0; } 補充說明: 剛開始練習就撞牆,但是不懂為啥,會超過時間 就上網找答案 發現 http://meagar.net/projects/2 是accepted 後來修改原本的code(就是目前po上的) 還是超過時間 請問一下版上的高手 到底我哪裡出了問題 麻煩請指導一下 感恩!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.39.173.180 ※ 編輯: ajeams 來自: 114.39.173.180 (11/08 04:32)

11/08 07:33, , 1F
while(true)
11/08 07:33, 1F

11/08 09:28, , 2F
while (cin >> i >> j) { ... }
11/08 09:28, 2F

11/08 09:45, , 3F
非常感謝!!!
11/08 09:45, 3F

11/08 11:53, , 4F
這題好像經典到不能在經典了(第一次去UVA也遇到這問題@@)
11/08 11:53, 4F

11/08 12:01, , 5F
回樓上,因為這是第一題XD
11/08 12:01, 5F
文章代碼(AID): #1CrmoErw (C_and_CPP)
文章代碼(AID): #1CrmoErw (C_and_CPP)