Codeforces 839E Mother of Dragons
题
OvO http://codeforces.com/contest/839/problem/E
(Codeforces Round #428 (Div. 2) - E)
解
首先,k肯定是要平均分给这图中的一个最大团,
粗略的证明如下

然后,可以通过BronKerbosch算法求极大团,然后从极大团中找出最大的团,就是最大团,
All表示当前团中元素的集合,Some表示候选元素的集合(Some中任意元素都与All中所有元素有边),None元素表示已选的元素的集合(None中任意元素与All中的所有元素都有边)(None是用于去重的),
当Some和None都为空的时候,All就是一个极大团。
u节点用于优化。
具体实现在代码中,这算法贼简洁。
(思路来源于瞟了一眼某大佬的代码)
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector> using namespace std; const int N=55;
const int M=11111; struct node{
int u,v;
int next;
}edge[N*N]; int n,k,num;
int head[N];
int g[N][N];
int mx;
int All[M][N],Some[M][N],None[M][N]; void addedge(int u,int v)
{
edge[num].u=u;
edge[num].v=v;
edge[num].next=head[u];
head[u]=num++;
} void init()
{
mx=0;
num=0;
memset (head,-1,sizeof(head));
memset(g,0,sizeof(g));
} void BronKerbosch(int id,int lenAll,int lenSome,int lenNone)
{
// cout<<"id: "<<id<<" lenAll: "<<lenAll<<" lenSome: "<<lenSome<<" lenNone: "<<lenNone<<endl;
if(lenSome==0 && lenNone==0)
{
if(lenAll>mx)
mx=lenAll;
return ;
}
if(lenSome==0)
return ;
int i,j,u,v,tid,tlenAll,tlenSome,tlenNone;
u=Some[id][1]; tid=id+1;
for(i=1;i<=lenSome;i++)
{
v=Some[id][i];
if(g[u][v]) continue;
tlenAll=lenAll+1;
for(j=1;j<=lenAll;j++)
All[tid][j]=All[id][j];
All[tid][tlenAll]=v;
tlenSome=0;
for(j=1;j<=lenSome;j++)
if(g[v][Some[id][j]])
Some[tid][++tlenSome]=Some[id][j];
tlenNone=0;
for(j=1;j<=lenNone;j++)
if(g[v][None[id][j]])
None[tid][++tlenNone]=None[id][j];
BronKerbosch(tid,tlenAll,tlenSome,tlenNone);
}
} void solve()
{
int i,j;
for(i=1;i<=n;i++)
Some[0][i]=i;
BronKerbosch(0,0,n,0);
} int main()
{
int i,j;
init();
scanf("%d%d",&n,&k);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
scanf("%d",&g[i][j]);
if(g[i][j]==1)
addedge(i,j);
}
solve();
double ans=1.0*(mx-1)*mx/2*(1.0*k/mx)*(1.0*k/mx);
printf("%.10lf\n",ans);
return 0;
}
Codeforces 839E Mother of Dragons的更多相关文章
- Codeforces 839E Mother of Dragons【__builtin_popcount()的使用】
E. Mother of Dragons time limit per test:2 seconds memory limit per test:256 megabytes input:standar ...
- Codeforces 839E Mother of Dragons(极大团)
[题目链接] http://codeforces.com/contest/839/problem/E [题目大意] 现在有一些点,现在你有k的液体,随意分配给这些点, 当两个点有边相连的时候,他们能产 ...
- 【CF839E】Mother of Dragons 折半状压
[CF839E]Mother of Dragons 题意:给你一张n个点,m条边的无向图.你有k点能量,你可以把能量分配到任意一些点上,每个点分到的能量可以是一个非负实数.定义总能量为:对于所有边&l ...
- Codeforces Round #428 (Div. 2)E. Mother of Dragons
http://codeforces.com/contest/839/problem/E 最大团裸题= =,用Bron–Kerbosch算法,复杂度大多博客上没有,维基上查了查大约是O(3n/3) 最大 ...
- CF839E Mother of Dragons 最大团 Bron-Kerbosch算法
题意简述 给你一个\(n\)个节点的无向图\(G=\{V,E\}\)的邻接矩阵\(g\)和每个点的点权为\(s_i\),且\(\sum_{i=1}^n s_i = K\),要你求出\(\mathrm{ ...
- Codeforces Round #428 (Div. 2) 题解
题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部 ...
- TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E
传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...
- 22. CTF综合靶机渗透(十五)
靶机说明: Game of Thrones Hacking CTF This is a challenge-game to measure your hacking skills. Set in Ga ...
- 长春理工大学第十四届程序设计竞赛(重现赛)M.Orx Zone
链接:https://ac.nowcoder.com/acm/contest/912/M 题意: Daenerys Stormborn, 风暴中出生的丹尼莉丝,the Unburnt, 烧不死的,Qu ...
随机推荐
- Python链表操作(实现)
Python链表操作 在Python开发的面试中,我们经常会遇到关于链表操作的问题.链表作为一个非常经典的无序列表结构,也是一个开发工程师必须掌握的数据结构之一.在本文中,我将针对链表本身的数据结构特 ...
- Gson格式转换Integer变为Double类型问题解决
问题描述 在前后端分离的开发模式下,前后端交互通常采用JSON格式数据.自然会涉及到json字符串与JAVA对象之间的转换.实现json字符串与Java对象相互转换的工具很多,常用的有Json.Gso ...
- k8s-部署及介绍
Kubernetes主要功能: 数据卷 Pod中容器之间共享数据,可以使用数据卷. 应用程序健康检查 容器内服务可能进程堵塞无法处理请求,可以设置监控检查策略保证应用健壮性. 复制应用程序 ...
- 3-Perl 基础语法
Perl 基础语法Perl借用了C.sed.awk.shell脚本以及很多其他编程语言的特性,语法与这些语言有些类似,也有自己的特点.Perl 程序有声明与语句组成,程序自上而下执行,包含了循环,条件 ...
- Atcoder-SoundHound Inc.Contest 2018 -Masters Tournament-比赛报告
A C++ Example #include <iostream> #include <cstdio> #include <cstdlib> #include &l ...
- opencv+ linux + cmake 生成 opencv静态库
您可以省去如下步骤,直接下载我编译好的: http://download.csdn.net/detail/u011258240/9710331 一.编译opencv2.4 不带contrib 1. ...
- 使用脚本启动fabric时出错
Error: got unexpected status: BAD_REQUEST -- error authorizing update: error validating ReadSet: rea ...
- Linux监控服务并主动重启
Linux查询后台进程,如果没有进程号,则重启服务: #!/bin/sh basepath=$(cd ``; pwd) while true do procnum=`ps -ef|grep " ...
- IPC之shm.c源码解读
// SPDX-License-Identifier: GPL-2.0 /* * linux/ipc/shm.c * Copyright (C) 1992, 1993 Krishna Balasubr ...
- Hive优化(十一)
Hive优化 Hive的存储层依托于HDFS,Hive的计算层依托于MapReduce,一般Hive的执行效率主要取决于SQL语句的执行效率,因此,Hive的优化的核心思想是MapReduce的优 ...