Codeforces Round #552 (Div. 3) 题解

CPRI原理及应用--基本原理 本文主要介绍CPRI的基本原理,包括CPRI的发展历程、CPRI基本协议、速率、帧结构、时延模型等 阅读详情

题目链接

A. Restoring Three Numbers

#include <stdio.h>
#include <bits/stdc++.h>
#define fst first
#define sed second
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int main()
{
#ifdef LOCAL
	//freopen("C:/input.txt", "r", stdin);
#endif
	ll x, y, z, p;
	cin >> x >> y >> z >> p;
	if (p < x)
		swap(x, p);
	if (p < y)
		swap(y, p);
	if (p < z)
		swap(z, p);
	printf("%I64d %I64d %I64d\n", p - x, p - y, p - z);

	return 0;
}

B. Make Them Equal

可以将某个数字加一次v或者减一次v不限制操作次数 找到一个最小的v可以将数字变为相同

#include <stdio.h>
#include <bits/stdc++.h>
#define fst first
#define sed second
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int main()
{
#ifdef LOCAL
	//freopen("C:/input.txt", "r", stdin);
#endif
	vector<int> v;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		int x;
		cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	if (v.size() > 3)
		cout << -1 << endl, exit(0);
	if (v.size() == 3 && v[1] - v[0] != v[2] - v[1])
		cout << -1 << endl, exit(0);
	if (v.size() == 3)
		cout << v[1] - v[0] << endl;
	else if (v.size() == 2)
	{
		int x = v[1] - v[0];
		if (x % 2 == 0)
			x /= 2;
		cout << x << endl;
	}
	else
		cout << 0 << endl;

	return 0;
}

C. Gourmet Cat <枚举>

三种食物 告诉你周几吃哪种食物 问从周几出发能够吃的最长时间

#include <stdio.h>
#include <bits/stdc++.h>
#define fst first
#define sed second
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int main()
{
#ifdef LOCAL
	//freopen("C:/input.txt", "r", stdin);
#endif
	ll x[3], z[3];
	cin >> x[0] >> x[1] >> x[2]; //147 26 35
	ll X = min({ x[0] / 3, x[1] / 2, x[2] / 2 }); //整周
	x[0] -= X * 3, x[1] -= X * 2, x[2] -= X * 2; //余下物品
	ll ans = X * 7;
	int y[] = { 0, 1, 2, 0, 2, 1, 0 };
	for (int i = 0; i < 7; ++i) //开始
	{
		z[0] = x[0], z[1] = x[1], z[2] = x[2];
		int cnt = 0;
		for (int j = i; z[y[j]]--; j = (j + 1) % 7)
			cnt++;
		ans = max(ans, X * 7 + cnt);
	}
	cout << ans << endl;

	return 0;
}

D. Walking Robot <模拟>

机器人有普通电池和太阳能充电电池 0为无光1为有光 可以选择消耗一个电池走一步 阳光下可以消耗一个普通电池走一步获得一个充电电池 问最远能走多远

#include <stdio.h>
#include <bits/stdc++.h>
#define fst first
#define sed second
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int main()
{
#ifdef LOCAL
	//freopen("C:/input.txt", "r", stdin);
#endif
	int n, a, b; //充电电池 电池
	cin >> n >> b >> a;
	int A = a, B = b;
	for (int i = 1; i <= n; ++i)
	{
		int s;
		scanf("%d", &s);
		if (s && B && A < a)
			A = min(a, A + 1), --B;
		else if (A)
			--A;
		else
			--B;
		if (!A && !B)
			cout << i << endl, exit(0);
	}
	cout << n << endl;

	return 0;
}

E. Two Teams <数据结构> <模拟>

两个教练选人 每次选数值最大的并且将旁边的k个也选走 问每个人都被那个教练选走了

#include <stdio.h>
#include <bits/stdc++.h>
#define fst first
#define sed second
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int N = 2e5 + 10;
int l[N], r[N]; //左侧右侧编号
int a[N], b[N], c[N]; //b表示a数组从大到小编号

void sel(int x, int p) //选中x
{
	r[l[x]] = r[x], l[r[x]] = l[x]; //拼接lr
	c[x] = p; //记录结果
}
int main()
{
#ifdef LOCAL
	//freopen("C:/input.txt", "r", stdin);
#endif
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]), l[i] = i - 1, r[i] = i + 1, b[i] = i;
	sort(b + 1, b + n + 1, [](int x, int y) { return a[x] > a[y]; });
	int p = 1;
	for (int i = 1; i <= n; ++i) //从大到小选取
	{
		if (c[b[i]]) //已经被选
			continue;
		int k = l[b[i]]; //两侧坐标
		for (int j = 0; k && j < m; ++j)
			sel(k, p), k = l[k];
		k = r[b[i]];
		for (int j = 0; k && j < m; ++j)
			sel(k, p), k = r[k];
		sel(b[i], p);
		p = p == 1 ? 2 : 1;
	}
	for (int i = 1; i <= n; ++i)
		putchar('0' + c[i]);
	cout << endl;

	return 0;
}

写丑了的map版

#include <stdio.h>
#include <bits/stdc++.h>
#define fst first
#define sed second
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f; 
const int N = 2e5 + 10;
bool one[N]; //是否1队

int main()
{
#ifdef LOCAL
	freopen("C:/input.txt", "r", stdin);
#endif
	map<int, int> pos, val; //位置顺序 值顺序
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i)
	{
		int v;
		scanf("%d", &v);
		pos[i] = v;
		val[v] = i;
	}
	int flag = 1;
	while (!val.empty())
	{
		int p = val.rbegin()->second; //最大值位置
		for (int i = 0; i < k; ++i) //左侧
		{
			auto it = pos.lower_bound(p);
			if (it == pos.begin())
				break;
			--it;
			if (flag) one[it->first] = 1;
			val.erase(it->second);
			pos.erase(it);
		}
		for (int i = 0; i < k; ++i) //右侧
		{
			auto it = pos.upper_bound(p);
			if (it == pos.end())
				break;
			if (flag) one[it->first] = 1;
			val.erase(it->second);
			pos.erase(it);
		}
		if (flag) one[p] = 1;
		val.erase(pos[p]);
		pos.erase(p);
		flag ^= 1;
	}
	for (int i = 1; i <= n; ++i)
		putchar(one[i] ? '1' : '2');
	cout << endl;

	return 0;
}

F. Shovels Shop <dp> <贪心>

n个物品买k个 有m个优惠每买x个物品其中y个就免费 问最小费用
如果买k个不管有没有优惠肯定买最便宜的k个,每个优惠策略可以重复使用所以如果同样是买x个一个优惠y1一个优惠y2则取最大的。
购买使用优惠时肯定是将大小相近的作为一组一起购买,因为尽量优惠较大的。进行排序(其实找到前k小已经排序了)。
令f[i]表示购买前i个的最小代价,枚举已经购买的物品数量尝试使用每个优惠进行转移取最小值。

#include <stdio.h>
#include <bits/stdc++.h>
#define fst first
#define sed second
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int N = 2e5 + 10;
int a[N], b[N], s[N];
int f[N]; //买前i个物品的最小代价

int main()
{
#ifdef LOCAL
	//freopen("C:/input.txt", "r", stdin);
#endif
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	sort(a + 1, a + n + 1); //贪心选择尽量便宜的k个 并且dp过程中需要价值连续
	for (int i = 1; i <= k; ++i)
		s[i] = s[i - 1] + a[i]; //前缀和优化转移
	for (int i = 0; i < m; ++i)
	{
		int x, y; //买x免费y
		scanf("%d%d", &x, &y);
		b[x] = max(b[x], y); //尽量多
	}
	memset(f, 0x3f, sizeof(f));
	f[0] = 0; //没有物品代价0
	for (int i = 1; i <= k; ++i) //物品
		for (int j = 1; j <= i; ++j) //一次性购买量
			f[i] = min(f[i], f[i - j] + s[i] - s[i - j + b[j]]); //只花费后半部分
	cout << f[k] << endl;

	return 0;
}

G. Minimum Possible LCM <枚举>

任选两个数字 求最小的最小公倍数
记录每个数字出现次数和出现下标,暴力枚举公因子i并乘上倍数j查询数值是否出现,如果同一个公因子i有两个倍数j出现则计算答案并且break,因为后面会更大。
即使是极端情况复杂度也在1e8以内。

#include <stdio.h>
#include <bits/stdc++.h>
#define fst first
#define sed second
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e7 + 10;
int cnt[N], pos[N]; //数值出现次数 数值编号

int main()
{
#ifdef LOCAL
	//freopen("C:/input.txt", "r", stdin);
#endif
	int n;
	cin >> n;
	ll ans = LINF, p, q;
	for (int i = 1; i <= n; ++i)
	{
		int x;
		scanf("%d", &x);
		++cnt[x];
		if (cnt[x] > 1 && ans > x) //出现2次可以直接作为答案
			ans = x, p = pos[x], q = i; //记录上次的编号和i
		pos[x] = i;
	}
	for (int i = 1; i < N; ++i) //公约数
	{
		int k = 0; //当前公约数最小的数字的倍率
		for (int j = 1; i * j < N; ++j) //倍率
			if (cnt[i * j])
			{
				if (k) //之前已有一个
				{
					if (ans > 1LL * i * j * k) //公约数*两个数的倍
						ans = 1LL * i * j * k, p = pos[i * k], q = pos[i * j]; //记录编号
					break; //后面只会更大
				}
				else
					k = j; //记录倍率
			}
	}
	if (p > q)
		swap(p, q);
	cout << p << " " << q << endl;

	return 0;
}
手把手搭建你的第一个OCT仿真模型:用Python和光学仿真库重现A-SCAN信号 本文详细介绍了如何使用Python和光学仿真库搭建OCT仿真模型,重现A-SCAN信号。从环境配置、干涉仪建模到信号处理全流程,手把手教你实现光学相干层析成像的核心技术。通过代码示例和性能优化技巧,帮助开发者深入理解OCT原理并应用于医疗诊断等领域。 阅读详情

相关推荐

【学习笔记】一文搞懂IEPE传感器

本文介绍了IEPE(集成电路压电式)传感器的工作原理及其在振动监测中的应用。通过压电效应原理,IEPE传感器将机械振动转换为电信号,内置电荷放大器将高阻抗电荷信号转换为低阻抗电压信号输出。还介绍了传感器的三轴测量结构、4mA恒流源供电机制以及灵敏度与量程的关系,并通过风扇实验演示了故障诊断过程。实验使用USB-3123采集卡和SRD-1104信号调理器,展示了正常与异常状态下的振动数据差异,验证了IEPE传感器在设备状态监测中的有效性。

m0_62969865的博客 2830

【verilog】组合逻辑练习

给定一个八位二进制数,求出其1的个数 module sum(x,y); input[7:0] x; output y; reg[3:0] y; integer i; always @(*)begin y = 4'd0; for(i=0;i<8;i = i+1)begin if(x[i] == 1) y = y + 1; end end endmodule module test( ); reg[7:0] x; wire[3:0]

清风微醺的博客 1105

OptiSystem仿真:波分与时分复用混合光网络的设计与性能优化

本文详细介绍了如何利用OptiSystem软件设计与优化波分复用与时分复用混合光网络。通过构建四路波分乘以四路时分的系统模型,文章阐述了从信源生成、复用合并、光纤传输到信号解复用与性能评估的全流程,并重点探讨了对抗色散、优化器件参数及探索高级调制格式等核心性能优化策略,为应对未来海量数据需求提供了高效、可行的仿真解决方案。

pink的博客 1114

Codeforces Round #552 (Div. 3)E. Two Teams

Codeforces Round #552 (Div. 3)E. Two Teams 题意 一共N个人,两个教练选人,每次找能力值最大的人,算上这个人往左取k个,往右取k个,就是他的成员,判断最后每个人是谁的成员 做法 set可以从小到大排序,也可以用erase insert轻松实现操作,都是STL数据库的东西,所以想这么做,但是由于对指针不太熟悉,理解起来花了好久时间 理解难点 1.每个人其实有...

想要一只银渐层 421

PS/2鼠标接口协议

一、PS/2鼠标接口        PS/2接口用于许多现代的鼠标和键盘,由IBM最初开发和使用。物理上的PS/2接口有两种类型的连接器:5脚的DIN和6脚的MINI-DIN。        二、鼠标的接口协议原理             PS/2鼠标接口采用一种双向同步串行协议。即每在时钟线上发一个脉冲,就在数据线上发送一位数据。但是在相互传输中 ,主机是拥有总线控制权的

Ant's home 1万+

