Time Limit: 2 Seconds Memory Limit: 131072 KB Special Judge
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)
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.
猜测答案最多是三个数,打表暴力,使用map映射
/*AC*/
#include <stdio.h>
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 123456789;
int a[20000];
map<int, int> m;
int n, maxi;
bool solve1() {
if (m[n]) {
printf("%d\n", m[n]);
return true;
}
else
return false;
}
bool solve2() {
for (int i = 1; i <= maxi; i++) {
int b = m[n - a[i]];
if (b) {
printf("%d %d\n", i, b);
return true;
}
}
return false;
}
bool solve3() {
for (int i = 1; i <= maxi; i++)
for (int j = i; j <= maxi; j++) {
int c = m[n - a[i] - a[j]];
if (c) {
printf("%d %d %d\n", i, j, c);
return true;
}
}
return false;
}
int main() {
int i = 1, s = 1;
while (s <= maxn) {
a[i] = s;
m[s] = i;
i++;
s += i;
}
maxi = i - 1;
int T;
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
if (solve1())
continue;
if (solve2())
continue;
if (solve3())
continue;
}
return 0;
}