Buggy Robot (二维压一维最短路
来源:互联网 发布:人工智能取代人类辩论 编辑:程序博客网 时间:2024/06/08 07:55
题意:可以任意删除或添加指令。最后输出修改了多少次指令,如果要撞墙就不走。
#include<bits/stdc++.h>using namespace std;#define pi acos(-1)#define endl '\n'#define rand() srand(time(0));#define me(x) memset(x,0,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0);typedef long long LL;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;const int dx[]={-1,0,1,0,-1,-1,1,1};const int dy[]={0,1,0,-1,1,-1,1,-1};const int maxn=1e4+5;const int maxx=1e6+100;const double EPS=1e-7;const int MOD=10000007;typedef pair<int, int>P;#define mod(x) ((x)%MOD);template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}long long gcd(long long a , long long b){if(b==0) return a;a%=b;return gcd(b,a);}#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define W whilevector<pair<int,int> >E[maxx];int n,m;int d[maxx],inq[maxx];char mapp[55][55],op[55];int check(int x,int y){ if(x>=1&&x<=n&&y>=1&&y<=m&&mapp[x][y]!='#') return 1; return 0;}int main(){ cin>>n>>m; FOR(1,n,i) cin>>mapp[i]+1; cin>>op+1; for(int i=0;i<maxx;i++) { E[i].clear(); inq[i]=0; d[i]=INF; } int st,ed,len=strlen(op+1); FOR(1,n,i) FOR(1,m,j) { if (mapp[i][j] == 'R') st=(i-1)*m+j; if (mapp[i][j] == 'E') ed=(i-1)*m+j; if (mapp[i][j] == '#') continue; FOR(1,len,k) { FOR(0,3,p) { int x=i+dx[p]; int y=j+dy[p]; if(check(x,y)) { int u=((i-1)*m+j)*(len+1)+k; int v=((x-1)*m+y)*(len+1)+k; E[u].push_back(make_pair(v,1)); // cout<<u<<" "<<v<<endl; } } int x = i, y = j; if (op[k] == 'R') y++; else if (op[k] == 'L') y--; else if (op[k] == 'U') x--; else x++; if(check(x,y)) { int u=((i-1)*m+j)*(len+1)+k; int v=((x-1)*m+y)*(len+1)+k+1; E[u].push_back(make_pair(v,0)); } else { int u=((i-1)*m+j)*(len+1)+k; E[u].push_back(make_pair(u+1,0)); } //int u=((i-1)*m+j)*(len+1)+k; // E[u].push_back(make_pair(u+1,1)); FOR(0,3,p) { int x=i+dx[p]; int y=j+dy[p]; if(check(x,y)) { int u=((i-1)*m+j)*(len+1)+len+1; int v=((x-1)*m+y)*(len+1)+len+1; E[u].push_back(make_pair(v,1)); } } } } queue<int >Q; st=st*(len+1)+1; Q.push(st),d[st]=0,inq[st]=1; while(!Q.empty()) { int now=Q.front(); Q.pop(); inq[now]=0; for(int i=0;i<E[now].size();i++) { int v=E[now][i].first; if(d[v]>d[now]+E[now][i].second) { d[v]=d[now]+E[now][i].second; if(inq[v]==1) continue; inq[v]=1; Q.push(v); } } } int ans=INF; FOR(1,len+1,i) { int cur=ed*(len+1)+i; ans=min(ans,d[cur]); } cout<<ans<<endl;}
阅读全文
0 0
- Buggy Robot (二维压一维最短路
- Buggy Robot Gym
- Buggy Robot Gym
- B. Buggy Robot
- CodeForces 888B Buggy Robot
- codeforces 893B. Buggy Robot
- Codeforces 888B Buggy Robot (模拟)
- Educational Codeforces Round 32 B. Buggy Robot(模拟)
- UVA Live 7693 (Codeforces Gym 101201B) Buggy Robot DP+bfs
- 二维最短路
- POJ 3072 Robot (最短路)
- poj 3072 Robot 最短路spfa
- poj 3072 Robot 最短路spfa
- Buggy Sorting
- hdu 4396(spfs/二维最短路)
- 【POJ】1724 ROADS 二维最短路
- CCF 201403-4无线网络 (二维最短路)
- CCF 201403-4无线网络 (二维最短路)
- Activiti初学者教程
- 在线获取键盘按键值(ascii码)工具
- 二叉树的面试题
- JAVA 攻城狮 第十三天
- java NIO (一)
- Buggy Robot (二维压一维最短路
- Cordova基本使用
- 刷题记录-luoguP1631 序列合并
- HDU-5956 The Elder(树型dp+斜率优化)
- 【Java基础】遍历指定目录并且找出包含指定名字的文件
- 把“0”强制转化为结构体指针类型得到成员变量的偏移量
- 双目立体视觉的原理
- JAVA设计模式之单例模式
- Python开发---操作MySQL数据库