网络赛 Instrusive (HDU-5040)
来源:互联网 发布:最新天正建筑软件 编辑:程序博客网 时间:2024/06/05 22:14
这道题怎么读都不对劲。
管理员的英语应该是语文老师教的。。。都不知道回答的是什么。
题目的大概意思是,在一个n*n的图上,有一些点上有摄影机,初始状态各个摄影机都有一个初始方向,之后每秒顺时针转动90度。
matt有三种移动策略,1是静止在原地(在原地花多1秒),2是不盖箱子走(走到下一个格花1秒),3盖着箱子走(走到下一个花3秒)。要盖箱子的情况:1当前站立的点被摄像机拍到,下一步要走的格子当前时刻被摄像机拍到(而不是下一步要到的点下一时该被摄像机拍到)。
在原地呆的时间不应该超过四秒。
记录下每个格子会在什么时间被拍到。
优化一下内存,记录一下每一个格子到达的最小距离。
#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <stack>#include <cmath>#include <cstdlib>#include <vector>#include <map>#include <iostream>using namespace std;char ma[510][510];struct Info{ int t[4];}info[510][510];char dir[5] = "NESW";const int mov[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};struct State{ <span style="white-space:pre"></span>//搜索状态 int x, y, dist, stt; State(int _x, int _y, int d, int s): x(_x), y(_y), dist(d), stt(s){} State(){} bool operator < (const State a) const{ return dist > a.dist; }};int dp[501][501];void init(const int n, int &sx, int &sy, int &ex, int &ey){ for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) for(int l = 0; l < 4; l++) info[i][j].t[l] = 1; for(int i = 0; i < n; i++) { scanf("%s", ma[i]); for(int j = 0; j < n; j++) { int k; for(k = 0; k < 4; k++) if(dir[k] == ma[i][j]) break; if(k < 4) { for(int l = 0; l < 4; l++)<span style="white-space:pre"></span>//摄像机周围的点什么时间会被拍到 { info[i][j].t[l] = 3; int nx = i + mov[(l + k) % 4][0]; int ny = j + mov[(l + k) % 4][1]; if(nx < n && ny < n && nx >= 0 && ny >= 0 && ma[nx][ny] != '#') { info[nx][ny].t[l] = 3;<span style="white-space:pre"></span> } } } else if(ma[i][j] == 'M') { sx = i; sy = j; } else if(ma[i][j] == 'T') { ex = i; ey = j; } } } for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) dp[i][j] = 1000000;}priority_queue<State> que;int main(){ int t; scanf("%d", &t); for(int cas = 1; cas <= t; cas ++) { int n; scanf("%d",&n); int sx, sy, ex, ey; init(n, sx, sy, ex, ey); while(!que.empty()) que.pop(); que.push(State(sx, sy, 0, 0)); ma[sx][sy] = '#'; printf("Case #%d: ", cas); while(!que.empty()) { State tmp = que.top(); if(tmp.x == ex && tmp.y == ey)<span style="white-space:pre"></span>//搜到终点 { printf("%d\n", tmp.dist); break; } que.pop(); if(tmp.stt < 4)<span style="white-space:pre"></span>//停少于4秒 que.push(State(tmp.x, tmp.y, tmp.dist + 1, tmp.stt + 1)); for(int i = 0; i < 4; i++) { int nx = tmp.x + mov[i][0]; int ny = tmp.y + mov[i][1]; if(nx < n && ny < n && 0 <= nx && 0 <= ny && ma[nx][ny] != '#') { int dist = tmp.dist + 1; if(info[nx][ny].t[(tmp.dist) % 4] == 3) dist = tmp.dist + 3; if(info[tmp.x][tmp.y].t[tmp.dist % 4] == 3) dist = tmp.dist + 3; if(dist < dp[nx][ny]) { dp[nx][ny] = dist; que.push(State(nx, ny, dist, 0));<span style="white-space:pre"></span>//下一个状态 } } } } if(que.empty()) { printf("-1\n"); } } return 0;}
0 0
- 网络赛 Instrusive (HDU-5040)
- HDU 5040 Instrusive(北京网络赛I题)
- HDU 5040 Instrusive 搜索
- hdu 5040 Instrusive(BFS)
- 【HDU 5040】Instrusive
- HDU 5040 Instrusive
- HDU 5040 Instrusive
- hdu 5040 Instrusive (bfs)
- HDU 5040 Instrusive
- hdu 5040 Instrusive(BFS)
- HDU 5040 Instrusive(搜索,bfs,2014北京网络赛1009)
- 2014年北京网络赛 Instrusive HDU 5040 题解 优先队列
- HDU 5040 Instrusive 最短路
- hdu 5040——Instrusive
- hdu 5040 Instrusive 最短路
- HDU-5040-Instrusive(BFS+优先队列)
- HDU 5040 Instrusive BFS 性质优化
- hdu 5040 Instrusive【BFS+优先队列】
- 配置ssh公钥访问oschina
- 阿里巴巴在硅谷人眼里充当什么角色?
- 写文档的一些感触
- Weka算法Classifier-trees-REPTree源码分析(二)
- 使用接插件需要注意的问题
- 网络赛 Instrusive (HDU-5040)
- DSP6000的上电及供电
- 【转】字符串hash算法比较
- JAVA(三)
- Spring mvc+jackson+jquery easyui返回json数据出现整合出问题
- 读书札记-2013年12月
- DSP6000的几个简单优化技巧
- 实验室第一周
- 辩护人 豆瓣影评