Characters with Hash

Mur loves hash algorithm, and he sometimes encrypt another one's name, and call him with that encrypted value. For instance, he calls Kimura KMR, and calls Suzuki YJSNPI. One day he read a book about SHA-256256 , which can transit a string into just 256256 bits. Mur thought that is really cool, and he came up with a new algorithm to do the similar work. The algorithm works this way: first we choose a single letter L as the seed, and for the input(you can regard the input as a string ss, s[i]s[i] represents the iith character in the string) we calculates the value(|(int) L - s[i]|∣(int)L−s[i]∣), and write down the number(keeping leading zero. The length of each answer equals to 2because the string only contains letters and numbers). Numbers writes from left to right, finally transfer all digits into a single integer(without leading zero(ss)). For instance, if we choose 'z' as the seed, the string "oMl" becomes "11 45 14".

It's easy to find out that the algorithm cannot transfer any input string into the same length. Though in despair, Mur still wants to know the length of the answer the algorithm produces. Due to the silliness of Mur, he can even not figure out this, so you are assigned with the work to calculate the answer.

Input

First line a integer TT , the number of test cases (T \le 10)(T≤10).

For each test case:

First line contains a integer NN and a character zz, (N \le 1000000)(N≤1000000).

Second line contains a string with length NN . Problem makes sure that all characters referred in the problem are only letters.

Output

A single number which gives the answer.

样例输入复制

2
3 z
oMl
6 Y
YJSNPI

样例输出复制

6
10

题目来源

ACM-ICPC 2018 徐州赛区网络预赛

 

这道题如果英语水平不太好的话可能就不能完全理解题意(我就是),尤其是一会保留前导零,一会不保留前导零,我当时就被它给弄晕啦,后来问了大神才明白了题意,他的意思就是对字符串中的每个字符从前往后按题中的公式运算,他说保留前导零,并且公式结果长度为2,这样的货就是说如果计算结果为1的话那么应该写成01,最后再将所有的结果合并起来,而合并起来的这个结果是不保留前导零的,比如三个结果分别是00 10 12 那么合并后的结果是1012为4为;

 

#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<stdio.h>
using namespace std;
struct Store {//a,b代表每一个结果的两位数是不是为零,false为零,true不为零
	bool a=false;
	bool b=false;
}store[10000001];
int main()
{
	
	//freopen("own.txt", "r", stdin);
	int t;
	cin >> t;
	while (t--) {
		int n;
		char z;
		bool flag =false;
		cin >> n >> z;
		string str;
		cin >> str;
		for (int i = 0; i < n; i++) {
			int x = abs((int)z - str[i]);
			if (x >= 10) {//如果运算的结果为两位数,那么肯定是ab都为true
				store[i].a = true;
				store[i].b = true;
			}
			else if (x > 0 && x <= 9) {//如果是一位数,那么就是a假b真
				store[i].a = false;
				store[i].b = true;
			}
			else if (x == 0) {//等于零就都是假
				store[i].a = false;
				store[i].b = false;
			}
	}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (flag) {//flag用来辅助判断有没有前导零,如果没有的话,以后的数就可以放心的加2啦
				ans += 2;
			}
			else {
				if (store[i].a == true) {//下边两个if语句是从最后合并的结果中找到第一个不是false的地方并计数
					ans++;
					flag = true;
				}
			if (store[i].b == true) {
				ans++;
				flag = true;
			}
			}

		}
		if (ans == 0)
			cout << 1 << endl;
		else
		cout << ans << endl;
	}
	
	return 0;
}

 

内容概要:本文档详细介绍了基于MATLAB实现的无人机三维路径规划项目,核心算法采用蒙特卡罗树搜索(MCTS)。项目旨在解决无人机在复杂三维环境中自主路径规划的问题,通过MCTS的随机模拟与渐进式搜索机制,实现高效、智能化的路径规划。项目不仅考虑静态环境建模,还集成了障碍物检测与避障机制,确保无人机飞行的安全性和效率。文档涵盖了从环境准备、数据处理、算法设计与实现、模型训练与预测、性能评估到GUI界面设计的完整流程,并提供了详细的代码示例。此外,项目采用模块化设计,支持多无人机协同路径规划、动态环境实时路径重规划等未来改进方向。 适合人群:具备一定编程基础,特别是熟悉MATLAB和无人机技术的研发人员;从事无人机路径规划、智能导航系统开发的工程师;对MCTS算法感兴趣的算法研究人员。 使用场景及目标:①理解MCTS算法在三维路径规划中的应用;②掌握基于MATLAB的无人机路径规划项目开发全流程;③学习如何通过MCTS算法优化无人机在复杂环境中的飞行路径,提高飞行安全性和效率;④为后续多无人机协同规划、动态环境实时调整等高级应用打下基础。 其他说明:项目不仅提供了详细的理论解释和技术实现,还特别关注了实际应用中的挑战和解决方案。例如,通过多阶段优化与迭代增强机制提升路径质量,结合环境建模与障碍物感知保障路径安全,利用GPU加速推理提升计算效率等。此外,项目还强调了代码模块化与调试便利性,便于后续功能扩展和性能优化。项目未来改进方向包括引入深度强化学习辅助路径规划、扩展至多无人机协同路径规划、增强动态环境实时路径重规划能力等,展示了广阔的应用前景和发展潜力。
我使用IEEE 的latex检查器,上传文件显示有一个错误和两个警告 This is BibTeX, Version 0.99d (TeX Live 2024) Capacity: max_strings=200000, hash_size=200000, hash_prime=170003 The top-level auxiliary file: output.aux The style file: IEEEtran.bst Reallocated singl_function (elt_size=4) to 100 items from 50. Reallocated singl_function (elt_size=4) to 100 items from 50. Reallocated singl_function (elt_size=4) to 100 items from 50. Reallocated wiz_functions (elt_size=4) to 6000 items from 3000. Reallocated singl_function (elt_size=4) to 100 items from 50. Database file #1: reference.bib Repeated entry---line 360 of file reference.bib : @article{10429768 : , I'm skipping whatever remains of this entry -- IEEEtran.bst version 1.14 (2015/08/26) by Michael Shell. -- http://www.michaelshell.org/tex/ieeetran/bibtex/ -- See the "IEEEtran_bst_HOWTO.pdf" manual for usage information. Done. You've used 30 entries, 4087 wiz_defined-function locations, 995 strings with 12414 characters, and the built_in function-call counts, 26851 in all, are: = -- 2276 > -- 614 < -- 288 + -- 372 - -- 94 * -- 1308 := -- 3935 add.period$ -- 60 call.type$ -- 30 change.case$ -- 30 chr.to.int$ -- 633 cite$ -- 30 duplicate$ -- 1870 empty$ -- 1894 format.name$ -- 120 if$ -- 6326 int.to.chr$ -- 0 int.to.str$ -- 30 missing$ -- 294 newline$ -- 113 num.names$ -- 29 pop$ -- 569 preamble$ -- 1 purify$ -- 0 quote$ -- 2 skip$ -- 2112 stack$ -- 0 substring$ -- 1522 swap$ -- 1702 text.length$ -- 77 text.prefix$ -- 0 top$ -- 5 type$ -- 30 warning$ -- 0 while$ -- 114 width$ -- 32 write$ -- 339 (There was 1 error message)
03-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值