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 ...
随机推荐
- 使用jQuery POST提交数据返回的JSON是字符串不能解析为JSON对象
post请求原代码: $.post( "/User/Home/Code", { Phone: $( "#phone").val() }, function (d ...
- Fragstats景观分析研究
QQ 交流群: Fragstats景观分析 加群链接:http://url.cn/N4wZ3N
- 【风马一族_xml】xml编程
xml编程:利用java程序支增删改查(CRUD)XML中的数据 解析思想: dom解析 sax解析 基于这两种解析思想市面上就有了很多的解析api sun jaxp (比较弱)既有dom方式也有sa ...
- dmp文件导入
dmp文件导入 1,打开“开始”-->输入cmd—> sqlplus log: 2,输入 conn / as sysdba管理员账户登录: 3,需要创建表空间,如果我们知道需要导入的数据库 ...
- silverlight 文本框只能输入数字
void mobile_KeyUp(object sender, KeyEventArgs e) { Regex rg = new Regex("^[0-9]{1,11}$"); ...
- winform 批量导入本地sql文件,批量导入mdb(access)文件到sqlserver
0.数据库连接 private void button1_Click(object sender, EventArgs e) { this.btnUpdate.Enabled = false; #re ...
- JS重写alert,保证弹窗错误的友好性
// ------------------------------------------------------------- // 重写alert,保证弹窗错误的友好性 var j_oldAler ...
- 如何查看 Apache 的版本
查看 Apache 服务器版本的命令行为: httpd -v 或者 apachectl -v 例如:用 Xshell 连接到服务器后,输入:httpd -v 或者:apachectl -v 返回: S ...
- setEllipsize(TruncateAt where)
void android.widget.TextView.setEllipsize(TruncateAt where) public void setEllipsize (TextUtils.Trun ...
- Asp.net MVC Global.asax文件
global.asax文件概述 global.asax这个文件包含全局应用程序事件的事件处理程序.它响应应用程序级别和会话级别事件的代码. 运行时, Global.asax 将被编译成一个动态生成的 ...