暴力有问题
  • 板块学术版
  • 楼主AndyC
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/10/17 12:09
  • 上次更新2023/10/27 07:09:32
查看原帖
暴力有问题
366430
AndyC楼主2022/10/17 12:09

P7915 正解会写 想写一个暴力 但是一直卡死 求助dalao

#include<bits/stdc++.h>
using namespace std;
int n;
deque<int> da,db;
deque<int> a,b; 
int save[1005];
bool ok;
bool ceck(deque<int> qq){
	while(!qq.empty()){
		if(qq.front()!=qq.back()){
			return false;
		}
		qq.pop_front();
		qq.pop_back();
	}
	return true;
}
int tot=0;
// a's front to b's end    del from a
// a's end to b's end      del from a
void dfs(){
	if(ceck(b)==true){
		ok=true;
		return;
	}
	if(a.empty()||b.empty()) return;
	
	int k;
	k=a.front();
	b.push_back(k);
	a.pop_front();
	dfs();
	if(ok==true){
		save[++tot]=1;
		return ;
	}
	a.push_front(k);
	
	k=a.back();
	b.push_back(k);
	a.pop_back();
	dfs();
	if(ok==true){
		save[++tot]=2;
		return ;
	}
	a.push_back(k);
}
int main(){
	int T;
	cin>>T;
	while(T--){
		tot=0;
		ok=false;
		while(!da.empty()) da.pop_back();
		while(!db.empty()) db.pop_back();
		cin>>n;
		int x;
		for(int i=1;i<=n/2;i++){
			cin>>x;
			a.push_back(x); 
		}
		for(int i=1;i<=n/2;i++){
			cin>>x;
			b.push_back(x); 
		}
		dfs();
		if(ok==false){
			cout<<-1<<endl;
		}
		else{
			for(int i=tot;i>=1;i--){
				
				if(save[i]==1){
					cout<<'L';
				}
				else cout<<'R';
			}
		}
	} 
	return 0;
}
2022/10/17 12:09
加载中...