hdu 4634 Swipe Bo

m写成了n。。。尼玛,wa死我了

#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
#include<ctime>
using namespace std;
#ifdef _WIN32
typedef __int64 i64;
#define out64 "%I64d\n"
#define in64 "%I64d"
#else
typedef long long i64;
#define out64 "%lld\n"
#define in64 "%lld"
#endif
/************ for topcoder by zz1215 *******************/
#define foreach(c,itr)  for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define FOR(i,a,b)      for( int i = (a) ; i <= (b) ; i ++)
#define FF(i,a)         for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a,b)      for( int i = (a) ; i >= (b) ; i --)
#define S64(a)          scanf(in64,&a)
#define SS(a)           scanf("%d",&a)
#define LL(a)           ((a)<<1)
#define RR(a)           (((a)<<1)+1)
#define pb              push_back
#define pf              push_front
#define X               first
#define Y               second
#define CL(Q)           while(!Q.empty())Q.pop()
#define MM(name,what)   memset(name,what,sizeof(name))
#define MC(a,b)		memcpy(a,b,sizeof(b))
#define MAX(a,b)        ((a)>(b)?(a):(b))
#define MIN(a,b)        ((a)<(b)?(a):(b))
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)

const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
const int maxn = 211;

int n, m;
char s[maxn][maxn];

int go[4][2] = { { 0, -1 }, { -1, 0 }, { 1, 0 }, { 0, 1 } };
int key;
int sx, sy;
int ex, ey;

struct zz{
	int x, y, hash;

	bool operator < (const zz& cmp)  const{
		if (x != cmp.x) return x<cmp.x;
		else if (y != cmp.y) return y<cmp.y;
		else return hash<cmp.hash;
	}

	bool operator == (const zz&cmp){
		return x == cmp.x && y == cmp.y && hash == cmp.hash;
	}
};

map<zz, int>mp;

void gao(){
	char c = '1';
	key = 0;
	int temp = 0;
	for (int x = 1; x <= n; x++){
		for (int y = 1; y <= m; y++){
			if (s[x][y] == 'K'){
				s[x][y] = c++;
				key |= 1 << temp;
				temp++;
			}

			if (s[x][y] == 'S'){
				sx = x;
				sy = y;
			}

			if (s[x][y] == 'E'){
				ex = x;
				ey = y;
			}
		}
	}
}

bool yes(zz now){
	return now.x <= n && now.x >= 1 && now.y <= m && now.y >= 1;
}

int get(char c)
{
    if( c == 'L'){
        return 0;
    }
    else if(c == 'U'){
        return 1;
    }
    else if(c == 'D'){
        return 2;
    }
    else if(c == 'R'){
        return 3;
    }else return -1;
}

set<zz>pass;

zz next(zz now,int d)
{
    zz to = now;
    int tx;
    for(int step=1;;step++){
        to.x += go[d][0];
        to.y += go[d][1];
        if(!yes(to)){
            return to;
        }
        if(s[to.x][to.y] == '#'){
            to.x -= go[d][0];
            to.y -= go[d][1];
            if(to == now){
                to.x=-1;
                return to;
            }
            else{
                return to;
            }
        }
        else if(s[to.x][to.y]>='1' && s[to.x][to.y]<='9'){
            tx = s[to.x][to.y] - '1';
            to.hash |= (1<<tx);
        }
        else if(s[to.x][to.y] == 'E'){
            if(to.hash == key){
                return to;
            }
        }
        else if(get(s[to.x][to.y])!=-1){
            int dx = get(s[to.x][to.y]);
            if(pass.find(to) != pass.end()){
                to.x = -1;
                return to;
            }
            else{
                pass.insert(to);;
                return next(to,dx);
            }
        }
    }
}

void spfa()
{
	queue<zz>q;
	zz now, to;
	now.x = sx;
	now.y = sy;
	now.hash = 0;
	mp.clear();
	mp[now] = 0;
	q.push(now);

	int temp;
	while (!q.empty()){
		now = q.front();
		q.pop();
		for (int i = 0; i < 4; i++){
			pass.clear();
			to = next(now, i);
			if (yes(to)){
				temp = mp[now] + 1;
				if (mp.find(to) == mp.end()){
					mp[to] = temp;
					q.push(to);
				}
			}
		}
	}
}

void start()
{
	gao();
	spfa();
    return ;
}

int main()
{
	while (cin >> n >> m){
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= m; j++){
				cin >> s[i][j];
			}
		}

		start();
		zz now;
		now.x = ex;
		now.y = ey;
		now.hash = key;
		if (mp.find(now) == mp.end()){
			cout << -1 << endl;
		}
		else{
			cout << mp[now] << endl;
		}
	}
	return 0;
}



基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip 个人大四的毕业设计、课程设计、作业、经导师指导并认可通过的高分设计项目,评审平均分达96.5分。主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。 [资源说明] 不懂运行,下载完可以私聊问,可远程教学 该资源内项目源码是个人的毕设或者课设、作业,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96.5分,放心下载使用! 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),供学习参考。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值