您的位置:首页 > 其它

HDOJ 5334 Virtual Participation

2015-07-31 15:56 399 查看
贪心就可以了。。。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int res[100005];
LL K, n;

void solve(int L ,int R, int t)
{
int tt = 1, i, t1 = res[R];
for(i = R-1; i >= L && t > 0; i--) {
if(t < tt) break;
else t -= tt, res[i] = t1;
tt++;
}
if(t == 0) return;
solve(L, i, t);
}

void work()
{
if(K <= 10000) {
printf("%lld\n", K);
for(int i = 1; i <= K; i++) printf("1%c", i == K ? '\n' : ' ');
return;
}

for(n = 0; n * (n + 1) / 2 < K; n++);
for(int i = 1; i <= n; i++) res[i] = i;
LL t = n * (n + 1) / 2 - K;
solve(1, n, t);
printf("%lld\n", n);
for(int i = 1; i <= n; i++) printf("%d%c", res[i], i == n ? '\n' : ' ');
}

int main()
{
while(scanf("%lld", &K) != EOF) {
work();
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: