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

通过的代码,看吧,很简单

Posted by hahaxiao at 2005-09-03 09:08:00 on Problem 1032
#include <iostream>
using namespace std;
int main() {
	int a[1001];
	int n;
	int i,j;
	int sum,r;
	while(cin>>n) {
		sum=0;
		i=2; sum+=i;
		while(sum<=n) {
			a[i]=i;
			++i;
			sum+=i;
		}
		sum=sum-i;
		--i;
		r=i;
		if(sum==n){
			cout<<a[2];
			for(i=3;i<=r;i++)
				cout<<' '<<a[i];
		}
		else {
			for(i=2;i<=r;i++)
				if(a[i]+n-sum>a[r]){
					a[++r]=a[i]+n-sum;
					j=i;
					break;
				}
			if(j==2) {
				cout<<a[3];
				for(i=4;i<=r;i++)
					cout<<' '<<a[i];
				cout<<endl;
			}
			else {
				cout<<a[2];
				for(i=3;i<j;i++)
					cout<<' '<<a[i];
				for(i=j+1;i<=r;i++)
					cout<<' '<<a[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