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

我是这么做了,但是wa~~~

Posted by guruqu at 2005-10-31 20:16:09 on Problem 2698
In Reply To:在某个状态,取出下次访问时间最晚的元素,替换 Posted by:zymx at 2005-10-30 16:54:46
#include <iostream>
using namespace std;

int indrive[10];
int disc[101];
int next[101];

int main()
{
	freopen("in.txt","r",stdin);
	int T;
	cin>>T;
	while(T--)
	{
		int n,m;
		cin>>n>>m;
		memset(indrive,-1,sizeof(indrive));
		memset(next,-1,sizeof(next));
		int i,j,ins=0;
		for(i=0;i<m;i++)
		{ 
			cin>>disc[i];
			if(disc[i]<0)
				while(1);
			for(j=i-1;j>=0;j--){
				if(disc[j]==disc[i]){
					next[j]=i;
					break;
				}
			}
		}
		
		for(i=0;i<m;i++)
		{
			int flg=1;

			for(j=0;j<n;j++)
			{
				if(indrive[j]==-1)
				{
					flg=0;
					indrive[j]=i;
					ins++;
					break;
				}
				if(disc[indrive[j]]==disc[i]){
					flg=0;
					break;
				}			
			}
			if(flg==0)  
				continue;
			int mid=-1,mv=0;
			for(j=0;j<n;j++)
			{
				if(mid==-1||next[indrive[j]]>mv||next[indrive[j]]==-1){
					mid=j;
					mv=next[indrive[j]];					
					if(mv==-1)
						break;
				}
			}
			indrive[mid]=i;
			ins++;
		}
		cout<<ins<<endl;
	}
	return 0;
}

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