牛客周赛 Round 70 个人题解

news/2025/2/7 0:20:03/文章来源:https://www.cnblogs.com/personaowl/p/18585052

牛客周赛 Round 70 个人题解 (A~G)

牛客周赛 Round 70

A. 小苯晨跑

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
void solve(){int a,b,c,d;cin>>a>>b>>c>>d;if(a==b && b==c && c==d){cout<<"NO"<<endl;}else cout<<"YES"<<endl;}
int main(){std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin>>T;while(T--) solve();return 0;
}

B. 小苯过马路

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
void solve(){int x,y,k,t;char c;cin>>x>>y>>k>>t>>c;if(c=='G'){int ans=0;if(k>=t) ans=t;else ans=t+k+x;cout<<ans<<endl;}else if(c=='R'){int ans=k+t;cout<<ans<<endl;}}
int main(){std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T=1;while(T--) solve();return 0;
}

C. 小苯的字符串染色

题目分析

  • 因为操作次数不大于n,所以直接对每个黑块染色即可
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
void solve(){int n;cin>>n;string s;cin>>s;s=" "+s;int tot=0;for(int i=1;i<=n;i++){if(s[i]=='1') tot++;}cout<<tot<<endl;for(int i=1;i<=n;i++){if(s[i]=='1'){cout<<i<<" "<<i<<endl;}}
}
int main(){std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin>>T;while(T--) solve();return 0;
}

D. 小苯的能量项链

题目分析

  • 维护前缀max 与后缀max,O(n)查询即可
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=5e5+10;
int a[N],pre[N],suf[N];
void solve(){int n,k;cin>>n>>k;for(int i=1;i<=n;i++) cin>>a[i];if(n==1){cout<<a[1]<<endl;return;}else if(n==2){cout<<a[1]+a[2]<<endl;return;}pre[0]=0,suf[n+1]=0;for(int i=1;i<=n;i++){pre[i]=max(a[i],pre[i-1]);}for(int i=n;i>=1;i--){suf[i]=max(a[i],suf[i+1]);}int ans=0;for(int i=1;i<=min(n-1,k+1);i++){int l=i;int r=max(i+1,n-k+i-1);int c1=pre[l],c2=suf[r];ans=max(ans,c1+c2);}cout<<ans<<endl;
}
signed main(){std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin>>T;while(T--) solve();return 0;
}

E. 小苯的最短路

题目分析

  • 考察异或性质的一道题,和之前 cf一道题类似codeforces.com/contest/2036/problem/F

  • f[l,r]表示l xor l+1 xor ... xor r

    • 当r%4==0时,f[0,r]=n
    • 当r%4==1时,f[0,r]=1
    • 当r%4==2时,f[0,r]=n+1
    • 当r%4==3时,f[0,r]=0
  • 由于是完全图,所以点1到每个点的最短路就是两点的边,所以经过化简后可得,ans=f[1,n] xor n个1的xor和

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
void solve(){int n;cin>>n;int t=0;if(n%4==0) t=n;else if(n%4==1) t=1;else if(n%4==2) t=n+1;else if(n%4==3) t=0;if(n%2==0){cout<<t<<endl;}else{int ans=1^t;cout<<ans<<endl;}
}
signed main(){std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin>>T;while(T--) solve();return 0;
}

F. 小苯的优雅好序列

