codeforces 712B Memory and Trident

STM32F103移植到F407后OLED不亮?主频与延时函数是关键 在嵌入式系统开发中,STM32系列芯片凭借丰富的资源和性价比被广泛使用,而OLED显示屏因其高对比度、低功耗成为交互界面的主流选择。当开发者把基于STM32F103的OLED驱动代码移植到主频更高的F407平台时,常遇到屏幕不亮的故障。其本质在于两款芯片的Cortex-M3与Cortex-M4内核主频差异显著(72MHz vs 168MHz),导致依赖指令循环的软件延时函数严重失真,进而破坏I2C通信的时钟极性与建立保持时间,使OLED控制器无法正确采样数据。同时,F407的GPIO复用映射(AF)也与F1 阅读详情

B. Memory and Trident
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion:

  • An 'L' indicates he should move one unit left.
  • An 'R' indicates he should move one unit right.
  • A 'U' indicates he should move one unit up.
  • A 'D' indicates he should move one unit down.

But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in s with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string.

Input

The first and only line contains the string s (1 ≤ |s| ≤ 100 000) — the instructions Memory is given.

Output

If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1.

Examples
input
RRU
output
-1
input
UDUR
output
1
input
RUUR
output
2
Note

In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.

In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change s to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.



首先,字符串的长度len肯定为偶数,否则不可能同时形成配对的U - D 和 R - L

设字符串中U,D,R,L的数量分别为cu,cd,cr,cl

t1 = cu + cd         t2 = cr + cl

在len为偶数的情况下,有两种情况:

1. t1和t2同时为奇

2. t1和t2同时为偶


同时为奇数的时候,则cu和cd尽可能平摊,多的一个给cr和cl,然后cr和cl再平摊,平摊的过程中记录变换的个数

同时为偶数的时候cu和cd直接平摊,cr和cl直接平摊就可以了,同样过程中记录变换的个数


#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <map>

using namespace std;

const int maxn = 100000;
char s[maxn + 5];
int len;

int main()
{
	int cu, cd, cr, cl, ans, t1, t2;
	scanf("%s", s);
	len = strlen(s);
	if (len % 2) {
		cout << -1 << endl;
		return 0;
	}
	map<char, int> m;
	for (int i = 0; i < len; i++) {
		m[s[i]]++;
	}
	cu = m['U'];
	cd = m['D'];
	t1 = cu + cd;
	cr = m['R'];
	cl = m['L'];
	t2 = cr + cl;
	if (t1 % 2 && t2 % 2) {
		ans = max(cu, cd) - t1 / 2;
		ans = ans + max(cl, cr) - (t2 + 1) / 2;
	} else if(t1 % 2 == 0 && t2 % 2 == 0) {
		ans = max(cu, cd) - t1 /2 + max(cl, cr) - t2 / 2;
	}
	cout << ans << endl; 
	return 0;
}



人工智能数据治理——解读AI时代数据治理白皮书 2025【附全文阅读】 摘要:该白皮书面向企业数字化负责人及AI项目推进人员,探讨AI时代数据治理的战略升级。提出"好数据+好数据知识"双基石理念,强调数据需满足"三高"标准(高精度、一致性、时效性)并构建语义知识库。构建四层治理框架,包括数据采集处理、合规安全、知识库建设及质量改进,并介绍AI赋能治理的新范式,如智能ETL和治理Agent体系。同时分析"软件+AI+好数据"的应用模式,为企业实现智能数据治理提供实践指导。(149字) 阅读详情

相关推荐

量化策略分享之首板低开

这个量化策略的核心是选择在低位、首次涨停后次日低开的股票,开盘时买入,上午有盈利就卖出,没有就拿到尾盘在卖出;策略优点在于选择的股票在低位,风险较低,并且刚启动首板,有大资金介入,第二天能快速跑路。

qq_29301281的博客 1513

Codeforces #370 (Div.2) B. Memory and Trident【思维】

传送门:B. Memory and Trident 描述: B. Memory and Trident time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output M

魔笛手的博客 518

别再为通讯发愁了!手把手教你用PCAN-View调试Kinco步科伺服电机的CANopen

本文详细介绍了如何使用PCAN-View工具调试Kinco步科伺服电机的CANopen通讯,从环境搭建到实战演练,涵盖硬件连接、软件配置及故障排除。通过具体案例和代码示例,帮助工程师快速掌握伺服电机通讯控制技术,解决工业设备通讯难题。

weixin_29189377的博客 282

Memory and Trident

Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: An ‘L’ indicates he should move one unit left. An ‘R’ indicates...

无限迭代中...... 560

KEITHLEY 2182A + 6220/6221 系列测试系统软件

6221型与2182A型相结合,是业界最完整的差分电导测量解决方案

业余程序员小徐的博客 3009

技术面试官视角:复盘北航/中科院/哈工大保研机试与面试,他们到底在考察什么?(附真题回忆与评分侧重点)

本文从技术面试官视角解析北航、中科院、哈工大等顶尖院校保研机试与面试的考核逻辑,揭示编程语言限制、题目难度设计等隐藏考察维度,并提供真题回忆与评分侧重点。帮助考生理解面试官的真实意图,掌握应对策略,提升通过率。

weixin_42549496的博客 525

