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

虽然最后发现看错题了,但还是发一下错误的代码纪念一下

Posted by zsasuke at 2008-11-06 13:41:39 on Problem 2161
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>
using namespace std;
char ch[10001];
class ty
{public:
	int level,count;
	ty *left,*right;
	ty()
	{
		count=level=0;
		left=right=0;
	}
	void resize()
	{
		if(level>1)
		{
		   int *e=new int [level];
		   e[0]=left->count;
		   e[1]=left->right->count;
		   int k=2,i,j;
		   ty *ps,*o=left->right->right,*df;
		  
		   while(o)
		   {
			   e[k]=o->count;
			   k++;
			   o=o->right;
		   }
		   sort(e,e+level,greater<int>());
		   for(i=0;i<level;i++)
		   { 
			   if(i==0)
		       ps=left;
		     else
				 ps=ps->right;
			   for(j=i;j<level;j++)
			   {
				   if(i==j)
					   o=ps;
				   else
					   o=o->right;
				   if(o->count==e[i])
				   {
					   if(o!=ps)
					   {
						   df=ps->left;
						   ps->left=o->left;
						   o->left=df;
						   o->count=ps->count;
						   ps->count=e[i];
						   int u=ps->level;
						   ps->level=o->level;
						   o->level=u;

					   }
					   break;
				   }
			   }

		   }

						   



		   for(i=0;i<level;i++)
			   e[i]+=i;
		   count=*max_element(e,e+level);
		   delete []e;
		}
		else if(level==1)
			count=left->count;
	}

		



};
void output(ty *o)
{
	if(o->level==0)
	printf("%c",'a');
	else if(o->level<0)
		{
			for(int i=0;i<o->count;i++)
				printf("%c",'a');
			printf("%d",o->count);
		}
		else
		{
		  ty *r=o->left;
		  while(r)
		  {
		  output(r);
		  r=r->right;
		  }
		  cout<<o->count;
		}
}
ty data[10001],*ee,*u;
vector<ty *> tree;
int main()
{
scanf("%s",ch);
	int i=0,j,l,k,p,f,a,b;
	int s=strlen(ch);
	while(i<s)
	{   j=i;
		while(ch[i]=='a')
		{	
		    data[i].level=0;
			data[i].count=1;
           i++;
		}
		l=i-j;
		if(l>=ch[i]-'0')
		{ k=l;
			k-=(ch[i]-'0');
			
				for(p=j;p<j+k;p++)
					tree.push_back(&data[p]);
				
					ee=new ty;
				ee->level=-(ch[i]-'0');
				ee->count=(ch[i]-'0');
				ee->left=&data[p];
				tree.push_back(ee);
				
		}
		else
		{  l=(ch[i]-'0');
		  k=j;
		   for(;k<i;k++)
			   tree.push_back(&data[k]);
			f=tree.size()-l;
			ee=new ty;
			ee->level=l;
			ee->left=tree[f];
			a=f;
		
			for(b=1;b<l;b++)
			{	tree[a]->right=tree[a+1];
			a++;
			}
			ee->resize();
			tree.erase(tree.begin()+f,tree.end());
			
			tree.push_back(ee);
			
		}
		i++;
	}
	cout<<tree[0]->count<<endl;
	output(tree[0]);
	cout<<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