2024 蓝桥杯模拟赛 1 (div1)
=.= ^-^
A[蓝桥杯 2021 国 BC] 大写
思路:小写转换大写#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve(){ string s; cin>>s; for(int i=0;i<s.size();++i){ if(s[i]>='a'&&s[i]<='z')s[i]-=32; cout<<s[i]; } } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } return 0; }View Code
B[传智杯 #4 决赛] 小智的疑惑
思路:暴力判断#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve(){ string s; string f="chuanzhi"; cin>>s; int ans=0; for(int i=0;i+7<s.size();++i){ if(s[i]=='c'){ // cout<<i<<':'<<s[i]<<'\n'; bool ok=true; for(int j=i,x=0;x<f.size();++x,++j){ if(f[x]!=s[j]){ ok=false; break; } } if(ok)ans++,i+=7; } } cout<<ans; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } return 0; }View Code
C[蓝桥杯 2017 省 B] 日期问题
思路:枚举所有情况勒,需判断日期是否合法,且日期不重复#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve(){ map<string,string>mp; mp["01"]="31",mp["02"]="29",mp["03"]="31",mp["04"]="30",mp["05"]="31"; mp["06"]="30",mp["07"]="31",mp["08"]="31",mp["09"]="30",mp["10"]="31"; mp["11"]="30",mp["12"]="31"; string s; cin>>s; string a=s.substr(0,2),b=s.substr(3,2),c=s.substr(6,2); string aa,bb,cc; vector<string>ss(3); if(a<="59")aa="20"+a; else aa="19"+a; bb=b,cc=c; ss[0]=aa+"-"+bb+"-"+cc; if(c<="59")cc="20"+c; else cc="19"+c; aa=a,bb=b; ss[1]=cc+"-"+aa+"-"+bb; ss[2]=cc+"-"+bb+"-"+aa; sort(ss.begin(),ss.end()); map<string,string>st; for(int i=0;i<3;++i){ a=ss[i].substr(5,2),b=ss[i].substr(8,2); c=ss[i].substr(0,4); if(!(a>="01"&&a<="12"))continue; int y=stoi(c); if((y%4==0&&y%100!=0)||y%400==0)mp["02"]="29"; else mp["02"]="28"; if(b>mp[a]||b=="00")continue; if(st.count(ss[i]))continue; cout<<ss[i]<<'\n'; st[ss[i]]=1; } } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } return 0; }View Code
D[蓝桥杯 2023 省 B] 冶炼金属
思路:转换率的最大值为a/b的最小值,最小值为a/(b+1)+1的最大值#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve(){ int n;cin>>n; vector<PII>ve(n); for(int i=0;i<n;++i)cin>>ve[i].first>>ve[i].second; int ma=1e9,mi=0; for(int i=0;i<n;++i){ ma=min(ma,ve[i].first/ve[i].second); mi=max(mi,ve[i].first/(ve[i].second+1)+1); } cout<<mi<<' '<<ma; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } return 0; }View Code
E[蓝桥杯 2015 省 A] 饮料换购
思路:记录每次换瓶子后的瓶盖数,统计换得的总瓶子数即可#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve(){ int n;cin>>n; int ans=n,l=n,c; while(l>=3){ c=l/3; l-=2*c; ans+=c; } cout<<ans; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } return 0; }View Code
F[蓝桥杯 2017 省 AB] 分巧克力
思路:二分边长a,一个矩形中正方形的个数为(h/a)*(w/a)#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve(){ int n,k;cin>>n>>k; vector<int>h(n),w(n); int ma=0; for(int i=0;i<n;++i){ cin>>h[i]>>w[i]; ma=max(ma,min(h[i],w[i])); } int l=1,r=ma,x; auto check=[&](int a){ int c=0; for(int i=0;i<n;++i){ c+=(h[i]/a)*(w[i]/a); } return c>=k; }; while(l<=r){ int mid=l+r>>1; if(check(mid))l=mid+1,x=mid; else r=mid-1; } cout<<x; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } return 0; }View Code
G[蓝桥杯 2016 省 B] 交换瓶子
思路:预处理每个数对应的位置,若该位置上的数不是本身,找到目标数所在的位置进行交换,记录交换次数。 也可以用图解决...,参考https://blog.csdn.net/qq_29992017/article/details/129885881#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=1e4+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve(){ int n; cin>>n; vector<int>ve(n+5),s(n+5); int ans=0; for(int i=1;i<=n;++i){ cin>>ve[i]; s[ve[i]]=i; } for(int i=1;i<=n;++i){ if(i==ve[i])continue; int b=s[i]; s[i]=i,s[ve[i]]=b; swap(ve[i],ve[b]); ans++; } cout<<ans; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } return 0; }View Code
H[蓝桥杯 2015 省 B] 生命之树
思路:树形dp一下子#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=1e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; int n,w[N],ans,st[N],f[N]; vector<vector<int>>g; int dfs(int u){ for(auto v:g[u]){ if(st[v])continue; st[v]=1; f[v]=w[v]+dfs(v); if(f[v]>0)f[u]+=f[v]; } return f[u]; } void solve(){ cin>>n; g=vector<vector<int>>(n+1); for(int i=1;i<=n;++i){ cin>>w[i]; } for(int i=1;i<n;++i){ int u,v; cin>>u>>v; g[u].push_back(v),g[v].push_back(u); } st[1]=1; f[1]=w[1]+dfs(1); for(int i=1;i<=n;++i)ans=max(ans,f[i]); cout<<ans; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } return 0; }View Code
I[蓝桥杯 2016 省 A] 密码脱落
思路:可以在任意位置添加,最坏的情况是每个字符都添加一个,如何尽可能的少添加,可以将原序列与置换后的序列求最长公共子序列,这些字符就不需要添加,答案即为n-lcs(最长公共子序列)#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve(){ string s,f; cin>>s; int n=s.size(); f=s, std::reverse(s.begin(), s.end()); s=' '+s; f=' '+f; vector<vector<int>>ve(n+5,vector<int>(n+5)); for(int i=1;i<=n;++i){ for(int j=1;j<=n;++j){ ve[i][j]=max(ve[i-1][j],ve[i][j-1]); if(s[i]==f[j])ve[i][j]=max(ve[i][j],ve[i-1][j-1]+1); } } cout<<n-ve[n][n]; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } return 0; }View Code
J[蓝桥杯 2022 省 A] 爬树的甲壳虫
思路:f[i]表示到达i的时间期望,那么f[i]=(1-p[i])*f[i-1]+1+p[i]*(f[i-1]+f[i]),解方程得f[i]=(f[i-1]+1)/(1-p[i])#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; int ksm(int a,int b){ int ans=1; while(b){ if(b&1)ans=ans*a%mod; b>>=1; a=a*a%mod; } return ans; } void solve(){ int n;cin>>n; vector<int>p(n+1); for(int i=1;i<=n;++i){ int x,y; cin>>x>>y; p[i]=y*ksm(y-x,mod-2)%mod; } vector<int>f(n+1); for(int i=1;i<=n;++i){ f[i]=(f[i-1]+1)*p[i]%mod; } cout<<f[n]; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } return 0; }View Code
标签:typedef,const,winter,int,double,long,day1,2024,define From: https://www.cnblogs.com/bible-/p/17980600