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
欢迎报名第四届北京大学游戏对抗邀请赛!

记录一下。

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:

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