alright
It's a greedy algorithm problem
Use an adjacency list to save the graph,
then find every vertex's successor which has most successors.
2009年12月20日 星期日
2009年12月16日 星期三
ACM 100
AC
Algorithm:
1. use a table cycle[] to store the result from 1~1000000, and go through it to do computation
- cycle[1] = 1
- Let n be the initial value, then n will become x through n = n / 2 or n = 3 * n + 1
- if cycle[x] is not empty, then cycle[n] = cycle[x] + number of computations
Be careful:
The input will consist of a series of pairs of integers i and j, i may bigger than j
Algorithm:
1. use a table cycle[] to store the result from 1~1000000, and go through it to do computation
- cycle[1] = 1
- Let n be the initial value, then n will become x through n = n / 2 or n = 3 * n + 1
- if cycle[x] is not empty, then cycle[n] = cycle[x] + number of computations
Be careful:
The input will consist of a series of pairs of integers i and j, i may bigger than j
訂閱:
文章 (Atom)