zoukankan      html  css  js  c++  java
  • UVALive

    题目大意:坑爹的题目。题意那么难理解。


    讲的就是,假设该点是山顶的话(高度为h)。那么以该点为中心,往外辐射。走高度大于h-d的点,到达不了还有一个比它高的点
    这就提示了,高度要从大到小排序,依次以高的点(假设高度为h)为核心辐射,假设碰上高度小于等于h-d的。表示此路不通了。就在该处停止
    反之。假设碰上高度大于h-d的,且没有被染色过的。那么就将其染色
    假设碰上高度大于h-d的,且被染色的话,就表明能够走到还有一个更高点了,那么此点就不是山顶了
    假设中途碰到了和该点一样高的,那么山顶的数量就加1

    这里出现了失误,写代码的时候把M写成N了(定义数组的时候,本来是hight[M][M]的,结果写成了hight[N][N],这里N = 250010。M = 510),结果一直CE,非常郁闷,可是电脑上的编译却过了
    后来我把结构体的定义拉到了后面,在电脑上编译就出错了。空间不足
    这就有点郁闷了。结构体的定义顺序还影响到了编译?
    假设有大神知道的。还望告知一下

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    using namespace std;
    #define N 250010
    #define M 510
    
    struct Node {
        int x, y, h;
    }node[N];
    
    int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    int Ans, H, W, D;
    int color[M][M];
    int hight[M][M];
    
    bool cmp(const Node &a, const Node &b) {
        return a.h > b.h;
    }
    
    struct tmp_node{
        int x, y;
        tmp_node() {}
        tmp_node(int x, int y): x(x), y(y) {}
    };
    
    
    void bfs(int u) {
        bool flag = true;
        int tot = 1, lim = node[u].h - D, high = node[u].h;
    
        queue<tmp_node> Q;
        Q.push(tmp_node(node[u].x, node[u].y));
        color[node[u].x][node[u].y] = high;
    
        while (!Q.empty()) {
            tmp_node t = Q.front();
            Q.pop();
            for (int i = 0; i < 4; i++) {
                int x = t.x + dir[i][0];
                int y = t.y + dir[i][1];
    
                if (x >= H || x < 0 || y >= W || y < 0)
                    continue;
    
                if (hight[x][y] <= lim)
                    continue;
                if (color[x][y] != -1) {
                    if (color[x][y] != high)
                        flag = false;
                    continue;
                }
    
                if (color[x][y] == -1) {
                    color[x][y] = high;
                    Q.push(tmp_node(x,y));
                }
                if (hight[x][y] == high)
                    tot++;
            }
        }
        if (flag)
            Ans += tot;
    }
    
    void solve() {
        sort(node, node + H * W, cmp);
        memset(color, -1, sizeof(color));
        Ans = 0;
    
        for (int i = 0; i < H * W; i++)
            if (color[node[i].x][node[i].y] == -1)
                bfs(i);
        printf("%d
    ", Ans);
    }
    
    int main() {
        int test;
        scanf("%d", &test);
        while (test--) {
    
            scanf("%d%d%d", &H, &W, &D);
            for (int i = 0; i < H; i++)
                for (int j = 0; j < W; j++) {
                    scanf("%d", &node[i * W + j].h);
                    node[i * W + j].x = i;
                    node[i * W + j].y = j;
                    hight[i][j] = node[i * W + j].h;
                }
            solve();
        }
        return 0;
    }
    
  • 相关阅读:
    (转)一篇教会你写90%的shell脚本
    (转)printf命令详解
    (转)linux shell 字符串操作详解 (长度,读取,替换,截取,连接,对比,删除,位置 )
    (转)Shell中read的选项及用法
    (转)linux中shell变量$#,$@,$0,$1,$2的含义解释/Shell中的${}、##和%%使用范例/export
    (转)linux运维人员必会的22道shell编程面试题及视频讲解
    (转)李文周的博客
    ROS报错“An error occurred during the signature verification”的解决办法
    RRT and RRT Variants
    ROS LocalPlanner 基于自行车模型的DWA
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/8282674.html
Copyright © 2011-2022 走看看