题目大意:
  一个平面直角坐标系中有给定的$n(n\le50)$个红点和$m(m\le50)$个蓝点,每个点可以选择画一个半径为$r$(所有的$r$相同)的圆或不画。圆的半径上限为$R(R\le1000)$。且不同颜色的点所画成的圆不能相交,问所有圆面积的和最大是多少?

思路:
  枚举每一对不同颜色的点,求出所有可能的$r$,显然这样的$r$有$nm$个。
  对于不同颜色的点,若以$r$为半径画出的圆相交,则在这两个点之间连边,题目转化为最大独立集问题。有结论:最大独立集=点数-二分图最大匹配。用Dinic求最大匹配即可。
  对$r$排序,则每次只会增加新的边,只需要在原来的基础上进行增广即可。时间复杂度$O(n^4)$。

 #include<cmath>
#include<queue>
#include<vector>
#include<cstring>
#include<climits>
#include<algorithm>
class HouseProtection {
private:
static constexpr int N=,M=;
static constexpr double pi=M_PI;
using Point=std::pair<int,int>;
struct Length {
double l;
int u,v;
bool operator < (const Length &rhs) const {
return l<rhs.l;
}
};
struct Edge {
int from,to,remain,next;
};
Point a[N],b[N];
std::vector<Length> len;
std::vector<Edge> e;
int s,t,lev[M],cur[M],h[M];
double sqr(const double &x) const {
return x*x;
}
double dist(const Point &a,const Point &b) const {
return sqrt(sqr(a.first-b.first)+sqr(a.second-b.second));
}
void add_edge(const int &u,const int &v,const int &w) {
e.push_back({u,v,w,h[u]});
h[u]=e.size()-;
}
void bfs() {
memset(lev,-,sizeof lev);
lev[s]=;
std::queue<int> q;
q.push(s);
while(!q.empty()) {
const int &x=q.front();
for(register int i=h[x];~i;i=e[i].next) {
const int &y=e[i].to,&r=e[i].remain;
if(r&&!~lev[y]) {
lev[y]=lev[x]+;
q.push(y);
}
}
q.pop();
}
}
int dfs(const int &x,const int &flow) {
if(x==t) return flow;
for(int &i=cur[x];~i;i=e[i].next) {
const int &y=e[i].to;
if(e[i].remain&&lev[y]>lev[x]) {
if(int d=dfs(y,std::min(flow,e[i].remain))) {
e[i].remain-=d;
e[i^].remain+=d;
return d;
}
}
}
return ;
}
int dinic() {
int maxflow=;
for(;;) {
bfs();
if(!~lev[t]) break;
memcpy(cur,h,sizeof h);
while(int flow=dfs(s,INT_MAX)) {
maxflow+=flow;
}
}
return maxflow;
}
public:
double safetyFactor(const std::vector<int> &possibleXForBlue,const std::vector<int> &possibleYForBlue,const std::vector<int> &possibleXForRed,const std::vector<int> &possibleYForRed,const int &R) {
memset(h,-,sizeof h);
const int n=possibleXForBlue.size(),m=possibleXForRed.size();
for(register int i=;i<n;i++) {
a[i]={possibleXForBlue[i],possibleYForBlue[i]};
}
for(register int i=;i<m;i++) {
b[i]={possibleXForRed[i],possibleYForRed[i]};
}
for(register int i=;i<n;i++) {
for(register int j=;j<m;j++) {
const double dis=dist(a[i],b[j])/;
if(dis<R) len.push_back({dis,i,j});
}
}
len.push_back({(double)R,-,-});
std::sort(len.begin(),len.end());
s=n+m,t=n+m+;
for(int i=;i<n;i++) {
add_edge(s,i,);
add_edge(i,s,);
}
for(int i=;i<m;i++) {
add_edge(n+i,t,);
add_edge(t,n+i,);
}
int match=;
double ans=;
for(register auto &e:len) {
match+=dinic();
ans=std::max(ans,pi*sqr(e.l)*(n+m-match));
if(e.l<R) {
add_edge(e.u,n+e.v,);
add_edge(n+e.v,e.u,);
}
}
return ans;
}
};

