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

一次AC,用数据结构的循环静态链表

Posted by long1897 at 2014-07-31 20:41:47 on Problem 3125
Source Code

Problem: 3125  User: long1897 
Memory: 216K  Time: 0MS 
Language: C++  Result: Accepted 
•Source Code
#include<iostream>
using namespace std;
const int MAX = 100;
int Queue[MAX] = {0};
bool Check(const int &n)                                             //没有更高则返回false,反之返回true
{
	int key = Queue[0];
	for( int i = 1; i < n; i++ )
		if( key < Queue[i] )
			return true;
	return false;
}
void Delete(int &m,int &time,int &n)
{
	for( int i = 1; i < n; i++ )
		Queue[i-1] = Queue[i];
	Queue[n-1] = 0;
	n--;
	time++;
	m--;
}
void Move(const int &n,int &m)
{
	int key = Queue[0];
	for( int i = 1; i < n; i++ )
		Queue[i-1] = Queue[i];
	Queue[n-1] = key;
	if( m == 0 )
		m = n - 1;
	else
		m--;
}
int main()
{
	int t,time,n,m;
	cin>>t;
	while( t != 0 )
	{
		cin>>n>>m;
		time = 0;
		for( int i = 0; i < n; i++ )
			cin>>Queue[i];
		while( m >= 0 )
		{
			if( !Check(n) )
				Delete(m,time,n);
			else
				Move(n,m);
		}
		cout<<time<<endl;
		memset(Queue,0,sizeof(Queue));
		t--;
	}
	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