• bjfu1262 优先队列


    比较典型的应用优先队列的题。题目是在一个长为n的数组中,依次问m个数中的最小值。那么把值和下标做成一个结构体,放进优先队列里,每次移动窗口就把该T的T掉,剩下的最小值就是答案,复杂度nlogn,轻松ac。

    /*
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    /*
     * 输入非负整数
     * 支持short、int、long、long long等类型(修改typec即可)。
     * 用法typec a = get_int();返回-1表示输入结束
     */
    typedef int typec;
    typec get_int() {
        typec res = 0, ch;
        while (!((ch = getchar()) >= '0' && ch <= '9')) {
            if (ch == EOF)
                return -1;
        }
        res = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9')
            res = res * 10 + (ch - '0');
        return res;
    }
    //输入整数(包括负整数,故不能通过返回值判断是否输入到EOF,本函数当输入到EOF时,返回-1),用法int a = get_int2();
    int get_int2() {
        int res = 0, ch, flag = 0;
        while (!((ch = getchar()) >= '0' && ch <= '9')) {
            if (ch == '-')
                flag = 1;
            if (ch == EOF)
                return -1;
        }
        res = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9')
            res = res * 10 + (ch - '0');
        if (flag == 1)
            res = -res;
        return res;
    }
    /**
     * 输入一个字符串到str中,与scanf("%s", str)类似,
     * 会忽略掉缓冲区中的空白字符。返回值为输入字符串
     * 的长度,返回-1表示输入结束。
     */
    int get_str(char *str) {
        char c;
        while ((c = getchar()) <= ' ') {
            if(c == EOF) {
                return -1;
            }
        }
        int I = 0;
        while (c > ' ') {
            str[I++] = c; c = getchar();
        }
        str[I] = 0;
        return I;
    }
    const int MAXN = 100009;
    typedef struct Evil {
        int id;
        int hp;
        Evil(int ii = 0, int hh = 0) {
            id = ii;
            hp = hh;
        }
    } Evil;
    inline bool operator<(const Evil &e1, const Evil &e2) {
        if (e1.hp != e2.hp) {
            return e1.hp > e2.hp;
        }
        return e1.id > e2.id;
    }
    
    int data[MAXN];
    int main() {
        int n, m;
        while ((n = get_int()) > 0 && (m = get_int()) > 0) {
            priority_queue<Evil> pq;
            for (int i = 0; i < n; i++) {
                data[i] = get_int();
            }
            int i = 0;
            for (; i < m; i++) {
                pq.push(Evil(i, data[i]));
            }
            printf("%d", pq.top().hp);
            for (; i < n; i++) {
                pq.push(Evil(i, data[i]));
                int j = i - m + 1;
                while (!pq.empty() && pq.top().id < j) {
                    pq.pop();
                }
                printf(" %d", pq.top().hp);
            }
            putchar('
    ');
        }
        return 0;
    }
  • 相关阅读:
    小组最终答辩
    机器学习的安全隐私
    关于Distillation as a Defense to Adversarial Perturbations against Deep Neural Networks的理解
    第十六讲-对抗样本与对抗训练3
    对抗样本机器学习_Note1_机器学习
    对抗样本机器学习_cleverhans_FGSM/JSMA
    实验四:Tensorflow实现了四个对抗图像制作算法--readme
    实验一拓展文献阅读—反向传播计算图上的微积分
    tf.placeholder 与 tf.Variable
    Robust Adversarial Examples_鲁棒的对抗样本
  • 原文地址:https://www.cnblogs.com/moonbay/p/4280620.html
Copyright © 2020-2023  润新知