Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:通过的代码,看吧,很简单In Reply To:通过的代码,看吧,很简单 Posted by:hahaxiao at 2005-09-03 09:08:00 如果你真的有什么心得,可以用几条语句或几条代码表示出来,贴出整个代码不太好 > #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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator