L5-f2021ljh模拟赛 题解
前言
十年oi一场空,不开ll见祖宗
300->270,警钟长鸣
出题人忘卡T1 a=1了(好耶)
考试结束后又加上了(270->260 警钟长鸣)
T1
CF1542B
原题可以转化成n是否能写成
显然,若本次操作为乘法,则结果变为
由于y是任意选取的,所以这个数仍是
若本次操作为加法,则结果变为
将式子转为
记得特判
/*
* @Author: 2019yyy
* @Date: 2022-10-13 20:30:39
* @LastEditors: 2019yyy
* @LastEditTime: 2022-10-13 22:00:56
* @FilePath: \code\codeBiulders\460A.cpp
* @Description:
*
* I love Chtholly forever
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int T;
cin>>T;
while(T--){
int n,x,y;
cin>>n>>x>>y;
if(x==1){if((n-1)%y==0){cout<<"Yes\n";}else{cout<<"No\n";}continue;}
bool flag=false;
for(int i=1;i<=n;i=x*i){
if((n-i)%y==0){
cout<<"Yes\n";
flag=true;
break;
}
}
if(!flag){
cout<<"No\n";
}
}
return 0;
}
T2
CF1016D
显然把步数平均是最好选择,因此我们每次走
如果中间超过了上限就输出NO
另外要特判步数摊不开,也就是
/*
* @Author: 2019yyy
* @Date: 2022-10-13 21:07:47
* @LastEditors: 2019yyy
* @LastEditTime: 2022-10-13 21:15:58
* @FilePath: \code\codeforces\460B.cpp
* @Description:
*
* I love Chtholly forever
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
int ans[210000];
signed main(){
int n,k,s;
cin>>n>>k>>s;
int t=s/k;
int p=s-k*t;
int now=1;
for(int i=1;i<=k;i=i+2){
now=now+t+(((p--)>0)?1:0);
ans[i]=now;
now=now-t-(((p--)>0)?1:0);
ans[i+1]=now;
if(ans[i]>n||ans[i]==ans[i+1]){
cout<<"NO\n";
return 0;
}
}
cout<<"YES\n";
for(int i=1;i<=k;i++){
cout<<ans[i]<<' ';
}
return 0;
}
T3
CF1681D
纯dfs连样例都过不去,所以我们要加优化
每次最小乘
然后我们考虑IDA*:每次增加一位数或不增加,我们可以统计出x的位数t,那么估价函数为f(x)=n-t
dfs后别忘了回溯,重新统计位数(我在这卡了20分钟)
/*
* @Author: 2019yyy
* @Date: 2022-10-13 21:20:47
* @LastEditors: 2019yyy
* @LastEditTime: 2022-10-13 21:29:01
* @FilePath: \code\codeBiulders\460C.cpp
* @Description:
*
* I love Chtholly forever
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,x,ans;
bool vis[10];
int getnum(int x){
memset(vis,0,sizeof(vis));
int len=0;
while(x){
int t=x%10;
vis[t]=true;
x=x/10;
len++;
}
return len;
}
bool dfs(int x,int t){
int len=getnum(x);
if(t+n-len>ans){
return 0;
}
if(len==n){
cout<<ans<<'\n';
exit(0);
}
for(int i=2;i<=9;++i){
if(vis[i]==true){
dfs(x*i,t+1);
getnum(x);
}
}
return 0;
}
signed main(){
cin>>n>>x;
int k=log2(2e19/x);
while(ans<=k&&!dfs(x,0)){
ans++;
}
cout<<-1<<'\n';
return 0;
}
T4
CF1628D1
我还不会,待更