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

我的MEMORY超出了70多K,郁闷~~~怎么改呢?哪位HELP一下下

Posted by Azaza at 2005-08-16 21:55:20 on Problem 1012
#include<iostream>
using namespace std;

typedef struct node{
	int data;
	struct node *next;
}*LinkedList;
int k;

LinkedList l;

LinkedList InitList(int k)
 {
	LinkedList head,p;
	head=(LinkedList)malloc(sizeof(node));
	head->next=head;
	head->data=1;
	for(int i=1;i<k;i++)
	{
		p=(LinkedList)malloc(sizeof(node));
		p->data=i+1;
		p->next=head->next;
		head->next=p;
		head=head->next;
	}
	return(head->next);
}
/*void DestroyList()
{
	LinkedList p=l,q;
	while (p->next!=NULL)
	{
		q=p->next;
		p->next=p->next->next;
		delete q;
	}
	l = NULL;
}*/
int del(int i,int k)
{
	LinkedList p=l,q;
	for(int num=2*k;num>k;num--)
	{
		for(int j=1;j<i-1;j++)
			p=p->next;
		if(p->next->data<=k)
		{
	//		DestroyList();
			return 1;
		}
		else 
		{
			q=p->next;
			p->next=p->next->next;
			p=p->next;
			free(q);
		}
	}
	return 0;
}
void main()
{
	while(cin>>k&&k!=0)
	{
		for(int i=k+1;;i++)
		{
			l=InitList(2*k);
			if(del(i,k)==0)
				break;
		}
		cout<<i<<endl;
	}
}

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