跳到正文

个人记录

国庆模拟赛04(下)

guagua1904约 4 分钟
原文

这是 2025年10月8日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2025年10月8日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 4 分钟

版本

  1. v2当前
  2. v1

1、U559540 美味度

这道题正解使用快慢指针,但我用的方法……不知道是什么。

代码:

C++
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
map<int,int>a;
map<int,int>b;
map<int,int>c;
#define int long long
signed main(){
	int T;
	cin>>T;
	while(T--){
		int n;
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		for(int i=1;i<=n;i++){
			cin>>b[i];
		}
		for(int i=1;i<=n;i++){
			c[i]=a[i]+b[i];
		}
		int ans=0;
		int cnt=0;
		int sum=0;
		for(int i=1;i<=n;i++){
			if(c[i]!=c[i-1]){
				ans=max(sum*cnt,ans);
				sum=a[i];
				cnt=1;
			}
			else{
				sum+=a[i];
				cnt++;
			}
		}
		ans=max(sum*cnt,ans);
		cout<<ans<<'\n';
	}
	return 0;
}

不知道为什么会用map估计是之前二维的搜索H×WH \times W==2e5的搜索做多了。用map的时间复杂度要多,在落落的去电脑上测试是65分,洛谷是85,改用普通数组直接在洛谷上ACAC了。

2、跳棋

这题主要是把两个部分分拿到了,那个X和Y的数量都为1的情况很好判断(r−l) mod 2(r-l)\bmod2判断就行了,但是X只有1个Y的数量不定的情况想了半天没想出来,于是和预判出题人直接

C++
cout<<"X\n";

但是竟然他对了?! 20分:

C++
#include<bits/stdc++.h>0
using namespace std;
int main(){
	int T;
	cin>>T;
	while(T--){
		string s;
		cin>>s;
		int X=0,Y=0;
		for(int i=0;i<s.size();i++){
			if(s[i]=='X')X++;
			if(s[i]=='Y')Y++;
		} 
		if(X==1&&Y==1){
			int l=0,r=0;
			for(int i=0;i<s.size();i++){
				if(s[i]=='X')l=i;
				if(s[i]=='Y')r=i;
			}
			if((r-l)%2==0){
				cout<<"Y\n";
			}
			else{
				cout<<"X\n";
			}
		}
		else if(X==1){
			cout<<"X\n";
		}
	}
	return 0;
}

3、划船计划

这道题在比赛的时候把双指针写出来了,但是是按照纪念品分组思路来的,这个时候发现欸?ww取什么?直接就等于最大值和最小值的平均值了,没有想到还要枚举ww

50分:

C++
#include<bits/stdc++.h>0
using namespace std;
int main(){
	int T;
	cin>>T;
	while(T--){
		string s;
		cin>>s;
		int X=0,Y=0;
		for(int i=0;i<s.size();i++){
			if(s[i]=='X')X++;
			if(s[i]=='Y')Y++;
		} 
		if(X==1&&Y==1){
			int l=0,r=0;
			for(int i=0;i<s.size();i++){
				if(s[i]=='X')l=i;
				if(s[i]=='Y')r=i;
			}
			if((r-l)%2==0){
				cout<<"Y\n";
			}
			else{
				cout<<"X\n";
			}
		}
		else if(X==1){
			cout<<"X\n";
		}
	}
	return 0;
}