A送分
B
大意:两个人两张牌 随机翻 求a翻出来的牌比b大的可能
| #include <cstdio> |
| #include <cmath> |
| #include <algorithm> |
| #include <iostream> |
| #include <cstring> |
| #include <vector> |
| #define ep emplace_back |
| using namespace std; |
| |
| void solve() { |
| int ans = 0; |
| int a1, b1, a2, b2; |
| cin >> a1 >> a2 >> b1 >> b2; |
| |
| int cnt1 = 0, cnt2 = 0; |
| if (a1 > b1) |
| cnt1++; |
| else if (a1 < b1) |
| cnt2++; |
| |
| if (a2 > b2) |
| cnt1++; |
| else if (a2 < b2) |
| cnt2++; |
| |
| if (cnt1 > cnt2) |
| ans += 2; |
| |
| cnt1 = cnt2 = 0; |
| if (a1 > b2) |
| cnt1++; |
| else if (a1 < b2) |
| cnt2++; |
| |
| if (a2 > b1) |
| cnt1++; |
| else if (a2 < b1) |
| cnt2++; |
| |
| if (cnt1 > cnt2) |
| ans += 2; |
| |
| cout << ans << "\n"; |
| } |
| |
| int main() { |
| int T = 1; |
| cin >> T; |
| while (T--) { |
| solve(); |
| } |
| return 0; |
| } |
| |
C
题目大意:有些区间被阻断 找连续的区间 判断最长的长度能否大于S
思路:保证l,r是不相交的 扫一遍所有的区间就好了 跑两个指针 pos1=0,pos2=l
| #include<iostream> |
| using namespace std; |
| void solve(){ |
| int n,s,m; |
| scanf("%d%d%d",&n,&s,&m); |
| bool ok=0; |
| int pos=0; |
| for(int i = 0; i < n; ++i){ |
| int l,r; |
| scanf("%d%d",&l,&r); |
| int k = l-pos; |
| if( k>=s ) |
| ok=1; |
| pos=r; |
| } |
| if(m-pos>=s) ok=1; |
| if(ok) cout<<"YES"; |
| else cout<<"NO"; |
| cout<<"\n"; |
| } |
| int main(){ |
| |
| int T; |
| cin>>T; |
| while(T--){ |
| solve(); |
| } |
| } |
D
题目大意:给定字串字符s t s某些字符可以修改 能否通过修改s st t是s子序列
思路:两个指针扫一遍,? 或者能匹配就让第二个指针往前跑,最后判断第二个指针跑到尾了
| #include <iostream> |
| #include <string> |
| #include <vector> |
| #include <unordered_set> |
| |
| using namespace std; |
| |
| void solve(){ |
| string s,t; |
| cin>>s>>t; |
| int j=0; |
| |
| for(int i = 0; i < s.size(); ++i){ |
| if(s[i] == '?' ){ |
| if(j < t.size()){ |
| s[i] = t[j]; |
| ++j; |
| } |
| else { |
| s[i] = 'a'; |
| } |
| } |
| else if( s[i] == t[j] and j<t.size()){ |
| ++j; |
| } |
| } |
| if(j == t.size()) cout<<"YES"<<"\n"<<s; |
| else cout<<"NO"; |
| cout<<"\n"; |
| } |
| int main(){ |
| int _; |
| cin>>_; |
| while(_ --){ |
| solve(); |
| } |
| } |
E:
题意:写下L,L+1,...R-1,R个数字,操作他,让一个数乘以三,另一个除以三。直到所有为0 求最小的操作次数
思路:先让L为0 ans 加上操作次数 观察到[3,8] opt=2,[9,26]opt=3 只需要计算区间长度乘以区间对应的opt次数就可
| #include <iostream> |
| #include <cmath> |
| #include <cstdio> |
| #define lld long long |
| using namespace std; |
| int f(int x){ |
| int ans=0; |
| while(x!=0){ |
| x/=3; |
| ans++; |
| } |
| return ans; |
| } |
| |
| void solve(){ |
| int L,R; |
| cin>>L>>R; |
| int K = f(L); |
| int M = f(R); |
| lld ans=0; |
| int a[50],b[50]; |
| for(int i=0;i<=32;++i){ |
| a[i] = pow(3,i); |
| b[i] = pow(3,i+1)-1; |
| } |
| ans+=2*f(L); |
| int pos=L+1; |
| for(int i=f(L+1) ; i <= M; ++i){ |
| |
| int pos2 = b[i-1]; |
| if(pos2>R){ |
| |
| pos2=R; |
| |
| ans+=(pos2-pos+1)*i; |
| break; |
| } |
| else { |
| |
| ans+=(pos2-pos+1)*i; |
| pos = a[i]; |
| } |
| |
| } |
| cout<<ans<<"\n"; |
| } |
| |
| int main(){ |
| int T; |
| cin>>T; |
| while(T--){ |
| solve(); |
| } |
| } |
| |
| |
| |
F:
大意:
思路:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效