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; }
相关文章推荐
- Android Animation动画(很详细)
- std::thread and std::mutex
- java缓存(1、概述)
- inline函数的作用
- 设计模式 观察者模式
- Javascript高级程序设计读书笔记(第六章)
- 网站HTTP请求过程解析
- Android下最小化程序到后台代码
- 【转】Lua编程规范
- android知识杂记(三)
- 关于update set from where
- 贪心算法之nyoj会场安排问题
- Windows Server 2003升级Win Ser 2008R2之域架构扩展报错
- 数字图像处理06(图像分割)
- 敌兵布阵
- poj 3737 UmBasketella(数学推导||三分)
- camera原理
- Javascript单元测试的基础
- PullToRefresh下拉刷新(内附下载地址)
- 制作蒙板(ios)