Codeforces Round #603 (Div. 2) 题解

本文详细解答了Codeforces Round #603 (Div. 2) 中的六道题目,包括A题的最小值分摊策略,B题的字符串变化分析,C题的数学应用,D题的并查集解决方案,E题的括号匹配与线段树应用,以及F题的图论和动态规划解法。
摘要由CSDN通过智能技术生成

题目链接:https://codeforces.com/contest/1263

 

A - Sweet Problem

把最小值分摊给其他两个,然后剩下的再加上最小值

#include<bits/stdc++.h>
#define x first
#define y second
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pa;
const int mx = 1e6 + 10;
int n,m;
int main()
{ 
	int t;scanf("%d",&t);
	while (t--) {
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		if (a > b) swap(a,b);
		if (a > c) swap(a,c);
		if (b > c) swap(b,c);
		int dif = c - b;
		int ans = a;
		if (dif >= a) {
			printf("%d\n",b+a);
		} else {
			a -= dif;
			printf("%d\n",ans+b-(a+1)/2);
		}
	}
    return 0; 
}

B - PIN Codes

易知一个字符串变一次可以有9+9+9+9==36种变法,所以肯定存在一种变法使得跟其他字符串都不一样。然后就暴力一下就ok了

#include<bits/stdc++.h>
#define x first
#define y second
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pa;
const int mx = 1e6 + 10;
int n,m;
multiset <string> mst;
int change(string& ss) {
	if (mst.count(ss) == 1) {
		return 0;
	}
	mst.erase(mst.find(ss));
	for (int i=0;i<4;i++) {
		for (int j=0;j<10;j++) {
			if (ss[i]==j+
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值