牛客小白月赛57 (A-E)
A- 最大面积
题意: 给出两个矩形,求相交面积
题解: 两个举行的最小边相乘

#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; const int N=2e5+5; const ll inf=1e18; const ll mod=998244353; signed main(){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); ll x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; cout<<min(y1,y2)*min(x1,x2); }
B- 种树
题意 : 0 1 字符串,每次可以在1的位置选择一个方向,将所有位置都变成1,问最少需要几次将所有位置变成1
题解: 题目说明一定有解,所以判断第一个位置和最后一个位置是否有1,有的话那么一步就可以完成,没有就两步,记住上来先判断字符串中有没有0。

#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; const int N=2e5+5; const ll inf=1e18; const ll mod=998244353; signed main(){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); ll n;cin>>n; string s;cin>>s; bool flag=0; bool st=0; for(ll i=0;i<s.size();i++){ if(s[i]=='0') st=1;//判断有没有0 } ll ans=0; if(s[0]=='0') ans++; if(s.back()=='0') ans++; cout<<ans; }
C-奇怪的电梯
题意: 一个n层电梯,开始在x层,每次选择一个k,x-k到x+k的层不能去,为最后能不能到y层。
题解: 这个题不能考虑的太简单,有坑,首先对于一个位置,如果不能一次直接去到,那么我们可以先去一个距离他很远的位置,然后再二次转回来。

#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; const int N=2e5+5; const ll inf=1e18; const ll mod=998244353; signed main(){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); ll t;cin>>t; while(t--){ ll n,k,a,b;cin>>n>>k>>a>>b; if(a==b){ cout<<"YES"<<endl;continue;//如果开始和终点相同 } if(k>n||a>n||b>n){ cout<<"NO"<<endl;continue; } if(abs(a-b)>k) cout<<"YES"<<endl;//如果起点终点的距离直接复合就YES else { if(a>b) swap(a,b); ll p=n-b;//判断终点距离最后一层的距离,如果距离>k,那么可以让终点作为中转 ll q=a-1;//判断起点距离 if(p>k||q>k){ cout<<"YES"<<endl;continue;} ll pt=a+k+1;//到达刚好大于K的位置 if(pt>n){//判断位置是否合法 cout<<"NO"<<endl; } else if(b-1>k){//从pt位置往起点方向,然后判断终点距离第一层的距离能否>k cout<<"YES"<<endl; } else cout<<"NO"<<endl; } } }
D-最大gcd
题意: 给出n个数,求出其中最大的gcd(a[i],a[j])
题解: 我们可以枚举因子,因为是求最大值,反向枚举即可

#include<bits/stdc++.h> using namespace std; typedef int ll; typedef pair<ll,ll> pll; const int N=1e6+5; const ll inf=1e18; const ll mod=998244353; ll maxn,ans=1; unordered_map<int,int> mp; void solve(){ for(ll i=maxn;i>=2;i--){ if(mp[i]>=2){ cout<<i<<endl;exit(0); } ll j=i; ll flag=0; while(j<=maxn){ if(mp[j]) flag+=mp[j]; if(flag>=2){ cout<<i;exit(0); } j+=i; } } } signed main(){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); ll n;cin>>n; for(ll i=1;i<=n;i++){ int a; cin>>a;mp[a]++; if(maxn<a) maxn=a; } solve(); cout<<ans; }
E-一道难题
题意: 给出一个数字n,在1-n中找出由01构成的,至少包含3个连续的1的数字个数。
题解: dfs+优化,这里不要枚举数字,然后判断是都小于筛选,因为这个数字的范围为1-10^23,这样的数字只能用字符串来存储,而字符串比较大小的复杂度不是O(1),次数多了很浪费时间,所以要避免这一点,所以应该加上限制条件,来保证枚举的每个情况都是 <=n的。

#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; const int N=2e5+5; const ll inf=1e18; const ll mod=998244353; ll a[N],maxn,ans,n; string s; vector<ll> q; bool check(string a,string b){ return a>b; } void bfs(ll pos,ll limt,ll cnt){ if(pos>=s.size()){ ans+=cnt>=3?1:0;return ;//判断这种情况是否符合 } ll up=0; if(limt){ up=1;}//如果之前已经有数字小于呢一位了,那么后面的数字就0,1随便取了 if(q[pos]>=1) up=1;//如果这一位本身的数字>=1,那么0,1也随便取,都不会大于他本身 for(ll i=0;i<=up;i++){ bfs(pos+1,(i<q[pos]?1:limt),(i==1||cnt>=3?cnt+1:0)); } } signed main(){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin>>s; for(ll i=0;i<s.size();i++){ q.push_back(s[i]-'0'); } bfs(0,0,0); cout<<ans; }
分类:
做题记录
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!