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,贴代码纪念一下#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator