hihoCoder#1119 小Hi小Ho的惊天大作战:扫雷·二
没有复杂算法,就是麻烦,写起来细节比较多,比较考验细心,一次AC好开心。
代码:
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdlib> using namespace std; #define SIZE 400 int N, M;
int map[SIZE][SIZE];
int res[SIZE][SIZE]; vector<pair<int, int> > unknown_neighbors(int i, int j) {
vector<pair<int, int> > nbs; for (int ii = -; ii < ; ii++)
for (int jj = -; jj < ; jj++) {
int r = ii + i;
int c = jj + j;
if (r >= && r < N && c >= && c < M && (r != i || c != j) && map[r][c] < )
nbs.push_back(pair<int, int>(r, c));
} return nbs;
} vector<pair<int, int> > known_counterparts(int i, int j) {
vector<pair<int, int> > cps; for (int ii = -; ii < ; ii++) {
for (int jj = -; jj < ; jj++) {
int r = ii + i;
int c = jj + j;
if (r >= && r < N && c >= && c < M && (r != i || c != j) && map[r][c] >= )
cps.push_back(pair<int, int>(r, c));
}
} return cps;
} vector<pair<int, int> > differ(vector<pair<int, int> > &a, vector<pair<int, int> > &b) {
vector<pair<int, int> > diff;
int count = ; for (auto pa : a) {
bool found = false;
for (auto pb : b) {
if (pb == pa) {
found = true;
count++;
break;
}
}
if (!found)
diff.push_back(pa);
} if (count < b.size())
diff.clear(); return diff;
} void merge_pos(int i, int j, int v) {
if (res[i][j] == - || res[i][j] == v)
res[i][j] = v;
else
res[i][j] = -;
} void solve() {
for (int i = ; i < N; i++)
for (int j = ; j < M; j++) {
if (map[i][j] == ) {
vector<pair<int, int> > nbs = unknown_neighbors(i, j);
for (auto p : nbs)
merge_pos(p.first, p.second, );
}
else if (map[i][j] > ) {
vector<pair<int, int> > nbs = unknown_neighbors(i, j);
if (nbs.size() == map[i][j]) {
for (auto p : nbs)
merge_pos(p.first, p.second, );
continue;
} vector<pair<int, int> > cps = known_counterparts(i, j);
for (auto p : cps) {
vector<pair<int, int> > cp_nbs = unknown_neighbors(p.first, p.second);
if (nbs.size() <= cp_nbs.size() || map[i][j] <= map[p.first][p.second])
continue;
vector<pair<int, int> > diff = differ(nbs, cp_nbs);
if ((int) (nbs.size() - cp_nbs.size()) == map[i][j] - map[p.first][p.second] && !diff.empty())
for (auto dp : diff)
merge_pos(dp.first, dp.second, );
}
}
}
} int main() {
int n; cin >> n;
while (n--) {
cin >> N >> M;
for (int i = ; i < N; i++)
for (int j = ; j < M; j++)
cin >> map[i][j];
memset(res, -, SIZE * SIZE * sizeof(int)); solve(); int mine = ;
int not_mine = ; for (int i = ; i < N; i++)
for (int j = ; j < M; j++) {
mine += (res[i][j] == ? : );
not_mine += (res[i][j] == ? : );
} cout << mine << " " << not_mine << endl;
} return ;
}
hihoCoder#1119 小Hi小Ho的惊天大作战:扫雷·二的更多相关文章
- hihoCoder 1114 小Hi小Ho的惊天大作战:扫雷·一 最详细的解题报告
题目来源:小Hi小Ho的惊天大作战:扫雷·一 解题思路:因为只要确定了第一个是否有地雷就可以推算出后面是否有地雷(要么为0,要么为1,如果不是这两个值就说明这个方案行不通),如果两种可能中有一种成功, ...
- hiho #1114 : 小Hi小Ho的惊天大作战:扫雷·一
#1114 : 小Hi小Ho的惊天大作战:扫雷·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 故事背景:密室.监视器与充满危机的广场 “我们还是循序渐进,先来考虑这 ...
- hihoCoder#1120 小Hi小Ho的惊天大作战:扫雷·三
原题地址 看上去非常复杂, 实际上是这一系列最简单的一步,本质上是个搜索过程,相比于前一道题,可以不用策略三,而且题目的数据规模超级小,所以暴力搜索就能过. 把尚未确定的点放在一个unsettled列 ...
- hihoCoder#1114 小Hi小Ho的惊天大作战:扫雷·一
原题地址 回溯+搜索 枚举每个位置上能否放地雷,当第i个位置枚举完成后,第i-1个位置的情况就确定了,此时,检查第i-1个位置是否满足要求,即左右间隔为1的范围内地雷数是否等于申明数字,如果满足条件, ...
- 【转】HTML5的小知识点小集合
html5的小知识点小集合 html5知识 1. Doctype作用?标准模式与兼容模式各有什么区别? (1).<!DOCTYPE>声明位于位于HTML文档中的第一行,处于<h ...
- html5的小知识点小集合
html5的小知识点小集合 html5知识 1. Doctype作用?标准模式与兼容模式各有什么区别? (1).<!DOCTYPE>声明位于位于HTML文档中的第一行,处于< ...
- 微信小程序即将开放申请?微信小论坛小程序专场16日或可见分晓
9月22号微信小程序内测至今已经好一段时间了,首批只开放了200个名额,没拿到内测资格的朋友早就等到心急了.就在刚刚,微信公开课宣布微信小论坛小程序专场即将在11月16号举行,微信公众平台小程序会在当 ...
- 如何获取微信小店小程序的AppID
2017年11月16日,微信有一个重磅的宣布:为了帮商家在微信内快速开店,方便商家和用户之间沟通,所有认证公众号,可快速创建微信小店小程序.这个改变是否能给微信小店带来新的生机?还需要时间的考验.微信 ...
- 微信小游戏 小程序与小游戏获取用户信息接口调整 wx.createUserInfoButton
参考: 小程序•小故事(6)——微信登录能力优化 小程序•小故事(4)——获取用户信息 本篇主要是讲微信getUserInfo接口不再出现授权弹框 那么原来getUserInfo是怎么样?修改之后又是 ...
随机推荐
- That Nice Euler Circuit UVALive - 3263 || 欧拉公式
欧拉定理: 简单多面体的顶点数V.棱数E及面数F间有关系有著名的欧拉公式:V-E+F=2. 设G为任意的连通的平面图,则v-e+f=2,v是G的顶点数,e是G的边数,f是G的面数.(引) 证明(?) ...
- ACM_查找ACM(加强版)
查找ACM(加强版) Time Limit: 2000/1000ms (Java/Others) Problem Description: 作为一个acmer,应该具备团队合作能力和分析问题能力.给你 ...
- Latex排版工具的使用(二) 分类: Latex 2014-06-14 23:01 389人阅读 评论(0) 收藏
Latex可以支持中文排版,如何实现中文支持可以到网上查找教程. 下面编写一段对中文排版的Latex源文档: 新建文件second.tex: \documentclass{article} \usep ...
- Styles and Themens(3)android所有主题表
The Android platform provides a large collection of styles and themes that you can use in your appli ...
- 转 ORA-00054 的解决方法
统有一个不用的索引,想删除这个索引, SQL> drop index GPSTIME_GLOBAL_INDEX 2 /drop index GPSTIME_GLOBAL_INDEX ...
- windows deintall 12c client
1.unintall: close all oracle app C:\app\client\CICadmin\product\12.1.0\client_1\deinstall deinstall ...
- 公众号如何获取已关注用户的unionid的问题
避免误导,先加一句:首先,得公众号绑定开放平台 这个问题困扰了我一早上,我尝试了很多次获取unionid都失败. 微信的开发文档上有说: 关于特殊场景下的静默授权 1.上面已经提到,对于以snsapi ...
- DeltaFish 选题报告总结
选题结果:校园物资流动系统 报告地点:3A101 会议时间:16:00 ~ 18:00 与会人员:软工小组全体成员 请假人员:无 缺席人员:无 报告人:陈志锴 一.报告内容总结 1.产品功能 针对校 ...
- vue2.0生命周期函数
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 如何选安卓android|linux系统开发板,简化学习难度,缩短开发进程
平台一:iTOP-4412精英版 系统支持:Android 4.0.3系统 / Android 4.4系统 / Linux + Qt系统 / Ubuntu12.04系统 开发板特点:Cortex-A ...