题目链接

有趣的题。

给一个图, n个点m条边。 有k个点不可选择。

现在让你选出一个非空的点集, 使得点集中strength最小的点的strength最大。

strength的定义:一个点周围的点中在集合里的点/一个点周围的点。

我们二分这个strength值。

每次二分, 我们遍历每个点, 然后将strength值小于mid的点加到队列里面,然后标记一下, 相当于将这个点去除掉。

然后遍历队列, 将队列里的点周围的点strength值小于mid的加进队列,标记, 不断重复。

最后看有没有点没有被标记就好。

具体看代码。

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef complex <double> cmx;
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9+7;
const int inf = 1061109567;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
const int maxn = 1e5+5;
int n, m, k;
int a[maxn], vis[maxn], ans[maxn], ban[maxn], de[maxn], num[maxn];
vector <int> g[maxn];
int dblcmp(double x) {
if(fabs(x)<eps)
return 0;
return x<0?-1:1;
}
int check(double ratio) {
queue <int> q;
mem(vis);
mem(num);
for(int i = 1; i <= n; i++) {
if(ban[i]) {
vis[i] = 1;
continue;
}
double tmp = 1-1.0*a[i]/de[i];
if(dblcmp(tmp-ratio)<0) {
q.push(i);
vis[i] = 1;
}
}
while(!q.empty()) {
int u = q.front(); q.pop();
for(auto &i : g[u]) {
if(ban[i] || vis[i])
continue;
num[i]++;
double tmp = 1-1.0*(a[i]+num[i])/de[i];
if(dblcmp(tmp-ratio)<0) {
q.push(i);
vis[i] = 1;
}
}
}
for(int i = 1; i <= n; i++) {
if(!vis[i])
return 1;
}
return 0;
}
void solve() {
double l = 0, r = 1;
for(int i = 0; i < 100; i++) {
double mid = (l+r)/2;
if(check(mid)) {
for(int j = 1; j <= n; j++) {
ans[j] = vis[j];
}
l = mid;
} else {
r = mid;
}
}
int cnt = 0;
for(int i = 1; i <= n; i++)
if(!ans[i])
cnt++;
cout<<cnt<<endl;
for(int i = 1; i <= n; i++)
if(!ans[i])
cout<<i<<" ";
}
int main()
{
int x, u, v;
cin>>n>>m>>k;
for(int i = 0; i < k; i++) {
scanf("%d", &x);
ban[x] = 1;
}
for(int i = 0; i < m; i++) {
scanf("%d%d", &u, &v);
g[u].pb(v);
g[v].pb(u);
de[u]++, de[v]++;
if(ban[u])
a[v]++;
if(ban[v])
a[u]++;
}
solve();
return 0;
}

codeforces 553D . Nudist Beach 二分的更多相关文章

  1. Codeforces 553D Nudist Beach(二分答案 + BFS)

    题目链接 Nudist Beach 来源  Codeforces Round #309 (Div. 1) Problem D 题目大意: 给定一篇森林(共$n$个点),你可以在$n$个点中选择若干个构 ...

  2. Codeforces 553D Nudist Beach(图论,贪心)

    Solution: 假设已经选了所有的点. 如果从中删掉一个点,那么其它所有点的分值只可能减少或者不变. 如果要使若干步删除后最小的分值变大,那么删掉的点集中肯定要包含当前分值最小的点. 所以每次删掉 ...

  3. codeforces 553 D Nudist Beach

    题意大概是.给出一个图,保证每一个点至少有一条边以及随意两点间最多一条边.非常显然这个图有众多点集,若我们给每一个点定义一个权值,那每一个点集都有一个最小权值点,如今要求出一个点集,这个点集的最小权值 ...

  4. [Codeforces 1199C]MP3(离散化+二分答案)

    [Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...

  5. CodeForces 670D1 暴力或二分

    今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1   This problem is given in two versions that diff ...

  6. codeforces 895B XK Segments 二分 思维

    codeforces 895B XK Segments 题目大意: 寻找符合要求的\((i,j)\)对,有:\[a_i \le a_j \] 同时存在\(k\),且\(k\)能够被\(x\)整除,\( ...

  7. Codeforces 626C Block Towers(二分)

    C. Block Towers time limit per test:2 seconds memory limit per test:256 megabytes input:standard inp ...

  8. codeforces 803D Magazine Ad(二分+贪心)

    Magazine Ad 题目链接:http://codeforces.com/contest/803/problem/D ——每天在线,欢迎留言谈论. 题目大意: 给你一个数字k,和一行字符 例: g ...

  9. Success Rate CodeForces - 807C (数学+二分)

    You are an experienced Codeforces user. Today you found out that during your activity on Codeforces ...

随机推荐

  1. JQuery EasyUi 扩展combox验证

    随笔记录一下 1.通过select text的值验证 /** * 扩展combox验证,easyui原始只验证select text的值,不支持value验证() */ (function($){ c ...

  2. Android 打开系统最近任务及最近应用方法

    Class serviceManagerClass; try { serviceManagerClass = Class.forName("android.os.ServiceManager ...

  3. JAVASCRIPT——图片滑动效果

    点击按钮开始整体右移,移动至蓝色区域全部显示出来停止. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&qu ...

  4. iOS学习心得——UINavigationController

            UINavigationController和UItableviewController一样也是iOS开发中常用的控件之一,今天就来学习一下它的常见用法.         有人说tab ...

  5. 多个不同的表合并到一个datatable中,repeater在绑定datatable

    using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...

  6. 当tomcat有两个链接数据库的应用同时运行可能冲突

    -Xms512M   -Xmx1024M -XX:MaxPermSize=256M

  7. MySQL必知必会笔记<2>

    [英]ben Forta著 5 1.0  *使用扩展查询* |---->select note from table   where Match(note) Against('anl'); |- ...

  8. VMware的CentOS无法上网的解决方法

    1)点击 VM->Settings Hardware 选项卡下面 2)点击 Network Adapter 设置在虚拟机中将网络配置设置成NAT 3)开启 Windows服务中的 VMware ...

  9. Linux08--Shell程序设计03 shell script

    第一个Shell脚本——HelloWorld [root@localhost ~]# vi sh01.sh #!/bin/bash #!表明使用哪种shell # this is my first s ...

  10. 您在基于 Windows 7 的或基于 Windows Server 2008 R2 的计算机上读取器中插入智能卡时出现错误消息:"设备驱动程序软件未能成功安装"

    http://support.microsoft.com/kb/976832/zh-cn http://support.microsoft.com/kb/976832/zh-tw 症状 当智能卡插入智 ...