UVALive 3977 BFS染色
这个题意搞了半天才搞明白 就是如果定义一个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染色的更多相关文章
- 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 ...
 - UVALive - 3977 Summits (BFS染色)
		
题目大意:坑爹的题目.题意那么难理解. 讲的就是,假设该点是山顶的话(高度为h).那么以该点为中心,往外辐射.走高度大于h-d的点,到达不了还有一个比它高的点 这就提示了,高度要从大到小排序,依次以高 ...
 - BFS(染色) LA 3977 Summits
		
题目传送门 题意:题意坑爹.问符合条件的的山顶个数 分析:降序排序后从每个点出发,假设为山顶,如果四周的点的高度>h - d那么可以走,如果走到已经走过的点且染色信息(山顶高度)不匹配那么就不是 ...
 - UVALive 6663 Count the Regions 离散+bfs染色_(:зゝ∠)_
		
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=4675">点击打开链接 gg.. ...
 - Hdu 5285 wyh2000 and pupil (bfs染色判断奇环) (二分图匹配)
		
题目链接: BestCoder Round #48 ($) 1002 题目描述: n个小朋友要被分成两班,但是有些小朋友之间是不认得的,所以规定不能把不认识的小朋友分在一个班级里面,并且一班的人数要比 ...
 - CF796D Police Stations BFS+染色
		
题意:给定一棵树,树上有一些点是警察局,要求所有点到最近的警察局的距离不大于 $d$,求最多能删几条边 ? 题解: 考虑什么时候一条边可以被断开:这条边的两个端点被两个不同的警察局覆盖掉. 我们要设计 ...
 - CodeForces-598D(BFS,染色)
		
链接: https://vjudge.net/problem/CodeForces-598D 题意: Igor is in the museum and he wants to see as many ...
 
随机推荐
- Java中很少用的CopyOnWriteArrayList
			
类注释 /** * A thread-safe variant of {@link java.util.ArrayList} in which all mutative * operations ({ ...
 - 深入解读EOS源代码之——区块链内核
			
EOS进入大众视野并且受到热议已经有一段时间了,各种热捧和争议过后,是时候让我们静下来搞清楚EOS到底是一个什么样的产品.本文从技术角度深入的分析EOS底层设计,从源代码入手,一层层揭开EOS区块链底 ...
 - Golang函数-递归函数
			
Golang函数-递归函数 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.
 - HiBench成长笔记——(7) 阅读《The HiBench Benchmark Suite: Characterization of the MapReduce-Based Data Analysis》
			
<The HiBench Benchmark Suite: Characterization of the MapReduce-Based Data Analysis>内容精选 We th ...
 - [CodeForces]1263A Sweet Problem
			
题目链接 题目描述 You have three piles of candies: red, green and blue candies: the first pile contains only ...
 - wav文件与byte互转  C#
			
//wav转byte public void WavToByte() { Byte[] bs; FileStream fs = new FileStream(@"C:\1.wav" ...
 - 【LOJ6498】「雅礼集训 2018 Day2」农民
			
题面 solution 直接暴力模拟,原数据可获得满分的成绩. 对于每个点,其父亲对其都有一个限制.故我们只需要判断当前点到根的路径上的限制是否都能满足即可. 考虑用树剖+线段树维护这个限制.考虑到翻 ...
 - 入门QT5 D1 Widget的移动
			
又重温了一遍C++之后来看QT教程了.QT之前也看过,不过都是很长时间之前了,一直也用到. 反过来再一学,这是和学新的是一样一样的. 首先创建新项目. 1.点击NEW PROJECT 2.Applit ...
 - jsp采用ajax传递数组给后台controller并遍历
			
ajax传递数组,期间出各种各样的问题,那叫一个头疼,网上各种查,都没有解决,最终摸索摸索加借鉴搞定,不多说,上代码 /* 复选框选定部分 */ $("#delete").clic ...
 - MySQL每日执行
			
drop event if exists upload_deadline; DELIMITER $$ create event upload_deadline day starts timestamp ...