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 |
急救 为什么会Memory Limit Exceed#include<iostream> #include<iomanip> using namespace std; struct joseph { int num; joseph * left; joseph * right; }; typedef joseph * ring; void creat(ring & head,int k) { ring pr,p; int i=1; p=new joseph; p->num=1; pr=p; while(i<k*2) { if(head==NULL) head=p; else { i++; p=new joseph; p->num=i; p->left=pr; pr->right=p; pr=p; } } p->right=head; head->left=p; } void del(ring & pr) { ring temp=pr; pr=pr->right; temp->left->right=temp->right; temp->right->left=temp->left; } void main() { int k; cin>>k; while(k!=0) { for(int m=k+1;;m++) { ring head=NULL; creat(head,k); ring p=head; for(int l=1;l<=k;l++) { for(int i=1;i<m;i++) p=p->right; if(p->num >k) del(p); else break; if(l==k) { cout<<m<<endl; goto end; } } } end: cin>>k; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator