题目链接

有趣的题。

给一个图, 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. Android开发 学习笔记——HelloWorld

    Day01 1.java开发过程———————————————不建议先用ECLIPSE写代码,因为它的函数式自动生成的,不利于找寻编程手感打开记事本写完程序后,修改扩展名为.java然后在DOS控制台 ...

  2. C# VS 面向对象基础(一)

    面向对象(Object Oriented,OO)的相关知识学习了很多了,这篇博客我从C#实现面向对象的理论来做个初步的总结. 在这篇博客中,我通过一个例子讲述了,面向对象中,类,类的实例化,构造方法, ...

  3. Jquery库自带的动画效果方法记录

    1.显示和隐藏hide()和show() <script type="text/javascript">             $(function() {      ...

  4. document_createElement

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  5. 5.7 cm server-agent 会出现无法启动

    异常信息如下: 离线安装cloudera-scm-agent5.7的Unable to create the pidfile问题 在离线安装Cloudera Manager启动agent出现了如下异常 ...

  6. Majority Element,Majority Element II

    一:Majority Element Given an array of size n, find the majority element. The majority element is the ...

  7. View的滑动冲突

    一.常见的滑动冲突 场景1:外部滑动和内部滑动不一致 场景2:外部滑动和内部滑动一致 场景3:上面两种情况的嵌套 二.滑动冲突的处理方法 场景一:根据水平滑动还是竖直滑动判断到底由谁来拦截事件. 场景 ...

  8. jupyter巨好玩-简介与安装

    ipython notebook改名jupyter了而且更好玩更好用 jupyter简介 jupyter是啥啊? 这个要从ipython说起,ipython是个交互式的python的解释器,自带颜色, ...

  9. de4dot命令 v2.0.3.3405

    de4dot v2.0.3.3405 Copyright (C) 2011-2013 [email]de4dot@gmail.com[/email] Latest version and source ...

  10. Mobile Service更新和 Notification Hub 对Android的支持

    本周,我们要推出一些更新,使移动服务成为移动应用程序更强大.更灵活的后端,同时推出一个与移动服务或网站结合使用的免费 20MB SQL 数据库,并且将支持通过Notification Hub中的 GC ...