当前位置: 首页 > news >正文

day27T2改错记

题面

平面上有\(n\)个点\((x_i, y_i)\),每个点两种权值\(a_i, b_i\)\(m\)条边连接这\(n\)个点,每条边权值\(c_i\)

边把平面分成很多块,每个块两种权值\(A_i, B_i\)\(A_i\)是它边界上所有点\(a_i\)之和,\(B_i\)是它边界上所有点\(b_i\)之和(最外面的无穷域边界认为是凸包上的点)

每个块可以选择\(A_i\)\(B_i\)一种权值加入收益,如果两个相邻的块权值种类不同,收益扣除它们之间的边的权值

求最大收益

\(n \le 4e4, m \le 2e5, |x_i|, |y_i| \le 2e4, 0 \le c_i \le 1e6, 0 \le a_i, b_i \le 1e3\)

保证分割出的块数\(C \le 4e4\)

解析

显然的平面图转对偶图,然后就可以跑最小割了

然后建图建错了,数据仁慈给了\(52pts\)

但是复杂度\(O(n + m \log m + maxflow(C, m + C))\)居然真的能跑过……

果然网络流复杂度是\(O(?)\)的……

代码

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#define MAXN 40005
#define MAXM 200005

typedef long long LL;
const double PI = acos(-1);
const LL INF = 0x3f3f3f3f3f3f3f3f;
struct Graph {
    struct Edge {
        int v, next; LL cap;
        Edge(int _v = 0, int _n = 0, LL _c = 0):v(_v), next(_n), cap(_c) {}
    } edge[(MAXN + MAXM) << 2];
    int head[MAXN << 1], dep[MAXN << 1], cur[MAXN << 1], cnt, S, T;
    void init() { memset(head, -1, sizeof head); cnt = 0; }
    void add_edge(int u, int v, LL c) { edge[cnt] = Edge(v, head[u], c); head[u] = cnt++; }
    void insert(int u, int v, LL c) { add_edge(u, v, c); add_edge(v, u, 0); }
    bool bfs();
    LL dfs(int, LL);
    LL dinic();
};
struct Point {
    int x, y, a, b;
};
struct Vector {
    int v, cost; double ang;
    Vector(int = 0, int = 0, int = 0);
    bool operator <(const Vector &v) const { return ang < v.ang; }
};

char gc();
int read();
void build();

Vector E[MAXM << 1];
Graph G;
std::vector<int> g[MAXN];
Point pt[MAXN];
int N, M, NUM, tot;
int bel[MAXM << 1], next[MAXM << 1];
LL val1[MAXN], val2[MAXN];
bool vis[MAXM << 1];

bool cmp(const int &a, const int &b) { return E[a].ang < E[b].ang; }

int main() {
    freopen("everfeel.in", "r", stdin);
    freopen("everfeel.out", "w", stdout);

    NUM = read(), N = read(), M = read();
    for (int i = 1; i <= N; ++i)
        pt[i].x = read(), pt[i].y = read(), pt[i].a = read(), pt[i].b = read();
    for (int i = 0; i < M; ++i) {
        int u = read(), v = read(), c = read();
        E[i << 1] = Vector(u, v, c), g[u].push_back(i << 1);
        E[i << 1 | 1] = Vector(v, u, c), g[v].push_back(i << 1 | 1);
    }
    build();
    //memory test
    //while(1);
    if ((NUM > 2 && NUM < 7) || (NUM > 10 && NUM < 13) || (NUM > 16 && NUM < 20)) {
        LL ans = 0;
        for (int i = 1; i <= tot; ++i) ans += std::max(val1[i], val2[i]);
        printf("%lld\n", ans);
    } else {
        LL ans = 0;
        for (int i = 1; i <= tot; ++i) ans += val1[i] + val2[i];
        printf("%lld\n", ans - G.dinic());
    }

    return 0;
}
inline char gc() {
    static char buf[1000000], *p1, *p2;
    if (p1 == p2) p1 = (p2 = buf) + fread(buf, 1, 1000000, stdin);
    return p1 == p2 ? EOF : *p2++;
}
inline int read() {
    int res = 0, op; char ch = gc();
    while (ch != '-' && (ch < '0' || ch > '9')) ch = gc();
    op = (ch == '-' ? ch = gc(), -1 : 1);
    while (ch >= '0' && ch <= '9') res = (res << 1) + (res << 3) + ch - '0', ch = gc();
    return res * op;
}
Vector::Vector(int _u, int _v, int _c):v(_v), cost(_c) { ang = atan2(pt[_v].y - pt[_u].y, pt[_v].x - pt[_u].x); }
void build() {
    for (int i = 1; i <= N; ++i) std::sort(g[i].begin(), g[i].end(), cmp);
    for (int i = 0; i < (M << 1); ++i) {
        int v = E[i].v;
        std::vector<int>::iterator it = ++std::lower_bound(g[v].begin(), g[v].end(), i ^ 1, cmp);
        if (it == g[v].end()) it = g[v].begin();
        next[i] = *it;
    }
    for (int i = 0; i < (M << 1); ++i) if (!vis[i]) {
        ++tot;
        for (int j = i; !vis[j]; j = next[j]) vis[j] = 1, bel[j] = tot;
    }
    G.init();
    for (int i = 0; i < (M << 1); ++i) {
        int u = bel[i], v = bel[i ^ 1], c = E[i].cost;
        val1[u] += (LL)pt[E[i].v].a, val2[u] += (LL)pt[E[i].v].b;
        if (u > v) continue;
        G.add_edge(u, v, c), G.add_edge(v, u, c);
    }
    for (int i = 1; i <= tot; ++i) {
        G.insert(0, i, val1[i]);
        G.insert(i, tot + 1, val2[i]);
    }
    G.S = 0, G.T = tot + 1;
}
bool Graph::bfs() {
    static int q[MAXN], hd, tl;
    hd = tl = 0;
    memset(dep, 0, sizeof dep);
    q[tl++] = S, dep[S] = 1;
    while (hd < tl) {
        int p = q[hd++];
        if (p == T) return 1;
        for (int i = head[p]; ~i; i = edge[i].next)
            if (edge[i].cap && !dep[edge[i].v]) {
                dep[edge[i].v] = dep[p] + 1;
                q[tl++] = edge[i].v;
            }
    }
    return 0;
}
LL Graph::dfs(int u, LL maxflow) {
    if (u == T) return maxflow;
    LL res = 0;
    for (int &i = cur[u]; ~i; i = edge[i].next)
        if (edge[i].cap && dep[edge[i].v] == dep[u] + 1) {
            LL d = dfs(edge[i].v, std::min(edge[i].cap, maxflow));
            if (d) {
                res += d, maxflow -= d;
                edge[i].cap -= d, edge[i ^ 1].cap += d;
                if (!maxflow) break;
            }
        }
    if (!res) dep[u] = -1;
    return res;
}
LL Graph::dinic() {
    LL res = 0;
    while (bfs()) {
        memcpy(cur, head, sizeof head);
        res += dfs(S, INF);
    }
    return res;
}
//Rhein_E O(?)

