直接搜索,简单题;

#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的更多相关文章

  1. UVALive - 3977 Summits (BFS染色)

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

  2. UVALive 3977 BFS染色

    这个题意搞了半天才搞明白 就是如果定义一个d-summit,即从该点到另一个更高的点,经过的路径必定是比当前点低至少d高度的,如果该点是最高点,没有比他更高的,就直接视为顶点 其实就是个BFS染色,先 ...

  3. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  4. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  5. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  6. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  7. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  8. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  9. UVALive 6500 Boxes

    Boxes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

随机推荐

  1. 8款唯美设计的HTML5/CSS3应用

    1.CSS3漂亮的自定义Checkbox复选框 9款迷人样式 今天我们来分享一款9款样式迷人的CSS3漂亮的自定义Checkbox复选框.这几款复选框样式很丰富,使用起来也比较方便. 在线演示 源码下 ...

  2. Difference between ref and out parameters

    Original link: http://www.dotnet-tricks.com/Tutorial/csharp/K0Hb060414-Difference-between-ref-and-ou ...

  3. STL--vector(转载)

    函数 表述 c.assign(beg,end) c.assign(n,elem) 将[beg; end)区间中的数据赋值给c. 将n个elem的拷贝赋值给c. c.at(idx) 传回索引idx所指的 ...

  4. berkerly db 中简单的读写操作(有一些C的 还有一些C++的)

    最近在倒腾BDB,才发现自己确实在C++这一块能力很弱,看了一天的api文档,总算是把BDB的一些api之间的关系理清了,希望初学者要理清数据库基本知识中的环境,句柄,游标的基本概念,这样有助于你更好 ...

  5. Excel中 设置使得每行的颜色不一样

        在编写测试案例的时候,众多的excel行看的眼睛花花的,这里给出一个小技巧,设置Excel的每行显示的颜色不一样,最终的效果如下:    具体操作:     1. Ctrl+A全选所有表格区域 ...

  6. 《Apache负载均衡》RHEL6

    Apache负载均衡的搭建,基于上篇<CDN web加速代理>搭建好的服务器,我们来搭建apache负载均衡: Apahe负载均衡:就是为了缓解一台服务器的压力而多台服务器配合使用. 基于 ...

  7. linux 终端显示 -bash-4.1

    解决方法: cp /etc/skel/.bashrc /root/ cp /etc/skel/.bash_profile  /root/ 重新登陆就OK了

  8. Win7开始菜单之【附件】不全解决方案

    Win7开始菜单之[附件]不全解决方案 1:打开你的[开始]菜单,转到附件,如果你发现你的附件里的“附件”不是那么全的话,如下图:来吧,我告诉你如何恢复它到最初的模样……哦,或许如果你不急于恢复的话, ...

  9. VS2010配色方案

    http://studiostyl.es/ 导入步骤:  工具------------导入和导出设置------------导入选定的环境设置------------否,仅导入新设置--------- ...

  10. impdp ORA-29913: error in executing ODCIEXTTABLEOPEN callout

    1.数据导出时的日志 ;;; Export: Release :: Copyright (c) , , Oracle and/or its affiliates. All rights reserve ...