Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

记录一下。

Posted by 264314 at 2018-10-07 22:24:15 on Problem 1068
```#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: