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 |
记录一下。#include <iostream> using namespace std; int GetLeftNum(int index,int s[],bool vis[]); int main() { int N; cin>>N; while(N--) { int num; cin>>num; int *P = new int[num]; //int *W = new int[num]; for(int i = 0;i<num;++i) cin>>P[i]; int *str = new int[num + P[num - 1]]; //即为括号串的长度 bool *vis = new bool[num + P[num - 1]]; //辅助访问数组 for(int i = 0;i<num + P[num - 1];++i) //初始化数组 { str[i] = 0; vis[i] = false; } for(int i = 0;i<num;++i) { str[i + P[i]] = 1; //该位置为右括号1 cout<<GetLeftNum(i+P[i]-1,str,vis)<<" "; } cout<<endl; } return 0; } int GetLeftNum(int index,int s[],bool vis[]) { int count = 0; for(;index>=0;index--) { if(s[index] == 0) { count++; if(!vis[index]) { vis[index] = true; break; } } } return count; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator