直接搜索,简单题;

#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. Spring IoC容器的设计——BeanFactory应用场景2

    1.BeanFactory接口设计了getBean方法,这个方法是使用IoC容器API的主要方法,通过这个方法,可以取得IoC容器中管理的Bean,Bean的取得是通过指定名字来索引的. 2.如果需要 ...

  2. 9款完美体验的HTML5/jQuery应用

    1.jQuery动画图标菜单导航 仿苹果样式 这次要分享的这款jQuery插件非常酷,它是一款带有动画按钮的jQuery菜单插件.而且从菜单的外观上来看,有点苹果菜单风格的味道.当我们将鼠标滑过菜单项 ...

  3. Java web的读取Excel简单Demo

    目录结构: Data.xls数据:   后台页面: GetExcelData.java       public void doGet(HttpServletRequest request, Http ...

  4. 链表的创建、测长、排序、插入、逆序的实现(C语言)

    #include <stdio.h> #define END_elem 0 struct node { int date; struct node * next; }; //链表创建 no ...

  5. sizeWithFont方法被弃用了,该怎么办?

    之前使用了NSString类的sizeWithFont:constrainedToSize:lineBreakMode:方法,但是该方法已经被iOS7 Deprecated了,而iOS7新出了一个bo ...

  6. 一款类似塔防类的保卫羊村游戏android源码

    一款类似塔防类的保卫羊村游戏源码,这个游戏很像我们平时玩的塔防游戏的,游戏的源码比较完整的,大家可以修改一下或者添加一些广告就可以上线到应用商店了,而且这个游戏目前已经上线国内的一些应用商店了,360 ...

  7. SQL2008、SQL2013 执行Transact-SQL 语句或者批处理时发生了异常。错误5120

    附加数据库的时候遇到问题,问题描述如下: 附加数据库 对于 服务器"服务器名"失败.(Microsoft.SqlServer.Smo) 执行Transact-SQL 语句或者批处理 ...

  8. asp.net图片上传实例

    网站后台都需要有上传图片的功能,下面的例子就是实现有关图片上传. 缺点:图片上传到本服务器上,不适合大量图片上传. 第一.图片上传,代码如下: xxx.aspx 复制代码代码如下: <td cl ...

  9. 感知器算法PLA

    for batch&supervised binary classfication,g≈f <=> Eout(g)≥0 achieved through Eout(g)≈Ein(g ...

  10. WPF以Clickonce方式发布后使用管理员身份运行

    WPF的程序,在发布时采用的Clickonce方式发布,Win7的用户安装完成之后,发现执行某些操作的时候会导致程序异常.在排查后发现,是权限问题导致.如图: 是执行File.Move时引发的异常:对 ...