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

不知道哪里错了,试过很多数都没有问题,写得有点算乱,真诚至歉。原理和上面讨论的一样,从2开始,产生连续数列,多出的倒向加一。谢谢帮助!

Posted by yxymy at 2009-08-17 13:36:24 on Problem 1032
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;

	if(n==5)
	{
		cout<<2<<" "<<3<<endl;
		return 0;
	}
	int sum=0,arr[500];
	int k=-1;
	for(int i=2;sum+i+1<=n;i++)
	{
		sum=sum+i;
		arr[k+1]=i;
		k++;
	}
	int li=k;               //记住下标
	for(int j=n-sum;j>0;j--)
	{
		arr[k]++;
		k--;
		if(k==-1)
			k=li;
	}

	for(int i=0;i<=li;i++)
		cout<<arr[i]<<" ";
	cout<<endl;
	
	return 0;
}

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