⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 4633531_ac_0ms_256k.cpp

📁 部分PKU上的源码
💻 CPP
字号:
#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;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -