首页 技术 正文
技术 2022年11月21日
0 收藏 520 点赞 4,901 浏览 1941 个字

和那道可重区间集一样
不过这道题可能有垂直于x轴的线段,这就很烦了,直接连会有负环,判掉又会WA
可以想办法把r端点和l端点分开,又要保证答案不变
那么直接把区间l,r都乘以2,l=r时r++,否则l++,这样r就与l分开,并且对其它没有影响(相当于在x轴上多加了点)


这道题在LOJ上可以切


如果看到了的并且有数据可以卡掉我的代码的请在下面评论

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
# define Copy(a, b) memcpy(a, b, sizeof(a))
# define Sqr(a) (1LL * (a) * (a))
using namespace std;
typedef long long ll;
# define int ll
const int _(1010), __(1e6 + 10), INF(2e9);IL ll Read(){
char c = '%'; ll x = 0, z = 1;
for(; c > '9' || c < '0'; c = getchar()) if(c == '-') z = -1;
for(; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
return x * z;
}int n, k, l[_], y_1[_], r[_], y_2[_], _w[_], o[_], len;
int cnt, fst[_], w[__], to[__], nxt[__], dis[_], vis[_], S, T, cost[__], pe[_], pv[_], max_flow, max_cost;
queue <int> Q;IL void Add(RG int u, RG int v, RG int f, RG int co){
cost[cnt] = co; w[cnt] = f; to[cnt] = v; nxt[cnt] = fst[u]; fst[u] = cnt++;
cost[cnt] = -co; w[cnt] = 0; to[cnt] = u; nxt[cnt] = fst[v]; fst[v] = cnt++;
}IL bool Bfs(){
Q.push(S); Fill(dis, 127); dis[S] = 0; vis[S] = 1;
while(!Q.empty()){
RG int u = Q.front(); Q.pop();
for(RG int e = fst[u]; e != -1; e = nxt[e]){
if(!w[e] || dis[to[e]] <= dis[u] + cost[e]) continue;
dis[to[e]] = dis[u] + cost[e];
pe[to[e]] = e; pv[to[e]] = u;
if(!vis[to[e]]) vis[to[e]] = 1, Q.push(to[e]);
}
vis[u] = 0;
}
if(dis[T] >= dis[T + 1]) return 0;
RG int ret = INF;
for(RG int u = T; u != S; u = pv[u]) ret = min(ret, w[pe[u]]);
for(RG int u = T; u != S; u = pv[u]) w[pe[u]] -= ret, w[pe[u] ^ 1] += ret;
max_cost -= ret * dis[T]; max_flow += ret;
return 1;
}
# undef int
int main(RG int argc, RG char *argv[]){
# define int ll
Fill(fst, -1); n = Read(); k = Read();
for(RG int i = 1; i <= n; ++i){
l[i] = Read(); y_1[i] = Read(); r[i] = Read(); y_2[i] = Read();
_w[i] = sqrt(Sqr(l[i] - r[i]) + Sqr(y_1[i] - y_2[i]));
if(l[i] > r[i]) swap(l[i], r[i]), swap(y_1[i], y_2[i]);
l[i] <<= 1; r[i] <<= 1;
if(l[i] == r[i]) ++r[i];
else ++l[i];
}
for(RG int i = 1; i <= n; ++i) o[++len] = l[i], o[++len] = r[i];
sort(o + 1, o + len + 1); len = unique(o + 1, o + len + 1) - o - 1;
T = len + 1;
for(RG int i = 0; i <= len; ++i) Add(i, i + 1, k, 0);
for(RG int i = 1; i <= n; ++i){
l[i] = lower_bound(o + 1, o + len + 1, l[i]) - o;
r[i] = lower_bound(o + 1, o + len + 1, r[i]) - o;
Add(l[i], r[i], 1, -_w[i]);
}
while(Bfs()); printf("%lld\n", max_cost);
return 0;
}
上一篇: NOIWC2018游记
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,965
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,486
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,331
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,114
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,747
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,781