codeforces 553D . Nudist Beach 二分
题目链接
有趣的题。
给一个图, 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 二分的更多相关文章
- Codeforces 553D Nudist Beach(二分答案 + BFS)
题目链接 Nudist Beach 来源 Codeforces Round #309 (Div. 1) Problem D 题目大意: 给定一篇森林(共$n$个点),你可以在$n$个点中选择若干个构 ...
- Codeforces 553D Nudist Beach(图论,贪心)
Solution: 假设已经选了所有的点. 如果从中删掉一个点,那么其它所有点的分值只可能减少或者不变. 如果要使若干步删除后最小的分值变大,那么删掉的点集中肯定要包含当前分值最小的点. 所以每次删掉 ...
- codeforces 553 D Nudist Beach
题意大概是.给出一个图,保证每一个点至少有一条边以及随意两点间最多一条边.非常显然这个图有众多点集,若我们给每一个点定义一个权值,那每一个点集都有一个最小权值点,如今要求出一个点集,这个点集的最小权值 ...
- [Codeforces 1199C]MP3(离散化+二分答案)
[Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...
- CodeForces 670D1 暴力或二分
今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1 This problem is given in two versions that diff ...
- codeforces 895B XK Segments 二分 思维
codeforces 895B XK Segments 题目大意: 寻找符合要求的\((i,j)\)对,有:\[a_i \le a_j \] 同时存在\(k\),且\(k\)能够被\(x\)整除,\( ...
- Codeforces 626C Block Towers(二分)
C. Block Towers time limit per test:2 seconds memory limit per test:256 megabytes input:standard inp ...
- codeforces 803D Magazine Ad(二分+贪心)
Magazine Ad 题目链接:http://codeforces.com/contest/803/problem/D ——每天在线,欢迎留言谈论. 题目大意: 给你一个数字k,和一行字符 例: g ...
- Success Rate CodeForces - 807C (数学+二分)
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces ...
随机推荐
- 不用css样式表和背景图片实现圆角矩形,超简洁!
当网站页面的整体布局设计好后,接下来有很多细节的实现是很让人头疼的.其中之一就是圆角矩形的实现. 在网上看了很多圆角矩形的实现方法,基本有两种,一种是用纯css实现,不需要背景图片:另一种是用背景图像 ...
- OC——类
1.Objective-C是C语言的超集,完全兼容C语言 2.所有的关键字都以“@”开头,例如:@interface,@class,@implementation 3.Objective-C的所有对象 ...
- Sql Server数据库设计高级查询
-------------------------------------第一章 数据库的设计------------------------------------- 软件开发周期: (1 ...
- 使用Open Live Writer 的代码高亮插件体验
由于windows live writer 2012 已经停止服务,转而推出开源项目Open Live Writer .虽然Open Live Writer 也没怎么更新,官网更是一个插件都没有放出来 ...
- 我的DbHelper数据操作类(转)
其实,微软的企业库中有一个非常不错的数据操作类了.但是,不少公司(起码我遇到的几个...),对一些"封装"了些什么的东西不太敢用,虽然我推荐过微软的企业库框架了...但是还是要&q ...
- easyui跨iframe属性datagrid
1.问题 如何刷新easyui父级tab页中iframe嵌套页中的datagrid? 2.解决方法 (1) parent.$("iframe[title='tabtitle']") ...
- Mysql 常用查询语句
SELECT * FROM table1 ,,,,,,,,) ) SELECT * FROM table3 WHERE t3Date >= '2011-08-10' SELECT * FROM ...
- git创建与合并分支
创建与合并分支 在版本回退里,你已经知道,每次提交,Git都把它们串成一条时间线,这条时间线就是一个分支.截止到目前,只有一条时间线,在Git里,这个分支叫主分 支,即master分支.HEAD严格来 ...
- poj3507---去掉最小值和最大值
#include <stdio.h> #include <stdlib.h> int main() { ) { ,max=,min=,t; ; i<; i++) { sc ...
- dhtmlgrid修改,支持IE10
因为项目IE升级,导致原来使用的dhtmlgrid无法正常显示,同时通过loadxml接口还有属性不支持. 花了半天时间对dhtmlgrid进行了修改,能够支持IE10正常加载显示. edit by ...