UVALive - 3977 Summits (BFS染色)
题目大意:坑爹的题目。题意那么难理解。
讲的就是,假设该点是山顶的话(高度为h)。那么以该点为中心,往外辐射。走高度大于h-d的点,到达不了还有一个比它高的点
这就提示了,高度要从大到小排序,依次以高的点(假设高度为h)为核心辐射,假设碰上高度小于等于h-d的。表示此路不通了。就在该处停止
反之。假设碰上高度大于h-d的,且没有被染色过的。那么就将其染色
假设碰上高度大于h-d的,且被染色的话,就表明能够走到还有一个更高点了,那么此点就不是山顶了
假设中途碰到了和该点一样高的,那么山顶的数量就加1
这里出现了失误,写代码的时候把M写成N了(定义数组的时候,本来是hight[M][M]的,结果写成了hight[N][N],这里N = 250010。M = 510),结果一直CE,非常郁闷,可是电脑上的编译却过了
后来我把结构体的定义拉到了后面,在电脑上编译就出错了。空间不足
这就有点郁闷了。结构体的定义顺序还影响到了编译?
假设有大神知道的。还望告知一下
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
#define N 250010
#define M 510
struct Node {
int x, y, h;
}node[N];
int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int Ans, H, W, D;
int color[M][M];
int hight[M][M];
bool cmp(const Node &a, const Node &b) {
return a.h > b.h;
}
struct tmp_node{
int x, y;
tmp_node() {}
tmp_node(int x, int y): x(x), y(y) {}
};
void bfs(int u) {
bool flag = true;
int tot = 1, lim = node[u].h - D, high = node[u].h;
queue<tmp_node> Q;
Q.push(tmp_node(node[u].x, node[u].y));
color[node[u].x][node[u].y] = high;
while (!Q.empty()) {
tmp_node t = Q.front();
Q.pop();
for (int i = 0; i < 4; i++) {
int x = t.x + dir[i][0];
int y = t.y + dir[i][1];
if (x >= H || x < 0 || y >= W || y < 0)
continue;
if (hight[x][y] <= lim)
continue;
if (color[x][y] != -1) {
if (color[x][y] != high)
flag = false;
continue;
}
if (color[x][y] == -1) {
color[x][y] = high;
Q.push(tmp_node(x,y));
}
if (hight[x][y] == high)
tot++;
}
}
if (flag)
Ans += tot;
}
void solve() {
sort(node, node + H * W, cmp);
memset(color, -1, sizeof(color));
Ans = 0;
for (int i = 0; i < H * W; i++)
if (color[node[i].x][node[i].y] == -1)
bfs(i);
printf("%d\n", Ans);
}
int main() {
int test;
scanf("%d", &test);
while (test--) {
scanf("%d%d%d", &H, &W, &D);
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++) {
scanf("%d", &node[i * W + j].h);
node[i * W + j].x = i;
node[i * W + j].y = j;
hight[i][j] = node[i * W + j].h;
}
solve();
}
return 0;
}
UVALive - 3977 Summits (BFS染色)的更多相关文章
- UVALive 3977 BFS染色
这个题意搞了半天才搞明白 就是如果定义一个d-summit,即从该点到另一个更高的点,经过的路径必定是比当前点低至少d高度的,如果该点是最高点,没有比他更高的,就直接视为顶点 其实就是个BFS染色,先 ...
- UVA12130 Summits(BFS + 贪心)
UVA12130 Summits(BFS + 贪心) 题目链接 题目大意: 给你一个h ∗ w 的矩阵,矩阵的每一个元素都有一个值,代表这个位置的高度. 题目要求你找出这个图中有多少个位置是峰值点.从 ...
- HDU 2444 二分图判断 (BFS染色)+【匈牙利】
<题目链接> 题目大意: 有N个人,M组互相认识关系互相认识的两人分别为a,b,将所有人划分为两组,使同一组内任何两人互不认识,之后将两个组中互相认识的人安排在一个房间,如果出现单人的情况 ...
- 【Luogu】P1330封锁阳光大学(bfs染色)
题目链接 这题恶心死我了. bfs染色,统计每个联通块两色的个数,ans加它们的最小值. #include<cstdio> #include<cctype> #include& ...
- XMU 1617 刘备闯三国之汉中之战 【BFS+染色】
1617: 刘备闯三国之汉中之战 Time Limit: 1000 MS Memory Limit: 128 MBSubmit: 6 Solved: 5[Submit][Status][Web B ...
- BFS(染色) LA 3977 Summits
题目传送门 题意:题意坑爹.问符合条件的的山顶个数 分析:降序排序后从每个点出发,假设为山顶,如果四周的点的高度>h - d那么可以走,如果走到已经走过的点且染色信息(山顶高度)不匹配那么就不是 ...
- UVALive 6663 Count the Regions 离散+bfs染色_(:зゝ∠)_
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=4675">点击打开链接 gg.. ...
- What a Ridiculous Election UVALive - 7672 (BFS)
题目链接: E - What a Ridiculous Election UVALive - 7672 题目大意: 12345 可以经过若干次操作转换为其它五位数. 操作分三种,分别为: 操作1:交 ...
- UVA 12130 - Summits(BFS+贪心)
UVA 12130 - Summits 题目链接 题意:给定一个h * w的图,每一个位置有一个值.如今要求出这个图上的峰顶有多少个.峰顶是这样定义的.有一个d值,假设一个位置是峰顶.那么它不能走到不 ...
随机推荐
- Linux - 用 Konstruct 安装 KDE 3.x
make-kde3.x Linux - 用 Konstruct 安装 KDE 3.x 找个截图工具 khtml2png (http://khtml2png.sourceforge.net/), 现在都 ...
- golang round
func Round(f float64, n int) float64 {pow10_n := math.Pow10(n)return math.Trunc((f+0.5/pow10_n)*pow1 ...
- NOI2005维修数列(splay)
题目描述: Description 请写一个程序,要求维护一个数列,支持以下 6 种操作: 请注意,格式栏 中的下划线‘ _ ’表示实际输入文件中的空格 Input 输入的第1 行包含两个数N 和M( ...
- 自绘listCtrl控件选中该行高亮(模拟windows)
CListCtrl的派生类CMyListCtrl的DrawItem()函数里添加代码 CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); if ...
- 洛谷 P3003 [USACO10DEC]苹果交货Apple Delivery
洛谷 P3003 [USACO10DEC]苹果交货Apple Delivery 题目描述 Bessie has two crisp red apples to deliver to two of he ...
- 洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II
洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II https://www.luogu.org/problemnew/show/P2616 题目描述 Farmer ...
- Android怎样实现毛玻璃效果之Android高级模糊技术
自从iOS系统引入了Blur效果,也就是所谓的毛玻璃.模糊化效果.磨砂效果.各大系统就開始竞相模仿,这是如何的一个效果呢,我们先来看一下,如以下的图片: 效果我们知道了,怎样在Android中实现呢. ...
- JQuery 各节点获取函数:父节点,子节点,兄弟节点
jQuery.parent(expr) //找父元素 jQuery.parents(expr) //找到所有祖先元素,不限于父元素 jQuery.children ...
- 【2017 Multi-University Training Contest - Team 10】Schedule
[链接]http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1010&cid=767 [题意] 给一些区间,每台机器在这些区间 ...
- 洛谷——P1601 A+B Problem(高精)
https://www.luogu.org/problem/show?pid=1601#sub 题目背景 无 题目描述 高精度加法,x相当于a+b problem,[b][color=red]不用考虑 ...