2024CCPC全国邀请赛(郑州)暨第六届CCPC河南省赛补题

目录

[A - Once In My Life](#A - Once In My Life)

[B - 扫雷 1](#B - 扫雷 1)

[F - 优秀字符串](#F - 优秀字符串)

[J - 排列与合数](#J - 排列与合数)

[M - 有效算法](#M - 有效算法)


这次2024ccpc全国邀请赛(郑州)暨第六届ccpc河南省赛之旅我们获得了一个小小的省铜,被一道题卡了很久,导致我们想冲击更高的奖项的理想破灭,菜就多练,加训,争取以后拿到更高的奖项

原题链接:Dashboard - 2024 National Invitational of CCPC (Zhengzhou), 2024 CCPC Henan Provincial Collegiate Programming Contest - Codeforces


A - Once In My Life

题意:输入两个数字,n,d。有一个幸运数字,1~9的数字至少出现一次,且数位为d的至少出现两次,n*k等于这个幸运数字,问k为多少

思路:先构造出一个数N。N=(1234567890+d)*pow(10,len)。len为n的位数

再构造出luck=luck-luck%n;就能求出幸运数字的大小,二者相除就能求出结果

cpp 复制代码
#include <bits/stdc++.h>
#define int long long 
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define fi first
#define se second
#define PII pair<int,int>
using namespace std;
const int N = 1e5+5;
int a[N],b[N];
void solve ()
{
	int n,k;cin>>n>>k;
	int len=to_string(n).size();//将n转换成string类型,再用size求长,可以求出n的位数

	int luck=(1234567890+k)*pow(10,len);//构造N

	luck+=n;

	luck-=luck%n;
	cout<<luck/n<<'\n';
}

signed main ()
{
	IOS;
	int T =1;
	cin>>T;
	while(T--) solve ();
	return 0;
}

B - 扫雷 1

题意:输入n个数字,到达第i个位置时有i元,走一步多一块。可以购买探测器,探测器的价钱为ai,问最多能买多少个探测器

思路:用vector<PII>数组来存储价钱以及坐标,将一些不符合的数据从数组里面抹掉,剩下的数组直接求值即可。pair还是很好用的。

cpp 复制代码
#include <bits/stdc++.h>
#define int long long 
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define  fi first
#define  se second
#define  PII pair<int,int>
using namespace std;
const int N = 1e5+5;
//int a[N],b[N];
void solve ()
{
	int n;cin>>n;
	vector <PII> a;
	for (int i=1;i<=n;i++)
	{
		int x;cin>>x;
		while (!a.empty()&&a.back().fi>=x) a.pop_back();//这里将不符合的都抹掉
		a.push_back({x,i});
	}
	int len=a.size();//后续操作就很简单了,直接求解
	int ans=a[0].se/a[0].fi;int t=a[0].se%a[0].fi;
	for (int i=1;i<len;i++)
	{
		ans+=(a[i].se-a[i-1].se+t)/a[i].fi;
		t=(a[i].se-a[i-1].se+t)%a[i].fi;
	}
	cout<<ans<<'\n';
}

signed main ()
{
	IOS;
	int T =1;
//	cin>>T;
	while(T--) solve ();
	return 0;
}

F - 优秀字符串

题意:给出n个字符串,求有几个符合题意

思路:直接模拟,虽然有点笨,但是过得快

cpp 复制代码
#include <bits/stdc++.h>
#define int long long 
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 1e5+5;
int a[N],b[N];
void solve ()
{
	int n;cin>>n;int ans=0;
	for (int i=1;i<=n;i++)
	{
		string s;cin>>s;
		int f=0;
		if (s.size()!=5)f=1;
		if (s[2]!=s[4])f=1;
		if (s[0]==s[1]||s[0]==s[2]||s[0]==s[3]||s[1]==s[2]||s[1]==s[3]||s[2]==s[3])f=1;
		if (f==0)ans++;
	}
	cout<<ans;
}

signed main ()
{
	IOS;
	int T =1;
//	cin>>T;
	while(T--) solve ();
	return 0;
}

J - 排列与合数

题意:求一个五位数是不是合数,如果是直接输出,如果不是随意排列求出一个合数,注意0不能当第一位

思路:直接输入五个字符,求0或者偶数,第一次交WA了一发,发现没有处理前导0,改了一次AC了

cpp 复制代码
#include <bits/stdc++.h>
#define int long long 
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define first fi
#define second se
using namespace std;
const int N = 1e5+5;
int a[N],b[N];
void solve ()
{
	int n;cin>>n;
	for (int i=1;i<=n;i++)
	{
		char ch1,ch2,ch3,ch4,ch5;
		cin>>ch1>>ch2>>ch3>>ch4>>ch5;
		if (ch1=='0') cout<<ch2<<ch3<<ch4<<ch5<<ch1<<'\n';
		else if (ch2=='0') cout<<ch1<<ch3<<ch4<<ch5<<ch2<<'\n';
		else if (ch3=='0')cout<<ch2<<ch1<<ch4<<ch5<<ch3<<'\n';
		else if (ch4=='0')cout<<ch2<<ch3<<ch1<<ch5<<ch4<<'\n';
		else if (ch5=='0')cout<<ch2<<ch3<<ch4<<ch1<<ch5<<'\n';
		else 
		{
			if ((ch1-'0')%2==0)cout<<ch2<<ch3<<ch4<<ch5<<ch1<<'\n';
			else if ((ch2-'0')%2==0)cout<<ch1<<ch3<<ch4<<ch5<<ch2<<'\n';
			else if ((ch3-'0')%2==0)cout<<ch2<<ch1<<ch4<<ch5<<ch3<<'\n';
			else if ((ch4-'0')%2==0)cout<<ch2<<ch3<<ch1<<ch5<<ch4<<'\n';
			else if ((ch5-'0')%2==0)cout<<ch2<<ch3<<ch4<<ch1<<ch5<<'\n';
			else cout<<"97531"<<'\n';
		}
		
	}
}

signed main ()
{
	IOS;
	int T =1;
//	cin>>T;
	while(T--) solve ();
	return 0;
}

M - 有效算法

题意:输入两个数组ai,bi。找最小的K,其中符合一些条件

思路:用二分答案的板子,二分k,找到一个相同的k作为check的条件。

当时比赛的时候脑子抽,知道用二分,一直在那二分x的大小,一直不会写,搞了好久也没弄出来,不然感觉能再A一题。

cpp 复制代码
#include <bits/stdc++.h>
#define int long long 
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define first fi
#define second se
using namespace std;
const int N = 3e5+5;
int a[N],b[N];
int n;
int check (int k)
{
    //将绝对值去掉会出现两种情况,一种找x的最大值,一种找x的最小值,判断最小值-最大值能否大于等于0;
	int ma=INT_MIN,mi=INT_MAX;
	for (int i=1;i<=n;i++)
	{
		ma=max(a[i]-k*b[i],ma);//找最大值
		mi=min(a[i]+k*b[i],mi);//找最小值
	}
	if (mi-ma>=0)return 1;
	else return 0;
}

void solve ()
{
	cin>>n;
	for (int i=1;i<=n;i++) cin>>a[i];
	for (int j=1;j<=n;j++) cin>>b[j];
	int l=-1,r=1e9;
	while (l<r)
	{
		int mid =l+r>>1;
		if (check(mid))r=mid;
		else l=mid+1;
	}//像左找,二分,边界为l
	cout<<l<<'\n';
}

signed main ()
{
	IOS;
	int T =1;
	cin>>T;
	while(T--) solve ();
	return 0;
}
相关推荐
2501_915106321 天前
iOS 使用记录和能耗监控实战,如何查看电池电量消耗、App 使用时长与性能数据(uni-app 开发调试必备指南)
android·ios·小程序·uni-app·cocoa·iphone·webview
栒U1 天前
一文从零部署vLLM+qwen0.5b(mac本地版,不可以实操GPU单元)
人工智能·macos·vllm
Swift社区1 天前
在企业内部分发 iOS App 时如何生成并使用 manifest.plist
macos·ios·cocoa
他们都不看好你,偏偏你最不争气1 天前
【iOS】 单例模式
macos·objective-c·cocoa
2501_915918411 天前
uni-app 项目 iOS 上架效率优化 从工具选择到流程改进的实战经验
android·ios·小程序·uni-app·cocoa·iphone·webview
FreeBuf_2 天前
苹果用户速更新!macOS存严重漏洞,用户隐私数据面临泄露风险
macos
Thomas21432 天前
macos deepctr_torch虚拟环境配置
macos
wxl7812272 天前
MacOS 运行CosyVoice
macos·cosyvoice·语音自然
lichong9512 天前
【混合开发】vue+Android、iPhone、鸿蒙、win、macOS、Linux之video 的各种状态和生命周期调用说明
android·vue.js·macos
程序务虚论2 天前
mac M1上安装windows虚拟机报错
windows·macos·parallels