MobaXterm破解14个会话限制的保姆级教程(附Python环境配置指南)

本文提供了MobaXterm破解14个会话限制的详细教程,并深入讲解了如何配置稳定的Python环境以支持相关脚本运行。通过理解软件授权机制、安全实践步骤以及许可文件的应用,帮助用户解除会话数量限制,实现高效的远程服务器管理与自动化运维。

weixin_29211309的博客 1749

Codeforces Round #552 (Div. 3) C

3种东西,指定星期几可以使用,问你最多能用几天 #include <bits/stdc++.h> using namespace std; typedef long long ll; ll x[3], z[3]; int y[] = { 0, 1, 2, 0, 2, 1, 0 }; int main() { cin >> x[0] >> x[1] &gt...

c3po 144

中图法第五版SQL,支持树形结构可直接导入使用

基于第五版中图法官方数据收集整理,效果图如下:

cloudin_adin的博客 987

Codeforces Round #552 (Div. 3) A B C D E F G (暴力,dp,模拟)

题目链接:https://codeforces.com/contest/1154 A:Restoring Three Numbers B:Make Them Equal C:Gourmet Cat D:Walking Robot E:Two Teams F:Shovels Shop G:Minimum Possible LCM A:给定b-a、a+c、b+c、a+b+c的值求ab...

Amo丶 426

ROM和RAM在单片机程序运行理解

ROM和RAM是电子设备中两种核心存储组件,主要区别在于:ROM用于长期存储系统程序、用户文件等固定数据,断电后数据不丢失,但写入速度较慢;RAM则用于临时存储运行中的程序和数据,读写速度快但断电后数据会清空。在单片机中,ROM存储程序代码和常量,RAM存储运行时的变量和数据。两者协同工作,ROM如同"永久档案库"保存必要信息,RAM则像"临时工作台"支持高速运算,共同确保设备正常运行。

qq_37999850的博客 1629

搬运机器人系列编程:KUKA KR QUANTEC_(2).KUKA KRL语言编程基础

定义一个函数END!调用函数PRINT "结果: ", result!定义一个过程PRINT msgEND!调用过程printMessage("欢迎使用 KUKA 机器人")!定义搬运零件的起始位置和目标位置!定义焊接路径的各个点!定义喷涂路径的各个点KUKA Robot Language (KRL) 是一种专门为工业机器人设计的编程语言,具有结构化编程、丰富的库函数、实时性以及集成性等特点。

zhubeibei168的博客 1259

Codeforces Round #552 (Div. 3) B

给你n个数,可以不变,可以加上D,可以减去D,能否变成同一个数,输出最小的D #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const int maxn=2e5+5; int a[maxn],cnt;std::vector&lt...

c3po 219

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

【题解】 Codeforces Round #552 (Div. 3)

