zoukankan      html  css  js  c++  java
  • JZOJ3450. 【NOIP2013模拟联考3】山峰(summits) (Standard IO)

    Description

    作为地质学家的JIH,为了绘制地图进行了野外考察。考察结束,他得到了一张n*m的地面高度地图。为了科学研究,JIH定义了一种山峰叫做d-山峰。一个高度为h地点被称作d-山峰,只有满足从这里出发,在不经过小于等于h-d的地点的前提下无法达到比它更高的地方。JIH正纠结于怎么分礼物,标出d-山峰的任务就交给你了。
     

    Input

    第一行n,m,d
    第二行开始,有一个n*m的矩阵表示地图,用空格隔开。
     

    Output

    输出d-山峰的个数。
     

    Solution

    就是搜索,过了,极限时间复杂度O(n2m2)。

    玄学!

    代码

     1 const
     2   dx:array [1..4] of longint=(0,1,-1,0);
     3   dy:array [1..4] of longint=(1,0,0,-1);
     4 var
     5   n,m,d,ans,max:longint;
     6   a,f:array [0..501,0..501] of longint;
     7   bo:array [0..501,0..501] of boolean;
     8 procedure init;
     9 var
    10   i,j:longint;
    11 begin
    12   readln(n,m,d);
    13   max:=0;
    14   for i:=1 to n do
    15    for j:=1 to m do
    16      begin
    17        read(a[i,j]);
    18        if a[i,j]>max then
    19          max:=a[i,j];
    20      end;
    21 end;
    22 
    23 function dfs(x,y,h,sum,tot:longint):boolean;
    24 var
    25   i,xx,yy:longint;
    26 begin
    27   f[x,y]:=sum;
    28   if (a[x,y]>h) or (a[x,y]=h) and (bo[x,y]) then
    29     begin
    30       ans:=ans-1;
    31       exit(true);
    32     end;
    33   if tot>n*m then exit(false);
    34   for i:=1 to 4 do
    35     begin
    36       xx:=x+dx[i]; yy:=y+dy[i];
    37       if (xx<=n) and (xx>0) and (yy<=m) and (yy>0) then
    38         if (f[xx,yy]<>sum) and (a[xx,yy]>h-d) then
    39           if dfs(xx,yy,h,sum,tot+1) then exit(true);
    40     end;
    41   exit(false);
    42 end;
    43 
    44 procedure main;
    45 var
    46   i,j:longint;
    47 begin
    48   ans:=n*m;
    49   for i:=1 to n do
    50     for j:=1 to m do
    51       if a[i,j]<>max then
    52         bo[i,j]:=dfs(i,j,a[i,j],i*m+j,0);
    53   writeln(ans);
    54 end;
    55 
    56 begin
    57   init;
    58   main;
    59 end.
  • 相关阅读:
    mysql 赋给用户权限 grant all privileges on
    ubuntu下aptget安装小型的lamp环境
    Linux系统进程管理
    SQLChapter1_Overview of SQL Server
    SQLChapter2Querying Data
    SQLexercise
    SQLChapter4Managing Databases and Table
    JavaUI添加事件(二)
    java ActionEventDemo
    JavaUI弹出对话框
  • 原文地址:https://www.cnblogs.com/zyx-crying/p/9497592.html
Copyright © 2011-2022 走看看