日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

机器人搬重物

發布時間:2024/10/5 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 机器人搬重物 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

https://www.luogu.org/problemnew/show/P1126

題解:

1、有可能就是機器人一直打轉RE

2、注意機器人是球形且有直徑,所以機器人不能到達儲藏室的邊緣。

3、注意樣例,一個障礙物直接占滿一個格子,而同樣因為機器人的直徑問題,不能到這些格子的格點上去。

4、在移動時機器人也需要一步一步移動,所以機器人不能跨過障礙物,即遇到障礙物就必須停止。

5、其他的按BFS常規做就行

/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int using namespace std; typedef long long ll; typedef __int128 lll; const int N=50+5; const int MOD=1e9+7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t,n,m,k,s; int sx,sy,fx,fy; char flag; bool a[N][N]; bool vis[N][N][5]; map <char,int>MAP; struct node{int x,y;int flag;int cnt; }f,tmp; int bfs(){queue<node>q;tmp.x=sx;tmp.y=sy;tmp.cnt=0;tmp.flag=MAP[flag];q.push(tmp);vis[sx][sy][tmp.flag]=1;while(!q.empty()){f=q.front();q.pop();if(f.x==fx&&f.y==fy){return f.cnt;}f.cnt++;tmp=f;tmp.flag=f.flag+1;if(tmp.flag>4)tmp.flag-=4;if(!vis[tmp.x][tmp.y][tmp.flag]){vis[tmp.x][tmp.y][tmp.flag]=1;q.push(tmp);}tmp.flag=f.flag-1;if(tmp.flag<1)tmp.flag+=4;if(!vis[tmp.x][tmp.y][tmp.flag]){vis[tmp.x][tmp.y][tmp.flag]=1;q.push(tmp);}//cout << f.x<<f.y <<f.cnt<<f.flag<< endl;tmp=f;if(f.flag==2){//Stmp.x=f.x+1;if(tmp.x<n&&!vis[tmp.x][tmp.y][tmp.flag]){if(!a[tmp.x][tmp.y]){vis[tmp.x][tmp.y][tmp.flag]=1;q.push(tmp);}else{continue;}}tmp.x=f.x+2;if(tmp.x<n&&!vis[tmp.x][tmp.y][tmp.flag]){if(!a[tmp.x][tmp.y]){vis[tmp.x][tmp.y][tmp.flag]=1;q.push(tmp);}else{continue;}}tmp.x=f.x+3;if(tmp.x<n&&!vis[tmp.x][tmp.y][tmp.flag]){if(!a[tmp.x][tmp.y]){vis[tmp.x][tmp.y][tmp.flag]=1;q.push(tmp);}else{continue;}}}else if(f.flag==1){//Etmp.y=f.y+1;if(tmp.y<m&&!vis[tmp.x][tmp.y][tmp.flag]){if(!a[tmp.x][tmp.y]){vis[tmp.x][tmp.y][tmp.flag]=1;q.push(tmp);}else{continue;}}tmp.y=f.y+2;if(tmp.y<m&&!vis[tmp.x][tmp.y][tmp.flag]){if(!a[tmp.x][tmp.y]){vis[tmp.x][tmp.y][tmp.flag]=1;q.push(tmp);}else{continue;}}tmp.y=f.y+3;if(tmp.y<m&&!vis[tmp.x][tmp.y][tmp.flag]){if(!a[tmp.x][tmp.y]){vis[tmp.x][tmp.y][tmp.flag]=1;q.push(tmp);}else{continue;}}}else if(f.flag==4){//Ntmp.x=f.x-1;if(0<tmp.x&&!vis[tmp.x][tmp.y][tmp.flag]){if(!a[tmp.x][tmp.y]){vis[tmp.x][tmp.y][tmp.flag]=1;q.push(tmp);}else{continue;}}tmp.x=f.x-2;if(0<tmp.x&&!vis[tmp.x][tmp.y][tmp.flag]){if(!a[tmp.x][tmp.y]){vis[tmp.x][tmp.y][tmp.flag]=1;q.push(tmp);}else{continue;}}tmp.x=f.x-3;if(0<tmp.x&&!vis[tmp.x][tmp.y][tmp.flag]){if(!a[tmp.x][tmp.y]){vis[tmp.x][tmp.y][tmp.flag]=1;q.push(tmp);}else{continue;}}}else{//Wtmp.y=f.y-1;if(0<tmp.y&&!vis[tmp.x][tmp.y][tmp.flag]){if(!a[tmp.x][tmp.y]){vis[tmp.x][tmp.y][tmp.flag]=1;q.push(tmp);}else{continue;}}tmp.y=f.y-2;if(0<tmp.y&&!vis[tmp.x][tmp.y][tmp.flag]){if(!a[tmp.x][tmp.y]){vis[tmp.x][tmp.y][tmp.flag]=1;q.push(tmp);}else{continue;}}tmp.y=f.y-3;if(0<tmp.y&&!vis[tmp.x][tmp.y][tmp.flag]){if(!a[tmp.x][tmp.y]){vis[tmp.x][tmp.y][tmp.flag]=1;q.push(tmp);}else{continue;}}}}return -1; }int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endif MAP['E']=1;//右 MAP['S']=2;//nanMAP['W']=3;//zuo MAP['N']=4;//upscanf("%d%d",&n,&m);for(int i=0;i<n;i++){for(int j=0;j<m;j++){scanf("%d",&t);if(t){a[i][j]=1;a[i][j+1]=1;a[i+1][j]=1;a[i+1][j+1]=1;}}}for(int i=0;i<=n;i++){a[i][m]=1;a[i][0]=1;}for(int i=0;i<=m;i++){a[0][i]=1;a[n][i]=1;}scanf("%d %d %d %d %c",&sx,&sy,&fx,&fy,&flag); // for(int i=0;i<=n;i++){ // for(int j=0;j<=m;j++){ // printf("%d",a[i][j]); // } // printf("\n"); // }cout << bfs() << endl;//cout << "Hello world!" << endl;return 0; }

?

總結

以上是生活随笔為你收集整理的机器人搬重物的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。