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

0ms飘过 模拟过程就行 附上代码和模拟出来的字符数组

Posted by jwy1111 at 2018-08-22 23:01:01 on Problem 1068
#include<cstdio>
#include<iostream>
#include<stack>
#include<cstring>
using namespace std;
int a[100];
char b[100];
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;	
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		a[0]=0;
		int tot=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=a[i]-a[i-1];j++){
				b[++tot]='(';
			}
			tot++;
			b[tot]=')';
		}
	/*	for(int i=1;i<=tot;i++){
			printf("%c ",b[i]);
		}*/
	//	printf("\n");
		stack<char>s;
		int book[100];
		memset(book,0,sizeof(book));
		for(int i=1;i<=tot;i++){
			if(b[i]==')'){
				int m=i;
				int tot=0;
				while(b[m]!='('||book[m]){
					m--;
					if(b[m]==')')
					tot++;
				}
				book[m]=1;
				printf("%d ",i-m-tot);
			}
		}	
		printf("\n");
	}
} 

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