[codeforces 1281B] Azamon Web Services 字符串+strcmp时间复杂度理解

本文详细解析了Codeforces竞赛中1281B题AzamonWebServices的解决思路与代码实现,重点讨论了字符串处理及strcmp函数的时间复杂度,通过实例展示了如何避免常见错误,提供了完整的GNU C++11代码示例。

[codeforces 1281B] Azamon Web Services   字符串+strcmp时间复杂度理解

总目录详见https://blog.youkuaiyun.com/mrcrack/article/details/103564004

在线测评地址https://codeforces.com/contest/1281/problem/B

 

ProblemLangVerdictTimeMemory
B - Azamon Web Services GNU C++11Accepted31 ms0 KB

 //Wrong answer on test 2反复阅读代码
//才发现此处错误//else if(strcmp(s,c)==0)printf("---\n");//ACB ACB就可推翻该句,写错一句。
//Time limit exceeded on test 4
//基本可以确认strcmp()需耗时O(n)

#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 5010
using namespace std;
char s[maxn],c[maxn],d[maxn],e;
void swap(char &a,char &b){
	char t;
	t=a,a=b,b=t;
}
int main(){
	int t,i,j,len,pos,check;
	scanf("%d",&t);
	while(t--){
		scanf("%s%s",s,c);
		if(strcmp(s,c)<0)printf("%s\n",s);
		//else if(strcmp(s,c)==0)printf("---\n");//ACB ACB就可推翻该句,写错一句。
		else{
			len=strlen(s),check=0,pos=-1;
			strcpy(d,s);
			sort(d+0,d+len);
			for(i=0;i<len;i++)
				if(s[i]!=d[i]){
					pos=i;
					break;
				}
			if(pos==-1){
				printf("---\n");
				continue;
			}
			check=0;
			for(i=pos+1;i<len;i++){//因值为d[pos]的字符在s[]中位置不确定,故得用循环傻找
				swap(s[i],s[pos]);
				if(strcmp(s,c)<0){
					printf("%s\n",s);
					check=1;
					break;
				}
				swap(s[pos],s[i]);
			}
			if(!check)printf("---\n");
		}
	}
	return 0;
}

 

当前提供的引用内容并未提及关于Codeforces比赛M1的具体时间安排[^1]。然而,通常情况下,Codeforces的比赛时间会在其官方网站上提前公布,并提供基于不同时区的转换工具以便参赛者了解具体开赛时刻。 对于Codeforces上的赛事而言,如果一场名为M1的比赛被计划举行,则它的原始时间一般按照UTC(协调世界时)设定。为了得知该场比赛在UTC+8时区的确切开始时间,可以遵循以下逻辑: - 前往Codeforces官网并定位至对应比赛页面。 - 查看比赛所标注的标准UTC起始时间。 - 将此标准时间加上8小时来获取对应的北京时间(即UTC+8)。 由于目前缺乏具体的官方公告链接或者确切日期作为依据,无法直接给出Codeforces M1比赛于UTC+8下的实际发生时段。建议定期访问Codeforces平台查看最新动态更新以及确认最终版程表信息。 ```python from datetime import timedelta, datetime def convert_utc_to_bj(utc_time_str): utc_format = "%Y-%m-%dT%H:%M:%SZ" bj_offset = timedelta(hours=8) try: # 解析UTC时间为datetime对象 utc_datetime = datetime.strptime(utc_time_str, utc_format) # 转换为北京时区时间 beijing_time = utc_datetime + bj_offset return beijing_time.strftime("%Y-%m-%d %H:%M:%S") except ValueError as e: return f"错误:{e}" # 示例输入假设某场Codeforces比赛定于特定UTC时间 example_utc_start = "2024-12-05T17:35:00Z" converted_time = convert_utc_to_bj(example_utc_start) print(f"Codeforces比赛在北京时间下将是:{converted_time}") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值