zoj 3768 continuous login Two points! Two points!

Pierre is recently obsessed with an online game. To encourage users to log in, this game will give users a continuous login reward. The mechanism of continuous login reward is as follows: If you have not logged in on a certain day, the reward of that day is 0, otherwise the reward is the previous day's plus 1.

On the other hand, Pierre is very fond of the number N. He wants to get exactly N points reward with the least possible interruption of continuous login.


Input

There are multiple test cases. The first line of input is an integer T indicates the number of test cases. For each test case:

There is one integer N (1 <= N <= 123456789).

Output

For each test case, output the days of continuous login, separated by a space.

This problem is special judged so any correct answer will be accepted.

Sample Input
4
20
19
6
9
Sample Output
4 4
3 4 2
3
2 3
Hint

20 = (1 + 2 + 3 + 4) + (1 + 2 + 3 + 4)

19 = (1 + 2 + 3) + (1 + 2 + 3 + 4) + (1 + 2)

6 = (1 + 2 + 3)

9 = (1 + 2) + (1 + 2 + 3)

Some problem has a simple, fast and correct solution.


I didn't say this question, I guessed up to 3 numbers, and spent a long time, because when I searched for 3 numbers, I found but only one break! ! ! ! ! ! There is only one break! ! ! ! ! ! ! ! ! ! ! ! ! ! !
Asi Bar
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <algorithm>
 6 #include <stack>
 7 #include <queue>
 8 #include <map>
 9 #include <set>
10 #include <cmath>
11 #include <cctype>
12 
13 using namespace std;
14 
15 int data[20000];
16 int dnum = 0;
17 
18 void init(){
19     int i;
20     for(i = 1;data[i] < 123456789;i++){
21         data[i] = data[i-1]+i;
22     }
23     dnum = i-1;
24     return;
25 }
26 
27 int lower_erfen(int snum){
28     int l = 1,r = dnum,mid;
29     while(l < r){
30         mid = (l+r)/2;
31         if(data[mid] == snum)
32             return mid;
33         else if(data[mid] < snum){
34             l = mid+1;
35         }
36         else{
37             r = mid-1;
38         }
39     }
40     if(data[l] > snum)
41         l--;
42     return l;
43 }
44 
45 int main(){
46     init();
47     int T,n;
48     scanf("%d",&T);
49     while(T--){
50         scanf("%d",&n);
51         int index1 = lower_erfen(n),index2,index3,cur3,book = 1;
52         if(data[index1] == n){
53             printf("%d\n",index1);
54             continue;
55         }
56         
57         for(int i = index1;i&&2*data[i]>= n;i--){
58             index2 = lower_erfen(n - data[i]);
59             if(data[index2] + data[i] == n){
60                 printf("%d %d\n",index2,i);
61                 book = 0;
62                 break;
63             }
64         }
65         if(book){
66             for(int i = index1;i&&2*data[i]>= n;i--){
67                 if(book == 2)
68                     break;
69                 index2 = lower_erfen(n - data[i]);
70                 for(int j = index2;j >0;j--){
71                     cur3 = n - data[i] - data[j];
72                     index3 = lower_erfen(cur3);
73                     if(data[index3] == cur3){
74                         printf("%d %d %d\n",i,j,index3);
75                         book = 2;
76                         break;
77                     }
78                 }
79             }
80         }
81     } 
82     return 0;
83 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324969072&siteId=291194637