Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:你的这5点有证明吗?第三点是为什么呀?

Posted by cyforever at 2010-08-19 19:16:09 on Problem 1032
In Reply To:你的这5点有证明吗?第三点是为什么呀? Posted by:knuthocean at 2005-03-27 11:38:06
有点复杂,我自己写了前几个,发现一点规律。
5 2 3
6 2 4
7  3 4
8  3 5

9 2 3 4
10 2 3 5
11 2  4 5
12 3 4  5
13 3 4 6


14 2 3 4 5
规律自己发现,只好意会,不可言传。代码如下:
#include <iostream>

using namespace std;

int main()
{
   int n,i,s,num,j;

   scanf("%d",&n);
   s=0;i=1;
   while(n>s)
   {
        i++;
        s+=i;
   }
   if(n==s)
   {
       for(j=2;j<=i;j++)
       printf("%d ",j);
       printf("\n");
   }
   else{
   s=s-i;
   i--;
   num=n-s;
   for(j=2;j<=i;j++)
   {
      if(i-j+1<=num%(i-1)) printf("%d ",j+num/(i-1)+1);
      else printf("%d ",j+num/(i-1));
   }
   printf("\n");
   }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator