第 8 场 小白入门赛
第 8 场 小白入门赛
最后一次小白赛了,之后要打强者赛咯
坤星球
思路
2024 * 2.5(小黑子题????)
代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin()+1,x.end()
void solve(){
cout<<2024*2.5<<endl;
return ;
}
signed main(){
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
二进制王国
思路
第一眼字符串排序,wa了,后来发现需要自定义排序,我们要保证高位尽可能是0,因此我们就可以写一个自定义排序,判断字符串a+b是否小于b+a
Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin()+1,x.end()
bool cmp(string a,string b){
string s1=a+b;
string s2=b+a;
return s1<s2;
}
void solve(){
int n;
cin>>n;
std::vector<string> a(n+1);
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(all(a),cmp);
for(int i=1;i<=n;i++){
cout<<a[i];
// return ;
}
// cout<<a[1].substr(a[2].size());
return ;
}
signed main(){
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
djwcb
思路:
我是分类讨论做的,但是据说欧拉定理也可以做?总感觉杀鸡用牛刀了?
(但是我写的巨长)
Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin()+1,x.end()
void solve(){
int x;
string p;
cin>>x>>p;
int x3=0;
for(int i=0;i<p.size();i++){
int x1=x3*10+(p[i]-'0');
int x2=x1%4;
x3=x2;
}
// cout<<x3<<endl;
int x4=0;
for(int i=0;i<p.size();i++){
int x1=x4*10+(p[i]-'0');
int x2=x1%2;
x4=x2;
}
x3-=1;
x4-=1;
if(x%10==0){
cout<<0<<endl;
return ;
}
else{
int x1=x%10;
if(x1==1){
cout<<1<<endl;
}
else if(x1==5){
cout<<5<<endl;
return ;
}
else if(x1==6){
cout<<6<<endl;
return ;
}
else if(x1==2){
if(x3==0){
cout<<2<<endl;
return ;
}
else if(x3==1){
cout<<4<<endl;
return ;
}
else if(x3==2){
cout<<8<<endl;
return ;
}
else{
cout<<6<<endl;
return ;
}
}
else if(x1==3){
if(x3==0){
cout<<3<<endl;
return ;
}
else if(x3==1){
cout<<9<<endl;
return ;
}
else if(x3==2){
cout<<7<<endl;
return ;
}
else{
cout<<1<<endl;
return ;
}
}
else if(x1==4){
if(x4==0){
cout<<4<<endl;
return ;
}
else{
cout<<6<<endl;
return ;
}
}
else if(x1==7){
if(x3==0){
cout<<7<<endl;
return ;
}
else if(x3==1){
cout<<9<<endl;
return ;
}
else if(x3==2){
cout<<3<<endl;
return ;
}
else{
cout<<1<<endl;
return ;
}
}
else if(x1==8){
if(x3==0){
cout<<8<<endl;
return ;
}
else if(x3==1){
cout<<4<<endl;
return ;
}
else if(x3==2){
cout<<2<<endl;
return ;
}
else{
cout<<6<<endl;
return ;
}
}
else if(x1==9){
if(x4==0){
cout<<9<<endl;
return ;
}
else{
cout<<1<<endl;
return ;
}
}
}
}
signed main(){
int t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}
求解线性方程组
思路:
很明显,我们只要确定了x1和x2的答案,后面也就自然而然的确定了,但是需要注意的是:有可能他不是正确的答案,所以我们需要注意一下,做一个标记就可以了。
Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin()+1,x.end()
const int N=1e6+10;
void solve(){
int n;
cin>>n;
std::vector<int> a(n+1);
for(int i=1;i<=n;i++){
cin>>a[i];
}
std::vector<int> v(n+1);
for(auto x:{0,1}){
for(auto y:{0,1}){
v[1]=x;
v[2]=y;
bool f=true;
int now=3;
for(int i=3;i<=n;i++){
int res=a[i-1]-v[i-1]-v[i-2];
if(res<0||res>=2){
f=false;
break;
}
v[i]=res;
}
if(!f){
continue;
}
if(v[n]+v[n-1]!=a[n]){
continue;
}
for(int i=1;i<=n;i++){
cout<<v[i]<<" ";
}
return ;
}
}
}
signed main(){
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
美丽圆环
思路:
我们不考虑操作二的操作次数,因此我们就可以先将数列排好序,这样只需要判断一下开头和结尾就好了,只需要将开头和结尾构造好就可以了。
Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin()+1,x.end()
void solve(){
int n;
cin>>n;
std::vector<int> a(n+1);
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(all(a));
// int res=2;
int ans=2;
// cout<<ans<<endl;
if(n==2){
if(a[1]==a[2]){
ans=0;
}
else{
ans=1;
}
}
else{
if(a[1]==a[2]){
if(a[n-1]==a[n]){
ans=0;
// cout<<"#1"<<endl;
}
else{
ans=1;
// cout<<"#2"<<endl;
}
}
else{
if(a[n-1]==a[n-2]||a[2]==a[3]||a[n-1]==a[n]){
ans=1;
// cout<<"#3"<<endl;
}
}
}
cout<<ans<<endl;
return ;
}
signed main(){
int t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}
小蓝的跳跃
思路:
经典的动态规划问题,我们只需要找到跳出去的最大心情值和最小心情值,只要x在这个范围当中就可以,因为如果我们我们只需要在最大值所跳跃的方案中改变一下,多跳几个芒果味的就可以-1
Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin()+1,x.end()
void solve(){
int n,x;
cin>>n>>x;
std::vector<int> a(n+3,0);
for(int i=1;i<=n;i++){
cin>>a[i];
}
std::vector<int> f1(n+3,0);
std::vector<int> f2(n+3,0);
f1[1]=f2[1]=a[1];
// f1[2]=f2[2]=a[2];
for(int i=2;i<=n+1;i++){
f1[i]=max(f1[i-1],f1[i-2])+a[i];
f2[i]=min(f2[i-1],f2[i-2])+a[i];
}
if(f1[n+1]>=x&&f2[n+1]<=x){
cout<<"Yes"<<endl;
return ;
}
else{
cout<<"No"<<endl;
return ;
}
}
signed main(){
int t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}
总结
这场小白赛还是比较简单的,都是一些很基础的知识点,但是还是需要多多练习!!!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?