【G - Shuffle'm Up】

本文详细解析了一道使用C++进行字符串操作的题目,通过模拟特定的字符串转换过程,探讨了字符串处理技巧和算法优化策略。文章分享了完整的代码实现,并分析了其运行效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以前做过原题,贴出链接(用的是map)。

下面是新代码:

  • 0ms 668kB
//0ms	668kB


#include <iostream>
#include <string>

using namespace std;

string l , r;
string tar , cur;
string book;
int N;
int ans;

void sitimulate(){
	cur.clear();
	for(int i=1;i<=2*N;i++){
		if(i%2){
			cur+=r[i/2];
		}
		else{
			cur+=l[(i-1)/2];
		}
	}
	l.clear();
	r.clear();
	for(string::iterator i = cur.begin() ; i != cur.end() ; i++){
		if(i - cur.begin() < N)
			l += *i;
		else
			r += *i;
	}
	ans++;
	return ;
}

void dealwithit(){
	sitimulate();
	book = cur;
	if(cur == tar)
		return ;
	while(true){
		sitimulate();
		if(cur == tar)
			return ;
		if(cur == book){
			ans = -1;
			return ;
		}
	}
}

int main(){
	int T;cin>>T;
	for(int t=1;t<=T;t++){
		ans = 0;
		cin>>N;
		cin>>l>>r>>tar;
		dealwithit();
		cout<<t<<' '<<ans<<endl;
		//特别有趣的是,一开始没加换行,结果第一个结果"变成"了23,haha 
	}
	return 0;
}
2025-06-28 11:42:45 25/06/28 03:42:45 INFO Worker: Executor app-20250628034119-0000/32 finished with state EXITED message Command exited with code 1 exitStatus 1 2025-06-28 11:42:45 25/06/28 03:42:45 INFO ExternalShuffleBlockResolver: Clean up non-shuffle and non-RDD files associated with the finished executor 32 2025-06-28 11:42:45 25/06/28 03:42:45 INFO ExternalShuffleBlockResolver: Executor is not registered (appId=app-20250628034119-0000, execId=32) 2025-06-28 11:42:45 25/06/28 03:42:45 INFO Worker: Asked to launch executor app-20250628034119-0000/33 for KafkaNumberAdder 2025-06-28 11:42:45 25/06/28 03:42:45 INFO SecurityManager: Changing view acls to: spark 2025-06-28 11:42:45 25/06/28 03:42:45 INFO SecurityManager: Changing modify acls to: spark 2025-06-28 11:42:45 25/06/28 03:42:45 INFO SecurityManager: Changing view acls groups to: 2025-06-28 11:42:45 25/06/28 03:42:45 INFO SecurityManager: Changing modify acls groups to: 2025-06-28 11:42:45 25/06/28 03:42:45 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users with view permissions: spark; groups with view permissions: EMPTY; users with modify permissions: spark; groups with modify permissions: EMPTY 2025-06-28 11:42:45 25/06/28 03:42:45 INFO ExecutorRunner: Launch command: "/opt/bitnami/java/bin/java" "-cp" "/opt/bitnami/spark/conf/:/opt/bitnami/spark/jars/*" "-Xmx1024M" "-Dspark.driver.port=36357" "-Dspark.ui.port=4041" "-Djava.net.preferIPv6Addresses=false" "-XX:+IgnoreUnrecognizedVMOptions" "--add-opens=java.base/java.lang=ALL-UNNAMED" "--add-opens=java.base/java.lang.invoke=ALL-UNNAMED" "--add-opens=java.base/java.lang.reflect=ALL-UNNAMED" "--add-opens=java.base/java.io=ALL-UNNAMED" "--add-opens=java.base/java.net=ALL-UNNAMED" "--add-opens=java.base/java.nio=ALL-UNNAMED" "--add-opens=java.base/java.util=ALL-UNNAMED" "--add-opens=java.base/java.util.concurrent=ALL-UNNAMED" "--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED" "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED" "--add-opens=java.base/sun.nio.cs=ALL-UNNAMED" "--add-opens=java.base/sun.security.action=ALL-UNNAMED" "--add-opens=java.base/sun.util.calendar=ALL-UNNAMED" "--add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED" "-Djdk.reflect.useDirectMethodHandle=false" "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED" "--add-opens=java.base/java.lang=ALL-UNNAMED" "org.apache.spark.executor.CoarseGrainedExecutorBackend" "--driver-url" "spark://CoarseGrainedScheduler@spark-master:36357" "--executor-id" "33" "--hostname" "172.20.0.4" "--cores" "2" "--app-id" "app-20250628034119-0000" "--worker-url" "spark://Worker@172.20.0.4:43009" "--resourceProfileId" "0" worker节点的日志
06-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值