UVALive 3977
直接搜索,简单题;
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#define maxn 505
#define ll long long
using namespace std; int map[maxn][maxn];
int dir[][]={{,},{,},{,-},{-,}};
int vis[maxn][maxn]; struct node
{
int x,y,d;
node(int x=,int y=,int d=):x(x),y(y),d(d){}
bool operator<(const node &t)const
{
return d>t.d;
}
}arr[maxn*maxn]; queue<node>q; int main()
{
int t,n,m,d;
scanf("%d",&t);
while(t--)
{
int cnt=;
scanf("%d%d%d",&n,&m,&d);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
scanf("%d",&map[i][j]);
arr[cnt++]=node(i,j,map[i][j]);
}
} memset(vis,-,sizeof vis);
int ans=;
sort(arr,arr+cnt);
while(!q.empty())q.pop(); for(int i=;i<cnt;i++)
{
node v=arr[i];
if(vis[v.x][v.y]!=-)continue;
bool flag=;
int bound=v.d-d;
int peak=v.d;
q.push(v);
int cot=; while(!q.empty())
{
node u=q.front();
q.pop();
vis[u.x][u.y]=peak;
for(int i=;i<;i++)
{
node tmp;
tmp.x=u.x+dir[i][];
tmp.y=u.y+dir[i][];
if(tmp.x<||tmp.x>n||tmp.y<||tmp.y>m)continue;
tmp.d=map[tmp.x][tmp.y];
if(tmp.d<=bound)continue;
if(vis[tmp.x][tmp.y]!=-)
{
if(vis[tmp.x][tmp.y]!=peak)
flag=;
continue;
}
vis[tmp.x][tmp.y]=peak;
if(tmp.d==peak)cot++;
q.push(tmp);
}
}
if(flag)
ans+=cot;
}
printf("%d\n",ans);
}
return ;
}
UVALive 3977的更多相关文章
- UVALive - 3977 Summits (BFS染色)
题目大意:坑爹的题目.题意那么难理解. 讲的就是,假设该点是山顶的话(高度为h).那么以该点为中心,往外辐射.走高度大于h-d的点,到达不了还有一个比它高的点 这就提示了,高度要从大到小排序,依次以高 ...
- UVALive 3977 BFS染色
这个题意搞了半天才搞明白 就是如果定义一个d-summit,即从该点到另一个更高的点,经过的路径必定是比当前点低至少d高度的,如果该点是最高点,没有比他更高的,就直接视为顶点 其实就是个BFS染色,先 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
随机推荐
- CityEngine2012(32位)安装
今天下午把CityEngine2012装好了,既然Esri大力推CityEngine作为其三维建模软件,那就学习一下,还好没花多长时间搞定破解版,以前装Erdas,南方CASS,AutoCAD那些该死 ...
- how to debug thread cpu 100%
when we write a program, cpu and memory usages are very important to indicate the stability of the p ...
- insertorupdate
MERGE INTO 运用的心得 最近完成一个功能,就是往表里插入数据,以party_id 和prod_id为联合主键,存在的更新,不存在的插入, ORACLE 10g 后可以试用MERGE INT ...
- 基于JQuery+JSP的无数据库无刷新多人在线聊天室
JQuery是一款非常强大的javascript插件,本文就针对Ajax前台和JSP后台来实现一个无刷新的多人在线聊天室,该实现的数据全部存储在服务端内存里,没有用到数据库,本文会提供所有源程序,需要 ...
- linux下配置tomcat7 + solr4.9(续)--- 多核索引的配置
在上一篇文章中(详见http://www.cnblogs.com/bxljoy/p/3850263.html),我们已经介绍了tomcat+solr的索引服务器的配置,但是文中创建的服务器只能支持存储 ...
- SQL Server 2008中新增的变更数据捕获(CDC)和更改跟踪
来源:http://www.cnblogs.com/downmoon/archive/2012/04/10/2439462.html 本文主要介绍SQL Server中记录数据变更的四个方法:触发器 ...
- CentOS安全设置
删除多余的用户和用户组,修改口令文件属性,禁止[Ctrl+Alt+Delete]重启命令,防止别人ping的方法.整理自互联网. 1.删除多余的用户和用户组 //删除多余用户 # vi /etc/pa ...
- html设置360兼容/极速模式
由于众所周知的情况,国内的主流浏览器都是双核浏览器:基于Webkit内核用于常用网站的高速浏览.基于IE的内核用于兼容网银.旧版网站.以360的几款浏览器为例,我们优先通过Webkit内核渲染主流的网 ...
- Delphi XE5教程2:程序组织
内容源自Delphi XE5 UPDATE 2官方帮助<Delphi Reference>,本人水平有限,欢迎各位高人修正相关错误! 也欢迎各位加入到Delphi学习资料汉化中来,有兴趣者 ...
- RealThinClient (RTC)是什么?
RealThinClient SDK是用于开发标准的HTTP(S)服务器,ISAPI扩展以及客户端的VCL控件.可用于Windows下的CodeGear Delphi 6-XE5. 功能描述 Abou ...