一道ACM題,總是 output limit exceed,誰能告我為什么是這個錯誤
一道ACM題,總是 output limit exceed,誰能告我為什么是這個錯誤
1013:The 3n + 1 problem
Time Limit:1 Sec Memory Limit:64 MB
Submit:58 Solved:16
[Submit][STATUS][Web Board]
Description
Consider the following algorithm to generate a sequence of numbers.Start with an integer n.If n is even,divide by 2.If n is odd,multiply by 3 and add 1.Repeat this process with the new value of n,terminating when n = 1.For example,the following sequence of numbers will be generated for n = 22:22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 It is conjectured (but not yet proven) that this algorithm will terminate at n = 1 for every integer n.Still,the conjecture holds for all integers up to at least 1,000,000.For an input n,the cycle-length of n is the number of numbers generated up to and including the 1.In the example above,the cycle length of 22 is 16.Given any two numbers i and j,you are to determine the maximum cycle length over all numbers between i and j,including both endpoints.
Input
The input will consist of a series of pairs of integers i and j,one pair of integers per line.All integers will be less than 1,000,000 and greater than 0.
Output
For each pair of input integers i and j,output i,j in the same order in which they appeared in the input and then the maximum cycle length for integers between and including i and j.These three numbers should be separated by one space,with all three numbers on one line and with one line of output for each line of input.
Sample Input
1 10
100 200
201 210
900 1000
Sample Output
1 10 20
100 200 125
201 210 89
900 1000 174
我的代碼:
#include
int main()
{
long i,j,k,s,t,max,m;
while(scanf("%ld%ld",&i,&j))
{
max=0;
for(k=i;kmax)
{
max=s;
}
}
printf("%ld %ld %ld\n",i,j,max);
}
return 0;
}
1013:The 3n + 1 problem
Time Limit:1 Sec Memory Limit:64 MB
Submit:58 Solved:16
[Submit][STATUS][Web Board]
Description
Consider the following algorithm to generate a sequence of numbers.Start with an integer n.If n is even,divide by 2.If n is odd,multiply by 3 and add 1.Repeat this process with the new value of n,terminating when n = 1.For example,the following sequence of numbers will be generated for n = 22:22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 It is conjectured (but not yet proven) that this algorithm will terminate at n = 1 for every integer n.Still,the conjecture holds for all integers up to at least 1,000,000.For an input n,the cycle-length of n is the number of numbers generated up to and including the 1.In the example above,the cycle length of 22 is 16.Given any two numbers i and j,you are to determine the maximum cycle length over all numbers between i and j,including both endpoints.
Input
The input will consist of a series of pairs of integers i and j,one pair of integers per line.All integers will be less than 1,000,000 and greater than 0.
Output
For each pair of input integers i and j,output i,j in the same order in which they appeared in the input and then the maximum cycle length for integers between and including i and j.These three numbers should be separated by one space,with all three numbers on one line and with one line of output for each line of input.
Sample Input
1 10
100 200
201 210
900 1000
Sample Output
1 10 20
100 200 125
201 210 89
900 1000 174
我的代碼:
#include
int main()
{
long i,j,k,s,t,max,m;
while(scanf("%ld%ld",&i,&j))
{
max=0;
for(k=i;kmax)
{
max=s;
}
}
printf("%ld %ld %ld\n",i,j,max);
}
return 0;
}
其他人氣:690 ℃時間:2020-06-25 19:39:04
優(yōu)質(zhì)解答
#includeint main(){long i,j,k,s,t,max,m;while(scanf("%ld%ld",&i,&j)==2) // 防止Output Limit Exceed{printf("%ld %ld ",i,j); // 先把 i 和 j 輸出if(i>j){max = i;i=j;j=max;} // 如果 i 大于 j,交換他們的位...
我來回答
類似推薦
- 這是為什么?Output Limit
- 一道c語言題,老是Output Limit Exceed,不知為何,
- 某人用392牛的力豎直向上提質(zhì)量為30千克的物體,他能否提起?物體受到的合力是多大?方向如何?
- 英語翻譯
- (X 3)的平方-X平方=39如何解
- 占地面積943.9千平方米等于多少畝
- over the two days .over two days 和in over two
- 小數(shù)和整數(shù)的意義相同嗎?
- 從視覺,聽覺,嗅覺,味覺角度描寫春天景物的詩句
- 請問1/(x^1/2)怎么算
- 取一粒浸軟的小麥種子,穿在鐵絲上,放到火上燒.種子燃燒后,剩下的灰燼與燒掉的物質(zhì)分別
- 鼻子塞住了,這會影響英語發(fā)音嗎?
猜你喜歡
- 1You are the love of my life 中文意思
- 2小學(xué)六年級英語考卷的題目,急!
- 3袋中裝的球,除去兩個以外都是紅色,除去兩個以外都是黃色球,除去兩個以外都是藍(lán)色球,請問袋中共裝有幾個球?
- 4青山水泥廠要把一批水泥運(yùn)到碼頭,用本廠的一輛貨車來運(yùn)需10才能運(yùn)完;如果用運(yùn)輸公司的一輛大貨車來運(yùn)只需5次就能運(yùn)完.現(xiàn)由本廠的一輛貨車運(yùn)送了4次,剩下部分由本廠一輛貨車和運(yùn)輸公司的一輛大貨車共同運(yùn)送,問剩下的需要幾次才能運(yùn)完(要算式)
- 5∫dx/(sinx+cosx)
- 6請教關(guān)于泰語的發(fā)音問題
- 7有關(guān)當(dāng)幸福來敲門的英文介紹
- 8小明的臥室經(jīng)測量長是3米,寬是5米,高是2.8米,其中門窗所占的面積是6平方米求粉刷臥室的面積
- 9歌頌父母之愛的名言警句
- 10下列生活里常見現(xiàn)象中,一定涉及化學(xué)變化的是( ?。?A.冰雪融化 B.冰箱中放入活性炭后,異味消失 C.點(diǎn)燃酒精加熱火鍋 D.榨取果汁
- 11下面的小動物分別代表哪個數(shù)字?
- 12工字開頭的成語