目录 A B C D A 题意:给你4个不知道顺序的值,分别为(a+b)、(a+c)、(b+c)、(a+b+c) 你需要任意输出三个正整数 A B C 解: 既然A B C都为正整数,那么a+b+c一定是最大的,排序输出即可 /** * Copyright(c) * All rights reserved. * Author : Mingzhe * ...

飒然霜林的博客 308

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Codeforces Round #552 (Div. 3) ABCDE题解

题目链接: http://codeforces.com/contest/1154 A. Restoring Three Numbers 注意看清题意,是a+b不是-a+b; 代码如下: #include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF=0x3f3f3f3f; c...

zamaochick的博客 533

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

UEFI固件PciHostBridge.c的PCIe资源分配机制深度解析

在UEFI固件开发中,PCIe资源分配是确保设备正常枚举与访问的关键环节,其核心逻辑集中在EDKII的PciHostBridge.c模块。面对BAR地址冲突、MMIO窗口不足或PCIe枚举失败等场景,理解RootBridge的资源窗口构建、设备BAR的对齐规则及两阶段分配模型至关重要。PCIe设备通过BAR寄存器映射到CPU物理地址空间,固件需按IO、Memory、Prefetchable Memory和Bus Number四类资源统一规划,遵循先上报需求再全局分配的流程,以实现地址空间的最优利用。这一机制

weixin_33778544的博客 205

Codeforces Round #552 (Div. 3)D、E题解

D. Walking Robot 题意 机器人在一维坐标轴上从0走到x,中途可以在有光的地方可以选择给太阳能电池充电,每次移动都要消耗一单位电,蓄电池容量为a,太阳能电池容量为b,一开始都是满电,问机器人采取最佳策略最多可以走多远。 题解 直接贪心模拟即可,具体见代码注释 1 #define dbg(x) cout<<#x<<" = "<< (x...

weixin_33939843的博客 92

【Codeforces Round #552 (Div. 3)】C.Gourmet Cat

题目链接:http://codeforces.com/problemset/problem/1154/C 题意:傲娇的小猫在星期1/4/7只吃鱼,在星期2/6只吃兔,在星期3/5只吃鸡。现在有鱼兔鸡各a,b,c份,问小猫最多能连续吃几天。 题解:如果鱼兔鸡的比例在3:2:2那么不管从哪天开始吃,都可以吃7天,所以我们先把整周算出来,然后剩下的就从星期一开始枚举能吃几天。最后取最大值。 My_Fee...

L_X_ 204

Codeforces Round #552 (Div. 3) A题

题目链接http://codeforces.com/contest/1154/problem/A 题目 A. Restoring Three Numbers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output ...

Viator 390

Codeforces Round #552 (Div. 3)

Codeforces Round #552 (Div. 3) 休闲VP发现打的真的太休闲了,完全没有比赛的氛围 A,B 不管 C 暴力跑第一轮和最后一轮 中间的轮数直接做除法 #include<cstdio> #include<iostream> #include<queue> #include<algorithm> #include&lt...

weixin_30409849的博客 145

Codeforces Round #552 (Div. 3)D. Walking Robot【贪心】

思路:如果当前有阳光,并且蓄电池不是饱和情况,我们就让蓄电池充电,如果蓄电池饱和我们就先用蓄电池,这样下次才有机会充电,总的来说就是贪心的思想。 #include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> ...

独钓门前月 424

Codeforces Round #552 (Div3)E

Codeforces Round #552 (Div. 3) E Two Teams 题意: ​ n个人排成一排,每个人都有一个iq,且iq不重复。现在给你一个k,且有两个教练编号为分别为1,2轮流进行以下操作 ​ 该教练从排成的一行中找出iq最大的人加入自己的团队,且让iq最大的人左边的k个人和右边的k个人都加入自己的团队(如果人数不够k个,则只把剩余的加入即可)。 ​ 现在问所有的人都被选出之...

Dch19990825的博客 259

Codeforces Round #552 (Div. 3) E. Two Teams 暴力+双向链表

传送 题意:将n个人分成2个队,每次选取队伍中未被选取的最大值,然后顺便选取左边相邻的k个数(有多少拿多少) 问你最后队伍的分配情况。 #include<bits/stdc++.h> using namespace std; const int maxn=2e5+10; int a[maxn]; struct node{ i...

henucm的博客 386

Codeforces Round #552 (Div. 3)G. Minimum Possible LCM

Codeforces Round #552 (Div. 3)G. Minimum Possible LCM 题意:给出n个数字,找出(i,j)(i,j)(i,j)使得lcm(ai,aj)lcm(a_i,a_j)lcm(ai​,aj​)最小 做法:假设现在有因子ppp,这个序列中能整除p的有五个数a1,a2,a3,a4,a5a_1,a_2,a_3,a_4,a_5a1​,a2​,a3​,a4​,a5​...

想要一只银渐层 200

Codeforces Round #552 (Div. 3)F Shovels Shop (前缀和+背包DP)

题目链接:http://codeforces.com/contest/1154 题目大意 给定n个东西的价值, 有m种优惠方式, 每种是个二元组,表示恰好买x个数可以 免费y个最便宜的,问恰好买k个物品的最小花费是多少. 题目分析 由于k数据范围很小, 我们从k这个维度思考. 首先贪心的把商品按价值排序, 然后把每种决策用一维数组映射出来,明显对于一样的x 我们选y最...

满月照亮的路 200

Codeforces Round #661 Div3 E1 Weights Division

Codeforces Round #661 Div3 E1 Weights Division (easy version) You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a vertex ????

u014156276的博客 259
上一篇: Farm Tour POJ - 2135 费用流
下一篇: Codeforces Round #553 (Div. 2) 题解
CaprYang
博客等级 码龄8年 148粉丝 277原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值