这个题意搞了半天才搞明白 就是如果定义一个d-summit,即从该点到另一个更高的点,经过的路径必定是比当前点低至少d高度的,如果该点是最高点,没有比他更高的,就直接视为顶点 其实就是个BFS染色,先按降序排序,然后每个点对其可到达的点染色,h-d的点为边界,走到这里就不用往下染了 然后其他店染色的时候若产生冲突,则非d—summit,否则该点为顶点 今天还有COJ上一个BFS染色的题目,一直TLE。。。还没弄出来

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
int mat[510][510];
int n,m,d,cnt;
struct node{
int x,y,h;
bool operator <(const node& rhs)const{
return h>rhs.h;
}
}P[510*500];
int dir[][2]={{0,1},{0,-1},{1,0},{-1,0}};
int vis[510][510];
int ans;
inline void bfs(int x)
{
node a=P[x];
int flag=1;
int tot=1;
if (vis[a.x][a.y]!=-1){
flag=0;
return;
}
else vis[a.x][a.y]=a.h;
queue<node> q;
q.push(a);
int sh=a.h;
int lh=a.h-d;
while (!q.empty())
{
node u=q.front();
q.pop();
for (int i=0;i<4;i++){
node np;
np.x=u.x+dir[i][0];
np.y=u.y+dir[i][1];
np.h=mat[np.x][np.y];
if (np.x>=n || np.y>=m || np.x<0 ||np.y<0) continue;
if (np.h<=lh) continue;
if (vis[np.x][np.y]!=-1){
if (vis[np.x][np.y]!=sh) flag=0;
continue;
}
vis[np.x][np.y]=sh;
if (np.h==sh) tot++;
q.push(np);
}
}
if (flag==1) ans+=tot;
}
int main()
{
int t;
scanf("%d",&t);
while (t--)
{
cnt=0;
scanf("%d%d%d",&n,&m,&d);
for (int i=0;i<n;i++)
{
for (int j=0;j<m;j++){
scanf("%d",&mat[i][j]);
P[cnt].x=i;
P[cnt].y=j;
P[cnt++].h=mat[i][j];
}
}
sort(P,P+n*m);
memset(vis,-1,sizeof vis);
ans=0;
for (int i=0;i<n*m;i++)
{
bfs(i);
}
printf("%d\n",ans);
}
return 0;
}

  

UVALive 3977 BFS染色的更多相关文章

  1. HDU 2444 二分图判断 (BFS染色)+【匈牙利】

    <题目链接> 题目大意: 有N个人,M组互相认识关系互相认识的两人分别为a,b,将所有人划分为两组,使同一组内任何两人互不认识,之后将两个组中互相认识的人安排在一个房间,如果出现单人的情况 ...

  2. 【Luogu】P1330封锁阳光大学(bfs染色)

    题目链接 这题恶心死我了. bfs染色,统计每个联通块两色的个数,ans加它们的最小值. #include<cstdio> #include<cctype> #include& ...

  3. XMU 1617 刘备闯三国之汉中之战 【BFS+染色】

    1617: 刘备闯三国之汉中之战 Time Limit: 1000 MS  Memory Limit: 128 MBSubmit: 6  Solved: 5[Submit][Status][Web B ...

  4. UVALive - 3977 Summits (BFS染色)

    题目大意:坑爹的题目.题意那么难理解. 讲的就是,假设该点是山顶的话(高度为h).那么以该点为中心,往外辐射.走高度大于h-d的点,到达不了还有一个比它高的点 这就提示了,高度要从大到小排序,依次以高 ...

  5. BFS(染色) LA 3977 Summits

    题目传送门 题意:题意坑爹.问符合条件的的山顶个数 分析:降序排序后从每个点出发,假设为山顶,如果四周的点的高度>h - d那么可以走,如果走到已经走过的点且染色信息(山顶高度)不匹配那么就不是 ...

  6. UVALive 6663 Count the Regions 离散+bfs染色_(:зゝ∠)_

    题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=4675">点击打开链接 gg.. ...

  7. Hdu 5285 wyh2000 and pupil (bfs染色判断奇环) (二分图匹配)

    题目链接: BestCoder Round #48 ($) 1002 题目描述: n个小朋友要被分成两班,但是有些小朋友之间是不认得的,所以规定不能把不认识的小朋友分在一个班级里面,并且一班的人数要比 ...

  8. CF796D Police Stations BFS+染色

    题意:给定一棵树,树上有一些点是警察局,要求所有点到最近的警察局的距离不大于 $d$,求最多能删几条边 ? 题解: 考虑什么时候一条边可以被断开:这条边的两个端点被两个不同的警察局覆盖掉. 我们要设计 ...

  9. CodeForces-598D(BFS,染色)

    链接: https://vjudge.net/problem/CodeForces-598D 题意: Igor is in the museum and he wants to see as many ...

随机推荐

  1. JSTL1.0和JSTL1.1的区别

    这要从一个异常说起 According to TLD or attribute directive in tag file, attribute value does not accept any e ...

  2. Springboot配置文件内容加密

      使用的是jasypt-spring-boot-starter,具体介绍可以参考 https://gitee.com/yangziyi2017/Jasypt-Spring-Boot   引入依赖 & ...

  3. 使用loadrunner监控apcahe资源

    一般要修改的内容在Httpd.conf文件中已经存在,如果不存在请自行添加相应内容. (1)修改Apache中Httpd.conf文件, (2)添加ExtendedStatus,设置ExtendedS ...

  4. 数据结构 c++ 广义表

    // CTest.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #include &l ...

  5. 我的Grunt之旅-序章

    时间:2018-03-05 13:52  事件:安装Grunt 相关网址: grunt官网:https://gruntjs.com node.js下载地址 :https://nodejs.org/en ...

  6. other#apache-commons

    if you want to be a better javaer, you should  spent time on apache commons.

  7. Codeforces 459E Roland and Rose

    本以为是个树形DP,按照树形DP的方法在那里dfs,结果WA到死,因为它存在有向环,不是树,凡是存在环的情况切记不要用树形的方法去做 题目的突破点在于将边排完序之后,用点表示以该点为边结尾的最大长度, ...

  8. mysql 存储引擎入门

  9. JAVA学习笔记-数组的三种初始化方式

      package Study; public class TestArray02 { public static void main(String[] args){//声明 int[] a; int ...

  10. ListView的DrawSubItem时间添加边框,字体变粗问题

    procedure TFrmrdp.ListView1AdvancedCustomDrawSubItem(Sender: TCustomListView; Item: TListItem; SubIt ...