题目分析

  • 题解的证明很好,这里引用一下
  • 首先不难发现,如果要满足这个数组的所有连续子数组都优秀,那么相邻两个数一定要满足条件,即a[i]|a[i+1]或者a[i+1]|a[i]
  • image-20241203205719781
  • 推出该式子后,只需找到相邻两项最大的d,然后枚举他的因数,再暴力check即可
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=5e4+10;
int a[N];
void solve(){int n,k;cin>>n>>k;for(int i=1;i<=n;i++){cin>>a[i];}int maxn=1e18,idx=0;for(int i=2;i<=n;i++){int tmp=abs(a[i]-a[i-1]);if(tmp && tmp<maxn){maxn=tmp;idx=i;}}if(maxn==1e18){cout<<k<<" "<<k*(k+1)/2<<endl;return;}int num=min(a[idx],a[idx-1]);vector<int> v;for(int i=1;i*i<=maxn;i++){if(maxn%i!=0) continue;int x=i-num;if(x>0 && x<=k) v.push_back(x);if(maxn/i!=i){int t=maxn/i;int _x=t-num;if(_x>0 && _x<=k) v.push_back(_x);}	}int cnt=0,ans=0;for(auto x:v){bool flag=1;for(int i=2;i<=n;i++){int t1=a[i-1]+x;int t2=a[i]+x;if(t1%t2 && t2%t1){flag=0;break;}}if(flag){cnt++;ans+=x;}}cout<<cnt<<" "<<ans<<endl;
}
signed main(){std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin>>T;while(T--) solve();return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/846323.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2024/12/3 【哈希表】

https://www.programmercarl.com/%E5%93%88%E5%B8%8C%E8%A1%A8%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80.html#%E5%B8%B8%E8%A7%81%E7%9A%84%E4%B8%89%E7%A7%8D%E5%93%88%E5%B8%8C%E7%BB%93%E6%9E%84 哈希表(Hash table)也称为散列表。 一. 哈希表是什么? 哈希表是根据关键码的…

基于GA遗传算法的PID控制器参数优化matlab建模与仿真

1.程序功能描述基于GA遗传算法的PID控制器参数优化,对比GA优化前后的PID控制器的控制曲线。 2.测试软件版本以及运行结果展示本程序和本人之前写的《基于GA遗传优化的PID控制器最优控制参数整定matlab仿真_ga-pid-CSDN博客》 区别是:之前的控制对象采用的是差分方程实现的,G…

基于MIMO系统的PE-AltMin混合预编码算法matlab性能仿真

1.算法仿真效果 matlab2022a仿真结果如下(完整代码运行后无水印): 仿真操作步骤可参考程序配套的操作视频。2.算法涉及理论知识概要在现代无线通信系统中,多输入多输出(Multiple-Input Multiple-Output, MIMO)技术是提高频谱效率和数据传输速率的关键。然而,随着天线数量…

E86 换根DP CF1324F Maximum White Subtree

视频链接: Maximum White Subtree - 洛谷 | 计算机科学教育新生态// 换根DP O(n) #include <bits/stdc++.h> using namespace std;const int N=200005; vector<int> e[N]; int n,a[N],f[N];void dfs(int u,int fa){f[u]=a[u];for(auto v:e[u]){if(v==fa)continu…

【Azure Developer】分享一段Python代码调用Graph API创建用户的示例

问题描述 在Azure门户(Create new user - Microsoft Azure 由世纪互联运营)中添加新用户,如果想通过代码来实现,有没有示例代码参考呢?问题解答 示例代码from azure.identity import AzureAuthorityHosts from azure.identity.aio import ClientSecretCredential from kiota…

Cocos creator制作透明背景桌面宠物

Cocos creator制作透明背景桌面宠物 目录Cocos creator制作透明背景桌面宠物来源前言验证可使用版本打包方案实现1、electron-js中main.js设置2、Cocos creator中宏配置3、Cocos creator中Canvas设置4、Cocos creator构建Web移动端5、修改Web移动端style.css6、使用electron-js…

【数据结构】 字典树trie详解

定义: 将多个字符串以树的方式存储即为字典树,如图,\(1,4,3,12\) 表示 \(cca\) ,我么用 \(ch[i][j]\) 来表示第 \(i\) 个节点的 \(j\) 字符所指向的下一个节点,\(tag[u]\) 表示节点 \(u\) 是否代表一个字符串的结尾,如果是的话,\(tag[u]=1\)。模板CODE 添加字符串 //n表…

五款实用报表工具对比推荐,各种免费好用的报表工具等你来试

概述 报表工具是企业进行数据分析、展示和决策支持的核心工具之一。本文将为大家介绍五款各具特色的报表工具,包括国产的山海鲸报表、FineReport,以及国际工具Databox、Pentaho Reporting和Zoho Analytics。通过详细分析它们的功能特点、优势和不足,帮助大家根据自身需求选择…

H5-24 CSS盒子模型(Box Model)

1、概念:所有HTML元素可以看作盒子,在CSS中,"box model"这一术语是用来设计和布局时使用CSS盒模型本质上是一个盒子,封装周围的元素HTML元素,它包括:外边距(margin),边框(border),内边距(padding),和实际内容(content) Margin(外边距):清楚边框外…

Logisim-022-☆16位快速加法器

电路文件所在 电路/3-data.circ 中的 ☆32位快速加法器仓库地址 https://gitee.com/gitliang/logisim-to-cpu

P11233 [CSP-S 2024] 染色 题解

我们设 \(dp_{x,y}\) 表示上一个红色是 \(x\),上一个蓝色是 \(y\) 时最大的价值。 容易发现转移为 \(dp_{a_i,x}=\max\limits_{j=1}^k dp_{k,x}+[k=a_i]a_i,dp_{x,a_i}=\max\limits_{j=1}^k dp_{x,k}+[k=a_i]a_i\)。其中 \(k\) 是值域。 容易发现,转移完后的 \(dp\) 数组中有…

Sybaris pg walkthrough Intermediate

nmap ┌──(root㉿kali)-[~/lab] └─# nmap -p- -A 192.168.166.93 Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-12-03 01:12 UTC Nmap scan report for 192.168.166.93 Host is up (0.071s latency). Not shown: 65519 filtered tcp ports (no-response) PORT …