C. Basic Diplomacy(ranting 1600)超详细题解

C. Basic Diplomacy(ranting 1600)超详细题解



前言

本系列的意义在于两点,一则是作为本人(一个编程初学者)的学习笔记记录,二则希望能对后来者提供一些帮助,因为本人也为新手,难免有些错误或讲述不清之处,恳请大家指出或提出建议,本人也会虚心修改。

本系列的目标是帮助大家解决一些codeforces上,ranting1600+(或者之后会改为1300+,看博主水平吧)的题目


一、题目及翻译

1. 原题(贴图)

2eb9437f9edd35df3a5e052cefea71e8.png
【戳我跳转到题目】

2. 翻译
  1. 机翻版
    7ca585417d9614c81e086c3e64c64408.jpg
  2. 省流版
    对于每个测试数据给定的n和数组S,我们需要构造两个括号序列满足可以通过添加字符’+"和"1"将其转换为有效的数学表达式(下称限制1)。同时,如果第i位上 s i s_i si是1,那么两个括号序列(下称a和b)的第i位应该相同,如果 s i s_i si是0,那么两个括号序列的第i位应该不同

二、解析及AC代码

1.解析

我们先讨论一下无解的情况:

  1. 如果有一个朋友有超过⌈m/2⌉天有空,且那些天只有他有空。为什么呢 ? 不难想到就算只有两个朋友,而有m天,只要我们能一天选一个另一天选另一个就好,但如果有一个朋友有超过⌈m/2⌉天有空,且那些天只有他有空,那么怎么选都必定超过⌈m/2⌉次

那么当有解情况下,我们记录每个朋友被选的次数,然后每天选择当天有空的朋友中被选的次数最少的朋友就好

那么,此时同学们就可以自己去尝试一下了,如果还是不太理解,可以参考下博主下面的AC代码

2.AC代码
#include<iostream>
#include<unordered_map>
#include<vector>

using namespace std;

typedef long long LL;

const int N = 1e6 + 10, MAXI = 0x3f3f3f3f;

int t, n, m, k;
vector<int> res[N];

int main()
{
  cin >> t;
  while (t--)
  {
  	cin >> n >> m;
  	unordered_map<int, int> map;
  	bool st = 0;
  	for (int i = 1; i <= m; i++)res[i].clear();
  	for (int i = 1; i <= m; i++)
  	{
  		cin >> k;
  		for (int j = 1; j <= k; j++)
  		{
  			int a; 
  			cin >> a;
  			res[i].push_back(a);
  		}
  		if (k == 1)
  		{
  			map[res[i][0]]++;
  			if (map[res[i][0]] > (m + 1) / 2)st = true;
  		}
  	}
  	if (st)cout << "NO" << endl;
  	else
  	{
  		cout << "YES" << endl;
  		for (int i = 1; i <= m; i++)
  		{
  			int ans = 0, mini = MAXI;
  			if (res[i].size() == 1)cout << res[i][0] << " ";
  			else
  			{
  				for (int j = 0; j < res[i].size(); j++)
  				{
  					if (map[res[i][j]] < mini)
  					{
  						mini = map[res[i][j]];
  						ans = res[i][j];
  					}
  				}
  				cout << ans << " ";
  				map[ans]++;
  			}
  		}
  		cout << endl;
  	}
  }
}

如果觉得有用还请点个赞吧,拜托拜托

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
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.

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值