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<string> using namespace std; string ss; int n; int p[25]; bool used[50]; void addleft(int x) { for(int count=0;count<x;count++) { ss+='('; } } void addright() { ss+=')'; } void getss() { for(int count=0;count<n;count++) { if(count==0) {addleft(p[0]);addright();} else{addleft(p[count]-p[count-1]);addright();} } } int match(int x) { for(int count=x-1;count>=0;count--) { if(used[count]==false&&ss[count]=='(') { used[count]=true; used[x]=true; return (x-count+1)/2; } } return 0; } void slove() { int first=0; for(int count=0;count<ss.length();count++) { if(ss[count]==')') {if(first!=0) cout<<" ";cout<<match(count);first++;}//可能不需要 } } int main() { int testnumber; cin>>testnumber; for(int count=1;count<=testnumber;count++) { cin>>n; ss.erase(); memset(p,0,sizeof(p)); memset(used,false,sizeof(used)); for(int count2=0;count2<n;count2++) { cin>>p[count2]; } getss(); if(count!=1) cout<<endl;//可能不需要 slove(); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator