目录
A - Once In My Life
B - 扫雷 1
F - 优秀字符串
J - 排列与合数
M - 有效算法
这次2024ccpc全国邀请赛(郑州)暨第六届ccpc河南省赛之旅我们获得了一个小小的省铜,被一道题卡了很久,导致我们想冲击更高的奖项的理想破灭,菜就多练,加训,争取以后拿到更高的奖项
原题链接:Dashboard - 2024 National Invitational of CCPC (Zhengzhou), 2024 CCPC Henan Provincial Collegiate Programming Contest - Codeforces
题意:输入两个数字,n,d。有一个幸运数字,1~9的数字至少出现一次,且数位为d的至少出现两次,n*k等于这个幸运数字,问k为多少
思路:先构造出一个数N。N=(1234567890+d)*pow(10,len)。len为n的位数
再构造出luck=luck-luck%n;就能求出幸运数字的大小,二者相除就能求出结果
#include
#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
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<>T;
while(T--) solve ();
return 0;
}
题意:输入n个数字,到达第i个位置时有i元,走一步多一块。可以购买探测器,探测器的价钱为ai,问最多能买多少个探测器
思路:用vector
#include
#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
using namespace std;
const int N = 1e5+5;
//int a[N],b[N];
void solve ()
{
int n;cin>>n;
vector 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>T;
while(T--) solve ();
return 0;
}
题意:给出n个字符串,求有几个符合题意
思路:直接模拟,虽然有点笨,但是过得快
#include
#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<>T;
while(T--) solve ();
return 0;
}
题意:求一个五位数是不是合数,如果是直接输出,如果不是随意排列求出一个合数,注意0不能当第一位
思路:直接输入五个字符,求0或者偶数,第一次交WA了一发,发现没有处理前导0,改了一次AC了
#include
#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<>T;
while(T--) solve ();
return 0;
}
题意:输入两个数组ai,bi。找最小的K,其中符合一些条件
思路:用二分答案的板子,二分k,找到一个相同的k作为check的条件。
当时比赛的时候脑子抽,知道用二分,一直在那二分x的大小,一直不会写,搞了好久也没弄出来,不然感觉能再A一题。
#include
#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>1;
if (check(mid))r=mid;
else l=mid+1;
}//像左找,二分,边界为l
cout<>T;
while(T--) solve ();
return 0;
}