栽萝卜

栽好多好多萝卜,留着吃

导航

POJ 1032

题目蛮简单。写几组数据便可想出算法。

代码:

 

1 #include <iostream>
2 #include <vector>
3  using namespace std;
4
5  int main()
6 {
7 int N;
8 while (cin>>N)
9 {
10 vector<int> size;
11 int x(2),sum(0),k,y;
12 for ( ; sum+x<=N; sum+=x,++x)
13 {
14 size.push_back(x);
15 }
16 k = N-sum;
17 y = (int)size.size();
18 while (k--)
19 {
20 size[y-1]++;
21 y--;
22 if(!y) y = (int)size.size();
23 }
24 for (size_t i=0;i<size.size();++i)
25 {
26 cout<<size[i]<<' ';
27 }
28 }
29 }

 

posted on 2011-01-13 22:15  海飞丝叔叔  阅读(248)  评论(0编辑  收藏  举报