zoukankan      html  css  js  c++  java
  • UOJ#386. 【UNR #3】鸽子固定器(链表)

    题意

    题目链接

    为了固定S**p*鸽鸽,whx和zzt来到鸽具商店选购鸽子固定器。

    鸽具商店有 nn 个不同大小的固定器,现在可以选择至多 mm 个来固定S**p*鸽鸽。每个固定器有大小 sisi 和牢固程度 vivi。

    如果他们选购的固定器大小不一或是不牢固,固定S**p*鸽鸽的时候肯定会很头疼,所以定义选择的物品总牢固程度和的 dvdv 次方减大小极差的 dsds 次方为这个方案的价值,求不同选购方案中,价值的最大值。

    Sol

    非常好的一道猜结论

    如果我们按$s$排序后,我们就可以枚举$max   s_i$和$min s_i$

    考虑到$M$很小,对于长度$leqslant M$的部分直接暴力枚举

    那长度$ > M$的呢?很显然,我们需要暴力里面$v$值较大的点

    因此我们用一个链表维护处所有的数,然后从小到大枚举$v$值,同时枚举一下能覆盖到它的区间来更新答案

    #include<cstdio>
    #include<algorithm>
    #include<queue>
    #define Pair pair<int, int> 
    #define MP(x, y) make_pair(x, y)
    #define fi first
    #define se second
    #define LL long long
     #define int long long  
    using namespace std;
    const int MAXN = 2 * 1e5 + 10, B = 25000;
    inline int read() {
        char c = getchar(); int x = 0, f = 1;
        while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
        while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x * f;
    }
    int N, M, ds, dv;
    int l[MAXN], r[MAXN];
    LL Get(LL x, int opt) {
        if(opt == 1) return x;
        else return x * x;
    }
    struct Node {
        int s, v;
        bool operator < (const Node &rhs) const {
            return s == rhs.s ? v < rhs.v : s < rhs.s;
        }
    }a[MAXN];
    main() {
        priority_queue<Pair> q;
        N = read(); M = read(); ds = read(); dv = read();
        for(int i = 1; i <= N; i++) {
            a[i].s = read(), a[i].v = read(); // 澶у皬 / 鐗㈠浐绋嬪害
            
        }
        sort(a + 1, a + N + 1);
        for(int i = 1; i <= N; i++) {
            q.push(MP(-a[i].v, i));
        }
        int ans = 0;
        for(int i = 1; i <= N; i++) {
            int sum = 0;
            for(int j = i; j <= i + M - 1 && j <= N; j++) {
                sum += a[j].v;
                ans = max(ans, Get(sum, dv) - Get(a[j].s - a[i].s, ds));
            }
        }
      // printf("%d
    ", ans);
        for(int i = 1; i <= N; i++) r[i] = i + 1, l[i] = i - 1;
        while(!q.empty()) {
         //   printf("%d
    ", q.top().fi);
            int pos = q.top().se; q.pop();
            int sum = a[pos].v, x = pos, y = pos;
            for(int j = 1; j < M; j++) {
                if(l[x]) x = l[x], sum += a[x].v;
                else if(r[y] <= N) y = r[y], sum += a[y].v;
            }
            while(x != r[pos] && y <= N) {
                ans = max(ans, Get(sum, dv) - Get(a[y].s - a[x].s, ds));
                sum -= a[x].v;
                x = r[x]; y = r[y];
                sum += a[y].v;
            }
            r[l[pos]] = r[pos];
            l[r[pos]] = l[pos];
        }
        printf("%lld", ans);
        
        return 0;
    }
    /*
    */
  • 相关阅读:
    Spring Boot中常用的三个注解
    Idea插件
    Java微服务 在 Linux 环境启停Shell脚本
    注解
    Oracle树状结构层级查询
    zabbix安装部署(server部分)
    zabbix监控系统客户端安装
    Windows 用bat脚本带配置启动redis,并用vb脚本使其在后台运行。
    svn cleanup failed–previous operation has not finished; run cleanup if it was interrupted
    PHP网页显示乱码问题总结
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/9630391.html
Copyright © 2011-2022 走看看