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写的,数据都 过了,就是WA!后来用queue改写了,就AC!奇怪!!!!

Posted by paul08colin at 2011-02-24 16:31:43 on Problem 3032 and last updated at 2011-02-24 16:32:59
list的代码如下:求解!
#include <iostream>
#include <cstdio>
#include <list>
#include <algorithm>
using namespace std;
struct node
{
  int initial;
  int current;
};
bool cmp(const node &a,const node &b)
{
  return a.initial<b.initial? true:false;
}
int main()
{
  int t;
  int n;
  int i;
  node nod;
  node mynode;
  node array[14];
  int j;
  scanf("%d",&t);
  while(t--)
    {
        int temp=0;
      list<node> mylist;
      list<node>::iterator it;
      scanf("%d",&n);
      if(n==0)
	{
	  printf("0\n");
	  continue;
	}

      for(i=1;i<=n;i++)
	{

     	  nod.initial=i;
	  nod.current=0;
	  mylist.push_back(nod);
	}

      for(i=1;;i++)
	{

	  for(j=1;j<=i;j++)
	    {
	      it=mylist.begin();
	      mynode=(*it);
	      mylist.erase(mylist.begin());
	      mylist.push_back(mynode);
	      
	    }
	  
	  it=mylist.begin();
	  mylist.erase(mylist.begin());
	  array[temp]=*it;
	  array[temp].current=temp+1;
	  temp++;
	  if(temp==n)
	    {
	      break;
	    }
	  it=mylist.begin();

		  
		  
	}
      sort(&array[0],&array[temp],cmp);
      for(i=0;i<temp;i++)
	{
	  printf("%d",array[i].current);
	  if(i!=temp-1)
	    {
	      printf(" ");
	    }    
	}
      printf("\n");
      
    }
  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