Codeforces 370D - Memory and Trident(模拟)

B. Memory and Trident time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Memory is performing a walk on the two-dimensional plane, starting a

Snakeflute的博客 513

2025.06.17【WGS】|多样品VCF文件中每个样品SNP数统计方法详解(含代码与注释)

摘要:本文介绍了一种从合并后的VCF文件中统计每个样品SNP数目的方法。通过解析VCF文件中的GT字段,排除纯合参考(0/0)和缺失(./.)的基因型,准确计算各样本的SNP位点数。文中提供了完整的Python脚本,利用bcftools工具高效处理大规模VCF文件,并支持输出SNP统计结果。该方法适用于群体遗传学和RAD-seq等高通量测序数据分析的质控环节,还可扩展为统计杂合/纯合SNP等进阶需求。脚本使用简单,只需输入VCF文件即可生成样本-SNP数目的统计报表。

1710

Codeforces Round #370 (Div. 2)B. Memory and Trident

地址:http://codeforces.com/problemset/problem/712/B 题目:    B. Memory and Trident time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp...

weixin_30338497的博客 153

华为无线WiFi实战:基于802.1x与NPS的企业级认证部署指南

本文提供了一份详尽的华为无线WiFi企业级认证部署实战指南。通过整合802.1x协议与Windows NPS服务器,构建基于AD域账号的安全认证体系,彻底解决传统WiFi密码共享带来的安全风险。文章详细拆解了从NPS服务器配置、证书部署到华为AC端RADIUS模板、AAA方案、认证域及VAP模板调用的全流程,并附有终端连接测试与常见故障排查方法,助力企业实现高效、安全的无线网络接入管理。

weixin_29239661的博客 280

用Python爬虫抓取大宗交易成交数据:全面解析与实战代码

大宗交易是指在证券市场中,涉及大额买卖的交易。此类交易通常由机构投资者进行,其交易量较大,对市场的影响显著。大宗交易数据包含了买卖双方的成交价格、成交量等关键信息,这些数据对于投资者和分析师而言,具有重要的市场预测意义。Python爬虫是一种自动化抓取互联网上数据的工具。通过爬虫,我们可以定期获取大宗交易数据,节省人工查询的时间。爬虫的工作原理通常包括:发送HTTP请求、获取响应数据、解析网页内容、提取关键信息、存储和展示数据。

2201_76125261的博客 427

Codeforces 712B. Memory and Trident

题目链接:http://codeforces.com/problemset/problem/712/B 题意:   一个人站在坐标原点处,他可以往上(U), 下(D), 左(L), 右(R), 四个方向移动,现给你一个移动序列,为了使他最后仍然能回到原点,你需要对这个序列做一些改变,每次可以改变其中一个字母,问最少的改变次数. 思路:   如果这个序列的长度是奇数,那么肯定不可能...

dimaishu7553的博客 158

无人飞行器和车辆的协同配送物资问题——附带MATLAB代码

通过建立城市地图、生成物资点和配送任务、路径规划、协同调度以及仿真和评估等步骤,可以有效地解决物资配送的优化问题。通过建立城市地图、生成物资点和配送任务、路径规划、协同调度以及仿真和评估等步骤,可以有效地解决物资配送的优化问题。我们的目标是最小化物资配送的总时间,同时确保每个物资点都被正确配送的无人飞行器或车辆所访问。我们的目标是最小化物资配送的总时间,同时确保每个物资点都被正确配送的无人飞行器或车辆所访问。我们首先需要建立一个城市地图,包括物资点、无人飞行器的起始点和车辆的起始点。

CyberJolt的博客 956

Codeforces 712B Memory and Trident

B. Memory and Trident time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Memory is performing a walk on the two-...

weixin_30594001的博客 115

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

codeforces 712B. Memory and Trident

题目链接:http://codeforces.com/problemset/problem/712/B 题目大意:   给出一个字符串(由'U''D''L''R'),分别是向上、向下、向左、向右一个单位,问修改若干字符,可以回到原点。回不到原点输出 -1,可以则输出最少修改的步数。 解题思路:   如果是奇数步,则不可以回到原点 直接输出-1;   否则:分别统计出向各个方向的步数,求出...

weixin_30484247的博客 125

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Codeforces Problem 712B Memory and Trident(implementation)

Codeforces Problem 712B Memory and Trident(implementation)

queuelovestack的专栏 1052

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Codeforces 712B Memory and Trident 简单贪心

B. Memory and Trident time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Memory is performing a walk on the tw

你那么爱笑,家里人知道吗? 591

CodeForces 712B Memory and Trident

Description Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: An 'L' indicates he should move one unit lef

弹剑听潮 334

B - Memory and Trident CodeForces - 712B(回到原点,水题)

Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: An ‘L’ indicates he should move one unit left. An ‘R’ indicates...

tomjobs的博客 389

CodeForces-712B. Memory and Trident(模拟)

B. Memory and Trident time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Memory is performing a walk on the two-dimensional plane, starting a

Prim 410

codeforces 712B B. Memory and Trident(水题)

题目链接: B. Memory and Trident time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Memory is performing a walk on the two...

weixin_30556161的博客 121
上一篇: codeforces706C Hard problem 动态规划
下一篇: hdu5902 GCD is Funny
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址