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;
}
codeforces #309 div1 D的更多相关文章
- codeforces #309 div1 C
首先我们会发现所有的人构成了一个图 定义相爱为 在一个集合里 定义相恨为 不在一个集合里 很容易发现满足条件的图一定是一个二分图 那么分类讨论如下: 1.如果出现不合法 答案为0 2.如果不是一个二分 ...
- codeforces #309 div1 B
题目啰里啰嗦说了一大堆(耐心读完题目就可以秒题了) 首先我们考虑当前置换的开头的循环节的开头 1.如果是1 1->1形成循环节 问题变成i-1的子问题 2.如果是2 1->2->1形 ...
- codeforces #309 div1 A
先说我的解法吧 首先设f(i,j)表示选了前i个球且j种颜色都已经选完了的方案数 这显然是可以随便转移的 #include<cstdio> #include<cstring> ...
- codeforces 407 div1 B题(Weird journey)
codeforces 407 div1 B题(Weird journey) 传送门 题意: 给出一张图,n个点m条路径,一条好的路径定义为只有2条路径经过1次,m-2条路径经过2次,图中存在自环.问满 ...
- codeforces 407 div1 A题(Functions again)
codeforces 407 div1 A题(Functions again) Something happened in Uzhlyandia again... There are riots on ...
- codeforces #305 div1 done
总算搞定了这一场比赛的题目,感觉收获蛮大 其中A,B,C都能通过自己的思考解决掉 D题思路好神,E题仔细想想也能想出来 以后坚持每两天或者一天做一场CF的div1的全套题目 除非有实在无法做出来的题目 ...
- codeforces #309 DIV2
这场并没有做,做的赛后的,太晚了时间,中午做了两题,稍微贴一下,剩余的题目本周争取补完 A题: 链接:http://codeforces.com/contest/554/problem/A #incl ...
- Codeforces #254 div1 B. DZY Loves FFT 暴力乱搞
B. DZY Loves FFT 题目连接: http://codeforces.com/contest/444/problem/B Description DZY loves Fast Fourie ...
- codeforces #313 div1 E
首先我们要注意到一个事情 如果一个灯塔向左覆盖,那么比他小的某个灯塔如果向左覆盖的端点大于当前塔向左覆盖的端点,他一定向右覆盖 对于当前灯塔向右覆盖也是同理 那么我们只需要记录当前覆盖到的端点就可以完 ...
随机推荐
- C# 高精度加法 支持小数(待优化)
直接上代码 实现思路: 1.首先小数点补 位,9223372036854775808.9+9223372036854775808.9223372036854775808 => 922337203 ...
- Today’s words
transcendental,transcendental capacity commission,the commission would keep venetian unimodel transi ...
- (转)MongoDb的十个使用要点
从 mongodb 阶段性技术总结 中抽取并整理了对大家有帮助的十个要点: 1.mongodb 表名和字段名统一用小写字母 mongodb 是默认区分大小写的,为了避免以前在 mysql 下遇到的 ...
- Linux 查看系统版本及位数
1. 查看内核版本命令: 1) [root@www ~]# cat /proc/version Linux version 2.6.9-22.ELsmp (bhcompile@crowe.dev ...
- ArrayList和Array之间的转换
ArrayList转Array (1):使用ArrayList的toArray方法. 1)当ArrayList中存放的是引用类型时(例如String),成功 /** * 使用 ...
- 登堂入室——java流
——文章出自PeterYe,不得私自转载 我所知道的 java.io里面的[流],就仿佛太平洋里面的水一样,浩浩荡荡,横无际涯... -----2016/7/16--------公寓处记录------ ...
- ASP.Net MVC中JSON处理。
实体数据Model [Serializable] public class UserModel { //public UserModel(string name, string classname, ...
- mysql中的if条件语句用法
· IF(expr1,expr2,expr3) 如果 expr1 是TRUE (expr1 <> 0 and expr1 <> NULL),则 IF()的返回值为expr2; ...
- CentOS安装libpcap
1.安装GCC: yum -y install gcc-c++ 2.安装flex: yum -y install flex 没有flex,直接安装libpcap会提示"Your o ...
- CodeForces 18C
Description Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In eac ...