[TC-HouseProtection]House Protection的更多相关文章

  1. ASP.NET Core 数据保护(Data Protection 集群场景)【下】

    前言 接[中篇],在有一些场景下,我们需要对 ASP.NET Core 的加密方法进行扩展,来适应我们的需求,这个时候就需要使用到了一些 Core 提供的高级的功能. 本文还列举了在集群场景下,有时候 ...

  2. ASP.NET Core 数据保护(Data Protection)【中】

    前言 上篇主要是对 ASP.NET Core 的 Data Protection 做了一个简单的介绍,本篇主要是介绍一下API及使用方法. API 接口 ASP.NET Core Data Prote ...

  3. ASP.NET Core 数据保护(Data Protection)【上】

    前言 上一篇博客记录了如何在 Kestrel 中使用 HTTPS(SSL), 也是我们目前项目中实际使用到的. 数据安全往往是开发人员很容易忽略的一个部分,包括我自己.近两年业内也出现了很多因为安全问 ...

  4. H TC並沒有成為下一個摩托羅拉或諾基亞。

    關於2014年第四季度,H T C在三季度財報說明中提到,“年度旗艦H T CO ne(M 8)與中端機型H T C D esire系列在競爭日趨激烈的智能手機市場保持穩定的銷售,市占率有所提升,延續 ...

  5. MacOS changed System Integrity Protection status

    禁止 System Integrity Protection 按住 command + R 重启系统 进入单用户模式 启动bash工具: 输入: csrutil disable 输入:reboot 启 ...

  6. "System Protection" is disabled in Win10 default settings

    We could find some important clue in Restore Point because "System Protection" of volume C ...

  7. TC(Total Commander)文件管理神器

    TC文件管理神器 Total Commander是一个会显著提高文件操作效率的工具,而文件操作是应用计算机最基本的功夫,也是伴随一生的操作.因此花一点时间学习,而会受益一世. Total Comman ...

  8. 挖掘机力矩限制器/挖掘机称重系统/挖泥机称重/Excavators load protection/Load moment indicator

    挖掘机力矩限制器是臂架型起重机机械的安全保护装置,本产品采用32位高性能微处理器为硬件平台 ,软件算法采用国内最先进的液压取力算法,该算法吸收多年的现场经验,不断改进完善而成.本产品符合<GB1 ...

  9. Process Kill Technology && Process Protection Against In Linux

    目录 . 引言 . Kill Process By Kill Command && SIGNAL . Kill Process By Resource Limits . Kill Pr ...

  10. iOS 开启data protection 的方法

    我这里说的data protection,指的是设备设置密码后,如果设备锁屏,并且当前解锁需要密码(有时可能因为自己的设定,导致会再几小时后才需要密码),这时应用程序处于加密状态,无法从外部读取.如果 ...

随机推荐

  1. Idea 怎么远程debug

    注意的问题:远程debug别人的服务器只能开一个debug,所以当你的同事比你先远程debug同一台服务器时,你应该报Error running 某某ip地址 .unable to open debu ...

  2. 普通table表格样式及代码大全

     普通table表格样式及代码大全(全)(一) 单实线边框表格 <table style="border-collapse: collapse" borderColor=#0 ...

  3. 【BZOJ2742】【HEOI2012】Akai的数学作业 [数论]

    Akai的数学作业 Time Limit: 10 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 这里是广袤无垠的宇宙这里 ...

  4. 安装vue,并新建一个项目

    Vue.js (读音 /vjuː/,类似于 view) 是一套构建用户界面的渐进式框架.与其他重量级框架不同的是,Vue 采用自底向上增量开发的设计.Vue 的核心库只关注视图层,它不仅易于上手,还便 ...

  5. 让button居中显示的的标签

    <center> <input type="button" class="buttoncls" style="width:80px& ...

  6. python--fnmatch

    import fnmatch ''' 这个库专门是用来做文件名匹配的,可以使用通配符如下 * 匹配任何数量的任意字符 ? 匹配单个数量的任意字符 [seq] 匹配seq中的任意字符 [!seq] 匹配 ...

  7. DRF基类APIView的子类GenericAPIView

    DRF的基类是APIView类,GenericAPIView类是APIView类的子类. GenericAPIView类有什么存在的意义呢? 其实, 他主要提供了两个用处: 1.提供关于数据库查询的属 ...

  8. CSS中的HSLA颜色

    CSS 中的颜色可以由RGB色彩空间和HSL色彩空间两种方式来表述.其中我们常用的是RGB色彩空间,RGB色彩空间的颜色表示方式有:十六进制颜色(如红色:#FF0000).RGB颜色(如红色:rgb( ...

  9. 简单unix 局域网的TCP会话

    client.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <e ...

  10. grep 所有多个关键字

    标签(空格分隔): Linux 多个关键字 或 关系 egrep 'CommentManager|getComment' --color catalina.log.2017-03-15 grep -E ...