| ||||||||||
| 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 | |||||||||
一次AC,用数据结构的循环静态链表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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator