题目大意:
  一个平面直角坐标系中有给定的$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. git上传本地项目

    1.(先进入项目文件夹)通过命令 git init 把这个目录变成git可以管理的仓库 git init 2.把文件添加到版本库中,使用命令 git add .添加到暂存区里面去,不要忘记后面的小数点 ...

  2. cxf+spring发布webservice和调用

    maven项目配置http://cxf.apache.org/docs/using-cxf-with-maven.html <properties> <cxf.version> ...

  3. oracle中分页的知识

    一:前言 自从出来实习后,基本上都没有按下心来总结下自己学的知识点,刚刚好现在快要国庆了,没有到深圳出差,在公司呆了三天,可以说是在公司打了三天的酱油啊,所以前两天都是在看些正则的文档,并且写了下总结 ...

  4. 汕头市队赛 yyl杯1 T2

    B SRM 05 - YYL 杯 R1 背景&&描述 有一个拥有n个城市的国家.这个国家由n-1条边连接起来.有一天国家发生叛乱.叛军已占领了一些城市.如果叛军占领的城市中,存在两个城 ...

  5. 金中欢乐赛 A题

    题目传送门 这道题就贪心.... 正的一坨和负的一坨间隔 #include<cstdio> #include<cstring> #include<algorithm> ...

  6. [Leetcode Week6]Linked List Cycle II

    Linked List Cycle II 题解 题目来源:https://leetcode.com/problems/linked-list-cycle-ii/description/ Descrip ...

  7. 关于preempt_enable 和 preempt_disable 【转】

    转自:http://blog.chinaunix.net/uid-8478094-id-2031177.html 关于preempt_enable 和 preempt_disable 允许抢占和禁止抢 ...

  8. IPython Notebook error: Error loading notebook

    打开jupyter突然报错: An unknown error occurred while loading this notebook. This version can load notebook ...

  9. 表单重置 jQuery

    //重置 $('.reset-bottom').click(function(){ $('.mui-input-clear').attr('value','');//text类型 $('input[n ...

  10. 51nod 几道题

    1001 数组中和等于K的数对 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 给出一个整数K和一个无序数组A,A的元素为N个互不相同的整数, 找出数组A中所有和等于 ...