B. Vasya and Isolated Vertices(图论基本知识)Educational Codeforces Round 52 (Rated for Div. 2)

原题链接: https://codeforces.com/problemset/problem/1065/B


测试样例

Sample In 1
4 2
Sample Out 1
0 1
Sample In 2
3 1
Sample Out 2
1 1

Note

In the first example it is possible to construct a graph with 0 isolated vertices: for example, it should contain edges (1,2) and (3,4). To get one isolated vertex, we may construct a graph with edges (1,2) and (1,3).
In the second example the graph will always contain exactly one isolated vertex.

题意: 给定顶点数和边数,找出被孤立点的最小数量和最大数量。(孤立即是没有和其他顶点相连。)

解题思路: 对于孤立点最小,我们可以想想,贪心使得一条边连接两个全新的顶点,那么这个时候就可以最大化利用边,所以最小值易求,直接判断即可,关键是最大值。这个关键就是我们要去构建一个无向完全图使得 m m m条边充分利用。这个时候就可以达成目的,使得孤立点最多了。OK,具体看代码。

AC代码

/*
*邮箱:unique_powerhouse@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h>	//POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>  pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

ll n,m;
int main(){
	//freopen("in.txt", "r", stdin);//提交的时候要注释掉
	IOS;
	ll maxx,minn;
	while(cin>>n>>m){
		maxx=0;minn=0;
		if(2*m>=n){
			minn=0;
		}
		else{
			minn=n-2*m;
		}
		//关键在于求maxx,构造一个完全图即可。
		for(ll i=n;i>=0;i--){
			ll temp=i*(i-1)/2;
			if(temp>=m){
				maxx=max(maxx,n-i);
			}
			else{
				break;
			}
		}
		cout<<minn<<" "<<maxx<<endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HeZephyr

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值