[ACM] 100題
看板C_and_CPP (C/C++)作者ajeams (Struggle in the mud)時間15年前 (2010/11/08 04:31)推噓0(0推 0噓 5→)留言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
11/08 07:33, 1F
→
11/08 09:28, , 2F
11/08 09:28, 2F
→
11/08 09:45, , 3F
11/08 09:45, 3F
→
11/08 11:53, , 4F
11/08 11:53, 4F
→
11/08 12:01, , 5F
11/08 12:01, 5F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章