poj 2612 Mine Sweeper
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 6429 | Accepted: 2500 |
Description
containing a mine is touched, an integer between 0 and 8 appears denoting the number of adjacent or diagonally adjacent grid positions that contain a mine. A sequence of moves in a partially played game is illustrated below.
Here, n is 8, m is 10, blank squares represent the integer 0, raised squares represent unplayed positions, and the figures resembling asterisks represent mines. The leftmost image represents the partially played game. From the first image to the second, the
player has played two moves, each time choosing a safe grid position. From the second image to the third, the player is not so lucky; he chooses a position with a mine and therefore loses. The player wins if he continues to make safe moves until only m unplayed
positions remain; these must necessarily contain the mines.
Your job is to read the information for a partially played game and to print the corresponding board.
Input
position. The next n lines are each n characters long: touched positions are denoted by an x, and untouched positions by a period. The sample input corresponds to the middle figure above.
Output
asterisk. All other positions should contain a period.
Sample Input
8
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
xxx.....
xxxx....
xxxx....
xxxxx...
xxxxx...
xxxxx...
xxx.....
xxxxx...
Sample Output
001.....
0013....
0001....
00011...
00001...
00123...
001.....
00123...
注意:假设踩到地雷。要把全部地雷表示出来。
#include <iostream>
using namespace std;
#define MAX 12
int n;
char map[MAX][MAX],ans[MAX][MAX];
int count(int i,int j,int n){
int ans=0;
if (map[i-1][j-1]=='*' && i-1>=0 && j-1>=0)
ans++;
if (map[i-1][j]=='*' && i-1>=0)
ans++;
if (map[i-1][j+1]=='*' && i-1>=0 && j+1<n)
ans++; if (map[i][j-1]=='*' && j-1>=0)
ans++;
if (map[i][j]=='*')
ans++;
if (map[i][j+1]=='*' && j+1<n)
ans++; if (map[i+1][j-1]=='*' && i+1<n && j-1>=0)
ans++;
if (map[i+1][j]=='*' && i+1<n)
ans++;
if (map[i+1][j+1]=='*' && i+1<n && j+1<n)
ans++;
return ans;
}
int main(){ while (cin>>n){
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
cin>>map[i][j];
int flag=0;
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){
cin>>ans[i][j];
if (map[i][j]=='*' && ans[i][j]=='x')
flag=1;
if (ans[i][j]=='x'){
int k=count(i,j,n);
ans[i][j]=k+'0';
}
}
}
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){
if (flag==1 && map[i][j]=='*')
cout<<map[i][j];
else
cout<<ans[i][j];
}
cout<<endl;
}
}
return 0;
}
poj 2612 Mine Sweeper的更多相关文章
- 2020杭电多校 10C / HDU 6879 - Mine Sweeper (构造)
HDU 6879 - Mine Sweeper 题意 定义<扫雷>游戏的地图中每个空白格子的值为其周围八个格子内地雷的数量(即游戏内临近地雷数量的提示) 则一张地图的值\(S\)为所有空白 ...
- POJ 2612
#include<iostream> #include<stdio.h> #include<algorithm> #define MAXN 11 using nam ...
- 2020杭电多校 C / HDU 6879 - Mine Sweeper
题意: t组输入,每组输入一个s 你需要输出一个r行c列的阵列,这个阵列中'X'代表炸弹,'.'表示没有炸弹 对于'.'这些位置都会有一个数值,这个值取决于这个位置附近8个位置,这8个位置一共有几个炸 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- 多级弹出菜单jQuery插件ZoneMenu
ZoneMenu是一个菜单jQuery插件,只需占用页面上的一个小区域,却可以实现多级菜单. 在线体验:http://keleyi.com/jq/zonemenu/ 点击这里下载 完整HTML文件代码 ...
- 中英文代码对比系列之Java一例
原文: https://zhuanlan.zhihu.com/p/30905033. 作者为本人. 这个系列将对同一段代码进行中文命名和英文命名两个版本的比较. 目的包括, 演示中文命名, 发现命名时 ...
- 2017-11-09 中英文代码对比系列之Java一例
原文: https://zhuanlan.zhihu.com/p/30905033. 作者为本人. 这个系列将对同一段代码进行中文命名和英文命名两个版本的比较. 目的包括, 演示中文命名, 发现命名时 ...
- FZU1920 Left Mouse Button(dfs)
Problem 1920 Left Mouse Button Accept: 385 Submit: 719 Time Limit: 1000 mSec Memory Limit : 3 ...
- [转]分享20佳好玩的 jQuery 游戏
本文转自:http://www.cnblogs.com/lhb25/archive/2011/04/17/2001089.html jQuery是时下最流行的 JavaScript 库.现在,除了HT ...
随机推荐
- UVA 11542 Square 高斯消元 异或方程组求解
题目链接:点击打开链接 白书的例题练练手. . . P161 #include <cstdio> #include <iostream> #include <algori ...
- 机器学习 LR中的参数迭代公式推导——极大似然和梯度下降
Logistic本质上是一个基于条件概率的判别模型(DiscriminativeModel). 函数图像为: 通过sigma函数计算出最终结果,以0.5为分界线,最终结果大于0.5则属于正类(类别值为 ...
- python spark kmeans demo
官方的demo from numpy import array from math import sqrt from pyspark import SparkContext from pyspark. ...
- oracle init.ora常用配置详解
参考网上整理了重要的配置文件 db_name = "51cto" 一个数据库标识符,应与CREATE DATABASE 语句中指定的名称相对应. instance_name = ...
- [IOI 1999] 花店橱窗布置
[题目链接] https://www.luogu.org/problemnew/show/P1854v [算法] f[i][j]表示放了前i束花,第i束花放在第j个花瓶中,所能获得的最大美学值 由于要 ...
- MarkDown 语法备份
标题 标题1 标题2 标题3 标题4 标题5 无序列表 飞雪连天射白鹿 书神侠倚碧鸳 有序列表 飞雪连天射白鹿 笑书神侠倚碧鸳 超链接 百度 图片 粗体和斜体 粗体 斜体 表格 左对齐标题 右对齐标题 ...
- javascript在html直接传值
function getUrlParam(url, name) { var pattern = new RegExp("[?&]" + name + "\=([^ ...
- .NET MVC Dropzone 上传图片
在nuget控制台输入:Install-Package dropzone @{ Layout = null; } <!DOCTYPE html> <html> <head ...
- CLR - 设计类型
前言 好记性不如烂“笔头”系列... 目录 类型基础 基元类型.引用类型和值类型 类型与成员 常量与字段 方法 类型基础 “运行时”要求每个类型最终都从System.Object 类型派生. 由于所有 ...
- JAVA 静态内部类--转自http://bbs.csdn.net/topics/350021609
内部类其实并不是非要声明成static的..主要还是要看实际情况决定..静态和非静态有不同的作用.. 引用一篇文章给楼主参考下吧. 在一个类中创建另外一个类,叫做成员内部类.这个成员内部类可以静态的( ...