SGU 479 Funny Feature spfa
来源:互联网 发布:成都黑马程序员 编辑:程序博客网 时间:2024/06/05 05:55
题目链接:点击打开链接
最短路。
#include <cstdio>#include <cstring>#include <queue>using namespace std;const int N = 205;const int dx[] = {-1, 1, 0, 0};const int dy[] = {0, 0, 1, -1};int a[N][N], x[N*N], y[N*N];bool vis[N][N];queue<pair<int, int> > q;int main() {int n, m;while(~scanf("%d%d", &n, &m)) {memset(vis, 0, sizeof vis);while(q.size()) q.pop();for(int i = 0; i < n; i ++) {for(int j = 0; j < m; j ++) {scanf("%d", &a[i][j]);if(a[i][j] == 1) {q.push(make_pair(i, j));vis[i][j] = 1;}}}//printf("%d\n", q.size());int top = 0;pair<int, int> t;while(q.size()) {t = q.front(); q.pop();int xx = t.first, yy = t.second;a[xx][yy] --;x[++top] = xx;y[top] = yy;if(a[xx][yy] < 0) {top = -2;break;}for(int i = 0; i < 4; i ++) {int nx = xx + dx[i], ny = yy + dy[i];if(nx < 0 || nx >= n || ny < 0 || ny >= m) continue;if(a[nx][ny] > 0) a[nx][ny] --;if(a[nx][ny] == 1 && !vis[nx][ny]) q.push(make_pair(nx, ny));else if(a[nx][ny] < 0) {top = -2;break;}}if(top == -2) break;}//printf("%d\n", top);for(int i = 0; i < n; i ++) {for(int j = 0; j < m; j ++) {if(a[i][j] > 0) {top = -2;break;}}}if(top == -2) puts("No solution");else {for(int i = top; i > 0; i --) {printf("%d %d\n", x[i] + 1, y[i] + 1);}}}return 0;}
0 0
- SGU 479 Funny Feature spfa
- SGU 137 Funny Strings
- sgu 137 Funny Strings
- [SGU]137. Funny Strings
- SSU 479.Funny Feature
- SGU 137 Funny Strings(构造)
- bnu 33971 Funny Car Racing (spfa)
- CSUOJ 1333 Funny Car Racing (spfa算法)
- CSU 1333 Funny Car Racing(spfa)
- CSU1333 Funny Car Racing(最短路,SPFA)
- SGU 103 Traffic Lights(Spfa)
- SPFA的构图加判定 SGU 103
- SGU 103. Traffic Lights (SPFA)
- CSU 1333: Funny Car Racing(SPFA)13年省赛题
- 文章标题 csu1333 :Funny Car Racing(最短路 spfa)
- 1333: Funny Car Racing(最短路用spfa)
- funny
- funny
- iOS真机测试
- websphere修改端口
- UITableViewCell的contentView
- raphaeljs画图官网地址
- Android SDK Manager更新拒绝连接解决办法
- SGU 479 Funny Feature spfa
- Java多线程-工具篇-BlockingQueue
- 忍者无敌-实例讲解Cocos2d-x瓦片地图
- 【华为OJ】超长正整数相加
- BMP图片格式C函数说明
- Android实现网络多线程断点续传下载
- MATLAB——mean 函数
- java泛型
- Ubuntu 安装 Ganglia并绑定hadoop集群