CF1484 C. Basic Diplomacy【贪心/网络流】

题目链接

题意

某人有 n n n 个朋友,在 m m m 天中,每天会有 k k k 个朋友有空,问是否存在一种方案收到每个朋友出现的次数不大于 ⌈ m 2 ⌉ \lceil\frac{m}{2}\rceil 2m,存在则输出YES和每天选择的朋友编号,否则输出 NO ( 1 ≤ n , m ≤ 1 0 5 ) (1≤n,m≤10^5) (1n,m105)

分析

题目的目的是让每个人出现的天数尽可能少,那么可以先处理掉那些只有一个人的时间,然后,按照贪心,每次选择出现次数最少的人。

代码

#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=1e5+5;
int ans[N],num[N];
vector<int>day[N];
//让每个人出现的次数尽可能小,先确定能够确定的
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int n,m,k;
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++)
			num[i]=0;
		for(int i=1;i<=m;i++)
			day[i].clear();
		for(int i=1;i<=m;i++){
			scanf("%d",&k);
			int x;
			for(int j=1;j<=k;j++){
				scanf("%d",&x);
				day[i].pb(x);
			}
			if(k==1){
				num[x]++;
				ans[i]=x;
			}
		}
		int flag=1;
		for(int i=1;i<=m;i++){
			if(day[i].size()==1)
				continue;
			int minn=m,p=1;
			for(auto x:day[i]){
				if(num[x]<minn){
					minn=num[x];
					p=x;
				}
			}
			num[p]++;
			ans[i]=p;
		}
		for(int i=1;i<=n;i++){
			if(num[i]>(m+1)/2){
				flag=0;
				break;
			}
		}
		if(flag){
			printf("YES\n");
			for(int i=1;i<=m;i++)
				printf("%d%c",ans[i],i==m?'\n':' ');
		}
		else 
			printf("NO\n");
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Ladies and gentlemen, Today, I want to talk about the two most important concepts that have shaped human history - war and peace. War has been an unfortunate reality in human history. It has caused immense suffering, destruction, and loss of life. From the ancient wars fought with swords and shields to the modern wars fought with tanks and drones, the devastation caused by war is undeniable. The scars of war can last for generations, and the human cost is immeasurable. However, war is not inevitable. We have the power to create a more peaceful world. Peace is not just the absence of war, but a state of harmony, where people can live together without fear, violence, or conflict. Peace is the foundation of progress, development, and prosperity. Achieving peace requires a collective effort from all of us. It requires us to work together, to respect each other's differences, and to find common ground. We must promote understanding, dialogue, and diplomacy, and reject the use of force as a means of resolving conflicts. We must also address the root causes of conflict. Poverty, inequality, and injustice are all factors that contribute to social unrest and conflict. By addressing these issues, we can create a more equal and just society, where people can live in harmony. In conclusion, war and peace are two sides of the same coin. We must strive for peace and work towards it every day. Let us choose the path of peace, and work together to create a better world for ourselves and future generations. Thank you.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值