求最小值最大显然是要二分

二分之后转换成了判定性问题

我们考虑哪些点一定不能选

显然是将所有可选点选中之后依然不满足条件的点不能选

那么我们不妨维护一个堆,每次取出堆顶看看是否满足条件

不满足条件就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的更多相关文章

  1. codeforces #309 div1 C

    首先我们会发现所有的人构成了一个图 定义相爱为 在一个集合里 定义相恨为 不在一个集合里 很容易发现满足条件的图一定是一个二分图 那么分类讨论如下: 1.如果出现不合法 答案为0 2.如果不是一个二分 ...

  2. codeforces #309 div1 B

    题目啰里啰嗦说了一大堆(耐心读完题目就可以秒题了) 首先我们考虑当前置换的开头的循环节的开头 1.如果是1 1->1形成循环节 问题变成i-1的子问题 2.如果是2 1->2->1形 ...

  3. codeforces #309 div1 A

    先说我的解法吧 首先设f(i,j)表示选了前i个球且j种颜色都已经选完了的方案数 这显然是可以随便转移的 #include<cstdio> #include<cstring> ...

  4. codeforces 407 div1 B题(Weird journey)

    codeforces 407 div1 B题(Weird journey) 传送门 题意: 给出一张图,n个点m条路径,一条好的路径定义为只有2条路径经过1次,m-2条路径经过2次,图中存在自环.问满 ...

  5. codeforces 407 div1 A题(Functions again)

    codeforces 407 div1 A题(Functions again) Something happened in Uzhlyandia again... There are riots on ...

  6. codeforces #305 div1 done

    总算搞定了这一场比赛的题目,感觉收获蛮大 其中A,B,C都能通过自己的思考解决掉 D题思路好神,E题仔细想想也能想出来 以后坚持每两天或者一天做一场CF的div1的全套题目 除非有实在无法做出来的题目 ...

  7. codeforces #309 DIV2

    这场并没有做,做的赛后的,太晚了时间,中午做了两题,稍微贴一下,剩余的题目本周争取补完 A题: 链接:http://codeforces.com/contest/554/problem/A #incl ...

  8. Codeforces #254 div1 B. DZY Loves FFT 暴力乱搞

    B. DZY Loves FFT 题目连接: http://codeforces.com/contest/444/problem/B Description DZY loves Fast Fourie ...

  9. codeforces #313 div1 E

    首先我们要注意到一个事情 如果一个灯塔向左覆盖,那么比他小的某个灯塔如果向左覆盖的端点大于当前塔向左覆盖的端点,他一定向右覆盖 对于当前灯塔向右覆盖也是同理 那么我们只需要记录当前覆盖到的端点就可以完 ...

随机推荐

  1. WCF学习笔记 -- 如何用C#开发一个WebService

    假设所有工程的命名空间是demo. 新建一个C#的ClassLibrary(类库)工程. 在工程引用中加入System.ServiceModel引用. 定义接口,你可以删除自动生成的代码,或者直接修改 ...

  2. String 转Clob

    把String转Clob java.sql.Clob c = new javax.sql.rowset.serial.SerialClob("abc".toCharArray())

  3. AE实现点击一个要素,并显示其属性

    第一步:根据鼠标点击处的点,找到被选中的要素 public IFeature Find2(IPoint pPoint) { ITopologicalOperator pTopoOpe = pPoint ...

  4. Docker容器里时间与宿主机不同步

    docker容器里时间设置: 第一种: Dockerfile文件中添加一行:RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime或者 第二种: ...

  5. iOS 简单总结:description方法\NSLog函数

    1.description方法是NSObject自带的方法,包括类方法和对象方法 + (NSString *)description; // 默认返回 类名 - (NSString *)descrip ...

  6. DevExpress gridLookUpEdit 实现多选

    一:创建类GridCheckMarksSelection   #region Fileds RepositoryItemGridLookUpEdit _currentRepository; prote ...

  7. PHP生成表格

    <?php /* DROP TABLE IF EXISTS `art`; CREATE TABLE `art` ( `id` int(11) NOT NULL AUTO_INCREMENT, ` ...

  8. Dapper full example

    Skip to content Sign up Sign in This repository Explore Features Enterprise Blog Watch Star , Fork S ...

  9. Delphi Variant oleVariant

    The OleVariant type exists on both the Windows and Linux platforms. The main difference between Vari ...

  10. Spark Streaming揭秘 Day23 启动关闭源码图解

    Spark Streaming揭秘 Day23 启动关闭源码图解 今天主要分析一下SparkStreaming的启动和关闭过程. 从Demo程序出发,主要聚焦在两段代码: 启动代码: 关闭代码: 启动 ...