Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
代妈。。。竟然搞了一次OLE如果scanf后面不加上>0就会OLE #include <iostream> #include <stdio.h> using namespace std; int state[10001] = {0}; int js(int N){ int n = N; if(state[n] > 0) return state[n]; int cnt = 0; while(1){ if(n%2 == 0) n /= 2; else n = 3*n+1; cnt++; if(n <= 10000 && state[n] > 0) { state[N] = cnt+state[n]; return cnt+state[n]; } } } int main() { int s, e; state[1] = 1; while(scanf("%d%d", &s, &e) > 0){ int start, end; if(s == 0 && e == 0) return 0; if(s <= e) { start = s; end = e; } else{ start = e; end = s; } int mx = 0; for(int i = start; i <= end; i++){ int ans = js(i); if(mx < ans) mx = ans; } printf("%d %d %d\n", s, e, mx); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator