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

估计是new了太多

Posted by hawk at 2004-05-22 17:03:16 on Problem 1012
In Reply To:急救 为什么会Memory Limit Exceed Posted by:90303121 at 2004-05-22 16:56:07
> #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:
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