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 kfq at 2013-12-26 17:12:39 on Problem 1068
#include <iostream>
#include <cmath>
#include <cstring>

using namespace std;
int main()
{
	int t,n;
	int P[25],S[100],W[50],str[50];
	cin>>t;
	while(t-->0)
	{
		memset(S,0, sizeof(S));
		cin>>n;
		for(int i=0;i<n;i++)
		{
			cin>>P[i];
		}
		S[P[0]]=-1;
		str[0]=P[0];
		for(int i=1;i<n;i++)
		{
			if(P[i]-P[i-1]!=0)
			{
				str[i]=str[i-1]+P[i]-P[i-1]+1;
				S[str[i]]=-1;	
			}
			else if(P[i]-P[i-1]==0)
			{
				str[i]=str[i-1]+1;
				S[str[i]]=-1;
			}
		}
		int m=0;
		for(int i=1;i<n*2;i++)
		{			
			if(S[i]==-1)
			{
				int j;
				for(j=i-1;j>=0;j--)
				{
					if(S[j]==0)
					{	
						S[j]=1;
						S[i]=1;
						break;
					}
				}
				W[m++]=(i-j+1)/2;
			}
			
		}
		for(int i=0;i<m;i++)
		{
			cout<<W[i]<<" ";
		}
		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