【BFS】Ball Aizu - 0033 原题正解 DFS

RT ORZ
硬生生 写成bfs

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
using namespace std;

int a[15];
//int b[15];
int n;

struct node {
	int cnt;
	int pos1,pos2;
	int an[15];
	int bn[15];
}ball,tmp,t;

bool bfs(){
	queue<node> q;
	ball.an[0]=a[0];
	ball.pos1=0;
	ball.pos2=0;
	ball.cnt=0;
	q.push(ball);
	while(!q.empty()){
		tmp=q.front();
		int f=1;
		if(tmp.an[tmp.pos1]<a[tmp.cnt+1]){
			tmp.an[tmp.pos1+1]=a[tmp.cnt+1];
			tmp.pos1++;
			tmp.cnt++;
			q.push(tmp);
			f=0;
		}
		tmp=q.front();
		if(tmp.pos2==0||tmp.bn[tmp.pos2]<a[tmp.cnt+1]){
			tmp.bn[tmp.pos2+1]=a[tmp.cnt+1];
			tmp.pos2++,tmp.cnt++;
			q.push(tmp);
			f=0;
		}
		/*
		for(int i=0;i<q.front().pos1;i++){
			cout<<q.front().an[i]<<"  ";
		}cout<<endl;
		for(int i=0;i<q.front().pos2;i++){
			cout<<q.front().bn[i]<<"  ";
		}cout<<endl;
		cout<<"   "<<tmp.cnt<<endl;
		q.pop();
	//	if(f) return 0;
	*/
	q.pop();
		if(tmp.cnt==9) return 1;
	}
	return 0;
} 

int main(){
	while(cin>>n){
		while(n--){
			ball.pos1=0,ball.pos2=0,ball.cnt=0,ball.bn[0]=0;
			for(int i=0;i<10;i++) cin>>a[i];
			if(bfs()) cout<<"YES\n";
			else cout<<"NO\n";
		}
	//	
	}
	return 0;
}

无力orz

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值