转载于:https://www.cnblogs.com/Rhein-E/p/10627278.html

相关文章:

  • 《深度学习入门基于Python的理论与实现》PDF及代码+《21个项目玩转深度学习》PDF及代码+原理到实践总结...
  • 一些常用的正则表达式示例
  • C++学习(三十四)(C语言部分)之 链表
  • RIpng配置(GNS3)(第九组)
  • halcon预处理函数
  • [博弈论]
  • 一个正在读本科的计院学生
  • 排序算法之快速排序QuickSort
  • CSS中一个冒号和两个冒号有什么区别
  • MSF内网渗透 扫描模块
  • [转帖]安德斯·海尔斯伯格
  • [转帖]Linux分页机制之概述--Linux内存管理(六)
  • Linux的远程连接工具:SSH的安装
  • Spring Reference
  • 【大数据应用技术】作业七|爬取全部的校园新闻
  • Angular Elements 及其运作原理
  • CNN 在图像分割中的简史:从 R-CNN 到 Mask R-CNN
  • HTTP 简介
  • Java基本数据类型之Number
  • k个最大的数及变种小结
  • LeetCode算法系列_0891_子序列宽度之和
  • magento2项目上线注意事项
  • ng6--错误信息小结(持续更新)
  • Python学习之路13-记分
  • React16时代,该用什么姿势写 React ?
  • React系列之 Redux 架构模式
  • Spring核心 Bean的高级装配
  • 纯 javascript 半自动式下滑一定高度,导航栏固定
  • 力扣(LeetCode)56
  • 数据科学 第 3 章 11 字符串处理
  • 在weex里面使用chart图表
  • 智能情侣枕Pillow Talk,倾听彼此的心跳
  • ​LeetCode解法汇总2670. 找出不同元素数目差数组
  • $(document).ready(function(){}), $().ready(function(){})和$(function(){})三者区别
  • (10)STL算法之搜索(二) 二分查找
  • (70min)字节暑假实习二面(已挂)
  • (ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY)讲解
  • (安卓)跳转应用市场APP详情页的方式
  • (动手学习深度学习)第13章 计算机视觉---图像增广与微调
  • (切换多语言)vantUI+vue-i18n进行国际化配置及新增没有的语言包
  • ./和../以及/和~之间的区别
  • .jks文件(JAVA KeyStore)
  • .mysql secret在哪_MySQL如何使用索引
  • .net core Swagger 过滤部分Api
  • .NET Core 控制台程序读 appsettings.json 、注依赖、配日志、设 IOptions
  • .net framwork4.6操作MySQL报错Character set ‘utf8mb3‘ is not supported 解决方法
  • .NET 设计模式—简单工厂(Simple Factory Pattern)
  • .NET 中各种混淆(Obfuscation)的含义、原理、实际效果和不同级别的差异(使用 SmartAssembly)
  • .NET开发者必备的11款免费工具
  • .net下简单快捷的数值高低位切换
  • @Not - Empty-Null-Blank
  • [ C++ ] template 模板进阶 (特化,分离编译)
  • [100天算法】-每个元音包含偶数次的最长子字符串(day 53)
  • [ABC294Ex] K-Coloring
  • [AIGC] 开源流程引擎哪个好,如何选型?