【DFS】HDU 1364 POJ 1071 Illusive Chase
生活随笔
收集整理的這篇文章主要介紹了
【DFS】HDU 1364 POJ 1071 Illusive Chase
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
數據水了。。。
不知道正解是什么
將TOM放在一個0上經過輸入的 ?1 2 R 這樣走 還能在圖上則這個點可行(走的過程中不能走出圖)
求有幾個0 可行
直接dfs 完全沒有別的思路
題目要求必須 走 A - B 步 所以在走A步不能遇到 1?
?
#include <cstdio> #include <cstdlib> #include <cstring> #include <climits> #include <cctype> #include <cmath> #include <string> #include <sstream> #include <iostream> #include <algorithm> #include <iomanip> using namespace std; #include <queue> #include <stack> #include <vector> #include <deque> #include <set> #include <map> typedef long long LL; #pragma comment(linker, "/STACK:1024000000,1024000000") #define pi acos(-1.0) #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 typedef pair<int, int> PI; typedef pair<int, PI> PP; #ifdef _WIN32 #define LLD "%I64d" #else #define LLD "%lld" #endif //LL quick(LL a, LL b){LL ans=1;while(b){if(b & 1)ans*=a;a=a*a;b>>=1;}return ans;} inline int read() {char ch=' ';int ans=0;while(ch<'0' || ch>'9')ch=getchar();while(ch<='9' && ch>='0'){ans=ans*10+ch-'0';ch=getchar();}return ans; } //inline void print(LL x){printf(LLD, x);puts("");} bool mp[105][105]; PP step[1005]; int d, m, n; bool solve(int r, int c,int x) {if(r>=m || c>=n)return false;if(r<0 || c<0)return false;if(x==d)if(!mp[r][c])return true;else return false;int a=step[x].second.first;int b=step[x].second.second;//bool flag=0;if(step[x].first==0){for(int i=c-1; i>=c-a; i--){if(i<0)return false;if(mp[r][i])return false;}for(int i=c-a; i>=c-b; i--){if(solve(r,i,x+1))return true;}}if(step[x].first==1){for(int i=c+1; i<=c+a; i++){if(i>=n)return false;if(mp[r][i])return false;}for(int i=c+a; i<=c+b; i++){if(solve(r,i,x+1))return true;}}if(step[x].first==2){for(int i=r-1; i>=r-a; i--){if(i<0)return false;if(mp[i][c])return false;}for(int i=r-a; i>=r-b; i--){if(solve(i,c,x+1))return true;}}if(step[x].first==3){for(int i=r+1; i<=r+a; i++){if(i>=m)return false;if(mp[i][c])return false;}for(int i=r+a; i<=r+b; i++){if(solve(i,c,x+1))return true;}}return false; } int main() { #ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout); #endifint t=read();while(t--){m=read(), n=read();for(int i=0; i<m; i++)for(int j=0; j<n; j++)mp[i][j]=read();d=0;while(true){int a=read(), b=read();if(a==0 && b==0)break;char op[2];int c;scanf("%s", op);if(op[0]=='L')c=0;else if(op[0]=='R')c=1;else if(op[0]=='U')c=2;else if(op[0]=='D')c=3;step[d++]=make_pair(c, make_pair(a, b));}int ans=0;for(int i=0; i<m; i++)for(int j=0; j<n; j++)if(!mp[i][j])if(solve(i, j,0))ans++;printf("%d\n", ans);}return 0; }轉載于:https://www.cnblogs.com/kewowlo/p/4088355.html
總結
以上是生活随笔為你收集整理的【DFS】HDU 1364 POJ 1071 Illusive Chase的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 什么是视频数据结构化?
- 下一篇: iOS 5.1.1 设备不能安装AdHo