BZOJ2960:跨平面
题面
Sol
对该平面图的对偶图建图后就是最小树形图,建一个超级点向每个点连 \(inf\) 边即可
怎么转成对偶图,怎么弄出多边形
把边拆成两条有向边,分别挂在两个点上
每个点的出边按角度排序
每次选择一个没有标记过的边做 \(DFS\)
从 \(u\) 到 \(v\),然后 \(v\) 选择 \((v,u)\) 顺时针转的下一条边,最后跑到原来的点,此时一定有一个多边形形成,记录编号后标记在边上即可
# include <bits/stdc++.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
const int maxn(100005);
const int inf(1e9);
namespace MST{
int n, cnt, pre[maxn], vis[maxn], id[maxn], ans, inw[maxn], sum, rt;
struct Edge{
int u, v, w;
} e[maxn];
IL void Add(RG int u, RG int v, RG int w){
e[++cnt] = (Edge){u, v, w};
}
IL int DirectedMST(){
for(RG int i = 1; i <= cnt; ++i) sum += e[i].w;
ans -= (++sum);
for(RG int i = 1; i <= n; ++i) Add(n + 1, i, sum);
rt = ++n;
while(true){
RG int idx = 0;
for(RG int i = 1; i <= n; ++i) pre[i] = id[i] = vis[i] = -1, inw[i] = inf;
for(RG int i = 1; i <= cnt; ++i)
if(e[i].u != e[i].v && e[i].w < inw[e[i].v]) inw[e[i].v] = e[i].w, pre[e[i].v] = e[i].u;
inw[rt] = 0, pre[rt] = rt;
for(RG int i = 1; i <= n; ++i){
ans += inw[i];
if(vis[i] == -1){
RG int x = i;
while(vis[x] == -1) vis[x] = i, x = pre[x];
if(x != rt && vis[x] == i){
id[x] = ++idx;
for(RG int j = pre[x]; j != x; j = pre[j]) id[j] = idx;
}
}
}
if(!idx) break;
for(RG int i = 1; i <= n; ++i) if(id[i] == -1) id[i] = ++idx;
for(RG int i = 1; i <= cnt; ++i)
e[i].w -= inw[e[i].v], e[i].u = id[e[i].u], e[i].v = id[e[i].v];
n = idx, rt = id[rt];
}
return ans;
}
}
struct Line{
int u, v, id, type;
double k;
IL int operator <(RG Line b) const{
return k < b.k;
}
} line[maxn];
struct Point{
int x, y;
} a[maxn];
struct Edge{
int u, v, next, type, id;
} edge[maxn];
int n, m, num, first[maxn], cnt, mat[2][maxn], vis[maxn], val[2][maxn];
IL void Add(RG int u, RG int v, RG int type, RG int id){
edge[cnt] = (Edge){u, v, first[u], type, id}, first[u] = cnt++;
}
IL int Dfs(RG int u, RG int ff){
if(vis[u]) return ++MST::n;
for(RG int e = first[u]; e != -1; e = edge[e].next){
RG int v = edge[e].v, id, type;
if(v == ff){
e = edge[e].next;
if(e == -1) e = first[u];
v = edge[e].v, id = edge[e].id, type = edge[e].type;
return mat[type][id] = Dfs(v, u);
}
}
return 0;
}
int main(){
n = Input(), m = Input();
for(RG int i = 1; i <= n; ++i) first[i] = -1;
for(RG int i = 1; i <= n; ++i) a[i].x = Input(), a[i].y = Input();
for(RG int i = 1, x, y; i <= m; ++i){
x = Input(), y = Input(), val[0][i] = Input(), val[1][i] = Input();
line[++num] = (Line){x, y, i, 0}, line[num].k = atan2(a[y].y - a[x].y, a[y].x - a[x].x);
line[++num] = (Line){y, x, i, 1}, line[num].k = atan2(a[x].y - a[y].y, a[x].x - a[y].x);
}
sort(line + 1, line + num + 1);
for(RG int i = 1; i <= num; ++i) Add(line[i].u, line[i].v, line[i].type, line[i].id);
for(RG int i = 0; i < cnt; ++i)
if(!mat[edge[i].type][edge[i].id]){
vis[edge[i].u] = 1;
mat[edge[i].type][edge[i].id] = Dfs(edge[i].v, edge[i].u);
vis[edge[i].u] = 0;
}
for(RG int i = 1; i <= m; ++i){
if(val[0][i]) MST::Add(mat[0][i], mat[1][i], val[0][i]);
if(val[1][i]) MST::Add(mat[1][i], mat[0][i], val[1][i]);
}
printf("%d\n", MST::DirectedMST());
return 0;
}
BZOJ2960:跨平面的更多相关文章
- BZOJ2960: 跨平面
从一条边出发遍历,每次找旋转角度最小的一条边作为下一条边,直到回到出发的边,就得到了一个区域.这样建出对偶图后跑不定根的最小树形图就行了. #include<bits/stdc++.h> ...
- 高速LVDS电平简介
一.LVDS简介 1.1.LVDS信号介绍LVDS:Low Voltage Differential Signaling,低电压差分信号.LVDS传输支持速率一般在155Mbps(大约为77MHZ)以 ...
- PCB设计工程师面试题
网上的一套PCB设计工程师面试题,测下你能不能拿90分? [复制链接] 一.填空 1.PCB上的互连线按类型可分为()和() . 2.引起串扰的两个因素是()和(). 3.EMI ...
- layout焊盘过孔大小的设计标准
PCB设计前准备 1.准确无误的原理图.包括完整的原理图文件和网表,带有元件编码的正式的BOM.原理图中所有器件的PCB封装(对于封装库中没有的元件,硬件工程师应提供datasheet或者实物,并指定 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 最小割&网络流应用
重要链接 基础部分链接 : 二分图 & 网络流初步 zzz大佬博客链接 : 网络流学习笔记 重点内容:最小割二元关系新解(lyd's ppt) 题目:网络流相关题目 lyd神犇课件链接 : 网 ...
- 平面内,线与线 两条线找交点 两条线段的位置关系(相交)判定与交点求解 C#
个人亲自编写.测试,可以正常使用 道理看原文,这里不多说 网上找到的几篇基本都不能用的 C#代码 bool Equal(float f1, float f2) { return (Math ...
- 在路上:安全公司“跨界”SD-WAN
编者按:本文是SDNLAB“企业+”特别报道之一.“企业+”是SDNLAB重点打造的栏目,汇聚信息行业运营商.设备商.互联网公司.软件公司.集成公司.融创投资公司.科研院所等企业,重新定义IT行业撮合 ...
- Luogu P1429 平面最近点对 【分治】By cellur925
题目传送门 题目大意:给定平面上n个点,找出其中的一对点的距离,使得在这n个点的所有点对中,该距离为所有点对中最小的.$n$<=100000. $Algorithm$ 最朴素的$n^2$枚举肯定 ...
随机推荐
- 【1】JMicro微服务-RPC体验
如非授权,禁止用于商业用途,转载请注明出处作者:mynewworldyyl JMICRO运行简单服务提供者和消费者 1. 下载源代码 git checkout https://github.com/m ...
- 50.RocketMQ (quickstart)
要多给下属表功,绝不能抢功. 1.订阅消息 /** * Copyright (C) 2010-2013 Alibaba Group Holding Limited * * Licensed under ...
- 45.oracle表类型、数据拆分、表分区
不要做一些没有意义的事情,就比如说你要离职并不打算吃回头草,离职理由中完全没有必要说明“领导的水平太渣,人品太差”此类的原因,而是“个人原因”,当然实在不批准辞职另说. oracle表类型 表的类型分 ...
- 架构师养成记--18.NIO
有人叫new IO 我这里就叫Non-block IO 经典概念: Buffer(缓冲区):之前直接通过流,现在提供一个buffer存放数据. Channel:管道,包括ServerSocketCha ...
- 2016级算法期末上机-A.简单·Bamboo's Fight with DDLs I
简单·Bamboo's Fight with DDLs I 分析 一句话:要装满的完全背包问题. 对比完全背包只有一点要改变:初始化为负无穷 传送门: https://buaacoding.cn/pr ...
- 集合之五:Set接口(答案)
package com.shsxt.homework; import java.util.ArrayList; import java.util.Collection; import java.uti ...
- panda的query过滤
pandas中可以用query函数以类SQL语言执行查询.
- windows下python3.7.2内置venv虚拟环境下pyinstaller错误问题
起因 开发一直使用python -m venv .pyenv 方式创建虚拟环境,在利用pyinstaller打包发布应用时,出现错误 3178 INFO: Warnings written to C: ...
- This operation is not available unless admin mode is enabled: FLUSHDB
报错: This operation is not available unless admin mode is enabled: FLUSHDB 参考内容: https://www.cnblogs ...
- Sql语句里的递归查询 SqlServer2005和Oracle 两个版本
以前使用Oracle,觉得它的递归查询很好用,就研究了一下SqlServer,发现它也支持在Sql里递归查询举例说明:SqlServer2005版本的Sql如下:比如一个表,有id和pId字段,id是 ...