codeforces #309 div1 D
求最小值最大显然是要二分
二分之后转换成了判定性问题
我们考虑哪些点一定不能选
显然是将所有可选点选中之后依然不满足条件的点不能选
那么我们不妨维护一个堆,每次取出堆顶看看是否满足条件
不满足条件就pop掉,并进行松弛
最后判定堆是否为空即可
另外,其实这道题思考到这里我们会发现二分并没有什么卵用,可以去掉二分省掉一个log
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<queue>
using namespace std;const int maxn=100010;
int n,m,k,x,u,v,tot;
bool vis[maxn];
bool check[maxn];
int deg[maxn];
int sum[maxn];
int ans[maxn];
int h[maxn],cnt=0;
struct edge{int to,next;
}G[maxn<<1];struct pos{double k;//����int now;//��ǰ��pos(double k=0,int now=0):k(k),now(now){}bool operator <(const pos &A)const{return k>A.k;}
};priority_queue<pos>Q;void add(int x,int y){++cnt;G[cnt].to=y;G[cnt].next=h[x];h[x]=cnt;}bool Get_check(double k){memset(check,0,sizeof(check));memset(deg,0,sizeof(deg));while(!Q.empty())Q.pop();for(int u=1;u<=n;++u){if(vis[u])continue;for(int i=h[u];i;i=G[i].next){int v=G[i].to;if(vis[v])continue;deg[v]++;}}for(int i=1;i<=n;++i){if(vis[i])continue;Q.push(pos((double)(deg[i])/sum[i],i));}while(!Q.empty()){while(!Q.empty()&&check[Q.top().now])Q.pop();if(Q.empty())break;pos tmp=Q.top();if(tmp.k>=k)break;int u=tmp.now;check[u]=true;for(int i=h[u];i;i=G[i].next){int v=G[i].to;if(check[v]||vis[v])continue;deg[v]--;Q.push(pos((double)(deg[v])/sum[v],v));}}if(Q.empty())return false;return true;
}int main(){scanf("%d%d%d",&n,&m,&k);for(int i=1;i<=k;++i){scanf("%d",&x);vis[x]=true;}for(int i=1;i<=m;++i){scanf("%d%d",&u,&v);add(u,v);add(v,u);sum[u]++;sum[v]++;}double L=0,R=1;for(int i=1;i<=50;++i){double mid=(L+R)/2;if(Get_check(mid))L=mid;else R=mid;}Get_check(L);tot=0;for(int i=1;i<=n;++i){if(check[i]||vis[i])continue;ans[++tot]=i;}printf("%d\n",tot);for(int i=1;i<=tot;++i)printf("%d ",ans[i]);return 0;
}
转载于:https://www.cnblogs.com/joyouth/p/5362005.html
codeforces #309 div1 D相关推荐
- codeforces round 309 div1 Nudist Beach 二分+搜索
题目描述:给出一个有n(1<=n<=1e5)个点m(1<=m<=1e5)条边的无向图,其中有k个点为堡垒,现在要求占领除堡垒外的一些点作为我方据点,未被占领的点视为敌方据点,使 ...
- 【Codeforces #167 Div1 Div2】Solutions
[A. Dima and Friends] http://www.codeforces.com/contest/272/problem/A 题目大意:n+1个人出手指头,加起来再做类似约瑟夫的出圈,问 ...
- codeforces #310 div1 C
操作无论是U还是L,都会使原图形分裂成两个图形,且两个图形的操作互不影响 我们又发现由于操作点只可能在下斜线上,如果将操作按x排序 那么无论是U还是L,都会将操作序列完整分割成两半,且两个操作序列互不 ...
- CodeForces:103(div1)104(div2)
文章目录 前言 CF104A Blackjack Description\text{Description}Description Solution\text{Solution}Solution Co ...
- CodeForces:372(div1)div373(div2)
文章目录 前言 CF373A Collecting Beats is Fun Description\text{Description}Description Solution\text{Soluti ...
- CodeForces:1103(div1)1104(div2)
文章目录 前言 CF1104A Splitting into digits Description\text{Description}Description Solution\text{Solutio ...
- CodeForces:749(div1)750(div2)
文章目录 前言 CF450A Jzzhu and Children Description\text{Description}Description Solution\text{Solution}So ...
- CodeForces: 360(div1)361(div2)
文章目录 前言 CF361A Levko and Table Description\text{Description}Description Solution\text{Solution}Solut ...
- codeforces:1361(div1)1362(div2):总结
文章目录 前言 1362-A. Johnny and Ancient Computer 解析 1362-B - Johnny and His Hobbies 解析 1362-C - Johnny an ...
最新文章
- 一劳永逸,iOS 网页视图控制器通用类封装
- Linux JQ 命令学习笔记
- 人一样自然流畅地说话,下一代智能对话系统还有多长的路要走?
- 【深度学习下一大突破】吴恩达对话 Hinton、Bengio、Goodfellow(视频)
- Java 集合 之 房屋出租实例
- IDEA 配置Maven项目
- 思科路由器Ez×××解决地址重叠测试
- 模电实验——实验四 RC正弦波振荡器
- 一级计算机考试电子表格排序筛选,重新应用Excel排序和筛选或清除筛选
- wav转mp3 c语言源码,C/C++知识点之mp3格式转wav格式 附完整C++算法实现代码
- 【漏洞扫描与复现】Kali之Metasploit渗透测试
- 我怎样从珍爱网拿回18800会员费:交友平台相亲不靠谱
- 人工智能机器学习入门资料免费送
- Android布局原理与优化
- 动态规划经典问题--TSP问题
- Smartbi自定义生成报表-制作流程
- 中国内地城市CA分布
- iphone7plus计算机,iPhone 7 Plus人像模式有多强大?看看就知道了
- 轻度Linux患者福利,Win10安装Linux子系统教程,附 Docker 安装教程
- HC-05 蓝牙 2.0 串口模块
热门文章
- Drools 文档(目录)
- 论 Java 中的内存分配
- ssh开发所需要的架包
- RunLoop已入门?不来应用一下?
- Android触控屏幕Gesture(GestureDetector和SimpleOnGestureListener的使用教程) 分类:Androidandroid实例...
- spring 操作对象写入mongo去除_class列
- cc1plus.exe: error: unrecognized command line option -fno-keep-inline-dllexport
- ZeroMQ接口函数之 :zmq_ipc – ZMQ本地进程间通信传输协议
- 服务器控件编程中的控件状态保存机制
- 浏览器如何解析HTML文档