1032 Parliament

 拆成从2开始的递增数列,余下的部分倒回去加2轮,证明比较多,可以看此题的Discuss

  1. //4540529_AC_47MS_424K
  2. /**********************************************************************
  3. *       Online Judge   : POJ
  4. *       Problem Title  : Parliament
  5. *       ID             : 1032
  6. *       Date           : 1/7/2009
  7. *       Time           : 22:27:43
  8. *       Computer Name  : EVERLASTING-PC
  9. ***********************************************************************/
  10. #include<iostream>
  11. using namespace std;
  12. int n,l,k;
  13. int main()
  14. {
  15. //  freopen("in_1032.txt","r",stdin);
  16.     while (cin>>n)
  17.     {
  18.         l=n;
  19.         k=2;
  20.         while (1)
  21.         {
  22.             if (l-k<0)
  23.             {
  24.                 break;
  25.             }
  26.             l-=k;
  27.             k++;
  28.         }
  29.         k--;
  30.         for (int i=2;i<k;++i)
  31.         {
  32.             cout<<i+(i>k-l?1:0)<<' ';
  33.         }
  34.         if (k==l)
  35.         {
  36.             cout<<k+2<<endl;
  37.         }
  38.         else
  39.         {
  40.             cout<<k+(l!=0?1:0)<<endl;
  41.         }
  42.     }
  43.     return 0;
  44. }

你可能感兴趣的:(Date)