原题:
Set Definition
Description
Set S is defined as follows:
(1) 1 is in S; (2) If x is in S, then 2x + 1 and 3x + 1 are also in S; (3) No other element belongs to S. Find the N-th element of set S, if we sort the elements in S by increasing order. Input
Input will contain several test cases; each contains a single positive integer N (1 <= N <= 10000000), which has been described above.
Output
For each test case, output the corresponding element in S.
Sample Input 100 254 Sample Output 418 1461 分析: 又是一道简单题, 我用的是打表的方法,将答案存在一个数组a 中. 在计算时用 i 和 j 分别记录下一个2*x + 1 和3*x + 1 的x 的下标, 比较2*x + 1 和3*x + 1 的大小, 小的存入a 数组, 这样a 数组中的数就已经从大到小排好序了. 最后根据输入只要输出答案就可以了! 参考代码: //2591 a[k] = min(t1,t2); while(cin>>n) system("pause"); 我用了157MS,看到有的高手30MS, 请到访的高手赐教,谢谢! |