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 |
不知道哪里错了,试过很多数都没有问题,写得有点算乱,真诚至歉。原理和上面讨论的一样,从2开始,产生连续数列,多出的倒向加一。谢谢帮助!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator