【牛客训练记录】牛客周赛 Round 70
训练情况
赛后反思
D题应该能出的,只是晚自习的debuff叠满了
A题
判断 \(4\) 个数是否相等,排序判断首位是否一样即可。
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'
using namespace std;
void solve(){
int a[4];
for(int i = 0;i<4;i++) cin>>a[i];
sort(a,a+4);
if(a[0] != a[3]) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
signed main(){
int T; cin>>T; while(T--)
solve();
return 0;
}
B题
简单分类讨论,如果是红灯答案是剩余红灯时间+过马路时间,如果是绿灯但是来不及就是剩余绿灯时间+红灯时间+过马路时间,如果是绿灯来得及就是过马路时间。
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'
using namespace std;
void solve(){
int x,y,k,t; cin>>x>>y>>k>>t;
string s; cin>>s;
if(s == "G"){
if(k >= t) cout<<t<<endl;
else cout<<k+x+t<<endl;
} else if(s == "R"){
cout<<k+t<<endl;
}
}
signed main(){
// int T; cin>>T; while(T--)
solve();
return 0;
}
C题
这题不需要在意操作次数,把所有的 \(1\) 都变成 \(0\) 即可,记录 \(1\) 的位置直接输出即可。
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'
using namespace std;
void solve(){
int n; cin>>n;
string s; cin>>s;
vector<int> ans;
for(int i = 0;i<n;i++){
if(s[i] == '1') ans.push_back(i);
}
cout<<ans.size()<<endl;
for(auto i:ans){
cout<<i+1<<" "<<i+1<<endl;
}
}
signed main(){
int T; cin>>T; while(T--)
solve();
return 0;
}
E题
这题写了一个 floyd 全源最短路,输出了前 \(100\) 的答案,我们通过观察发现有规律,对于 \(\le 10\) 的部分我们直接输出,之后就是一个长度为 \(4\) 的循环节。
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'
using namespace std;
const int N = 1e3;
int dis[N][N];
int a[21] = {0,0,3,1,4,0,7,1,8,0,11};
void solve(){
int n; cin>>n;
// cout<<n<<" ";
if(n<=10) cout<<a[n]<<endl;
else {
int tn = n;
n-=11;
if(n%4==0) cout<<1<<endl;
else if(n%4 == 1) cout<<tn<<endl;
else if(n%4 == 2) cout<<0<<endl;
else cout<<tn+1<<endl;
}
}
signed main(){
int T; cin>>T; while(T--)
solve();
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步