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

STL list 好用

Posted by dynamic_study at 2009-08-12 10:35:39 on Problem 3125 and last updated at 2009-08-12 10:36:19
#include<iostream>
#include<list>
using namespace std;
struct node
{
	int data;
	int no;
};
list<node>L;
list<node>::iterator iter;
int main()
{
	int n,i,location,ans,flag,t;
	node a,temp;
	cin>>t;
	while(t--)
	{
	while(!L.empty())
		L.pop_front();
	cin>>n>>location;
	for(i=0;i<n;i++)
	{
		cin>>a.data;
		if(i==location)
		    a.no=1;
		else
			a.no=0;
		L.push_back(a);
	}
	ans=0;
	while(!L.empty())
	{
	    flag=0;
	    temp=L.front();
	    for(iter=L.begin();iter!=L.end();++iter)
		{
		    if(iter->data>(temp.data))
			{     flag=1;
			      L.pop_front();
		          L.push_back(temp);
				 // cout<<"temp  "<<temp.data<<" "<<temp.no<<endl;
				  break;
			}
		}
	     if(flag==0)
		 {
			 //cout<<L.front().data<<"  "<<L.front().no<<endl;
			if(L.front().no==1)
				break;
			
			L.pop_front();
		
		    ans++;
		 }
	}
	cout<<ans+1<<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