搜啊搜~~~~~~~
1.用记忆化搜索 来搜答案,否则搜不完~
2.题目理解起来有困难....sad
讲:如果最后没有找到任何时间任何地点可能有贼,说明他跑掉了
除了上面这种情况,如果在所有时间里都同时存在多于一个点可能有贼,则Nothing known
除了上面两种情况,输出能确定贼的时间和该时间贼的地点
#include<cstdio> #include<cstring> #include<algorithm> #include<vector> using namespace std; typedef pair<int,int> pii; const int maxn = 105; int h,w,t; int d[maxn][maxn][maxn]; int dx[] = {-1,0,1,0,0}; int dy[] = {0,1,0,-1,0}; vector<pii> ans[maxn]; void init(){ memset(d,-1,sizeof(d)); int n; scanf("%d",&n); int tt,xa,ya,xb,yb; for(int i = 0; i < n; i++){ scanf("%d%d%d%d%d",&tt,&xa,&ya,&xb,&yb); for(int i = xa; i <= xb; i++){ for(int j = ya; j <= yb; j++){ d[tt][i][j] = 0; } } } } int dfs(int x,int y,int tt){ int &ans = d[tt][x][y]; if(ans != -1) return ans; ans = 0; if(tt == t) return ans = 1; for(int i = 0; i < 5; i++){ int xx = x + dx[i]; int yy = y + dy[i]; if(xx<1||xx>h||yy<1||yy>w) continue; if(dfs(xx,yy,tt+1)) ans = 1; } return ans; } int solve(){ int flag; for(int i = 1; i <= t; i++){ flag = 0; ans[i].clear(); for(int j = 1; j <= h; j++){ for(int k = 1; k <= w; k++){ if(d[i][j][k] == 1){ ans[i].push_back(make_pair(j,k)); flag = 1; } } } if(flag == 0) return 0; } flag = 1; for (int i = 1; i <= t; i++) { if (ans[i].size() == 1) { printf("Time step %d: The robber has been at %d,%d.\n", i, ans[i][0].first, ans[i][0].second); flag = 0; } } if (flag) return 1; return 2; } int main(){ int cas = 0; while(scanf("%d%d%d",&h,&w,&t)){ if(!h&&!w&&!t) break; init(); for(int i = 1; i <= h; i++){ for(int j = 1; j <= w; j++){ dfs(i,j,1); } } printf("Robbery #%d:\n",++cas); int tmp = solve(); if (tmp == 0) printf("The robber has escaped.\n"); else if (tmp == 1) printf("Nothing known.\n"); printf("\n"); } return 0; }
输出语句手打,打错了单词,wrong了好几次,不能再笨/////T_T
时间: 2024-10-24 21:20:29