CF933-Div3 大致思路+题解
A - Rudolf and the Ticket
纯水题 暴力枚举直接过
#include<bits/stdc++.h>
#define fo(x,y,z) for(int (x)=(y);(x)<=(z);(x)++)
#define fu(x,y,z) for(int (x)=(y);(x)>=(z);(x)--)
inline int qr()
{
char ch=getchar();int x=0,f=1;
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);
return x*f;
}
#define qr qr()
typedef long long ll;
using namespace std;
const int Ratio=0;
const int N=200005;
const int maxx=INT_MAX;
int T,n,m,k;
int b[N],c[N];
int main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
cin>>T;
while(T--)
{
cin>>n>>m>>k;
int cnt=0;
for(int i=1;i<=n;i++)
cin>>b[i];
for(int i=1;i<=m;i++)
cin>>c[i];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(b[i]+c[j]<=k)
cnt++;
printf("%d\n",cnt);
}
return Ratio;
}
B - Rudolf and 121
题目中要求的是变换
换个角度就是变换
过一遍循环 当出现
输出
#include<bits/stdc++.h>
#define fo(x,y,z) for(int (x)=(y);(x)<=(z);(x)++)
#define fu(x,y,z) for(int (x)=(y);(x)>=(z);(x)--)
inline int qr()
{
char ch=getchar();int x=0,f=1;
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);
return x*f;
}
#define qr qr()
typedef long long ll;
using namespace std;
const int Ratio=0;
const int N=200005;
const int maxx=INT_MAX;
int n;
int a[N];
int main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
int T=qr;
while(T--)
{
n=qr;
fo(i,1,n)
a[i]=qr;
bool fla=true;
fo(i,1,n-2)
{
if(a[i]<0)
{
fla=false;
break;
}
a[i+1]-=2*a[i];
a[i+2]-=a[i];
a[i]=0;
}
if(fla==true&&a[n-1]==0&&a[n]==0)
printf("YES\n");
else
printf("NO\n");
}
return Ratio;
}
C - Rudolf and the Ugly String
字符串!噔咚噔
还是较为简单的 毕竟是
简单观察后就能发现要求的字符串
因此我们选用方便的
-
若前方存在
则答案++ 同时向右走 位 -
其次 若前方存在
或 答案++ 同时向右走 位 -
否则 向右走
位
#include<bits/stdc++.h>
#define fo(x,y,z) for(int (x)=(y);(x)<=(z);(x)++)
#define fu(x,y,z) for(int (x)=(y);(x)>=(z);(x)--)
inline int qr()
{
char ch=getchar();int x=0,f=1;
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);
return x*f;
}
#define qr qr()
typedef long long ll;
using namespace std;
const int Ratio=0;
const int N=200005;
const int maxx=INT_MAX;
int n,cnt;
string s;
int main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
int T=qr;
while(T--)
{
n=qr;
cin>>s;
cnt=0;
int i=0;
while(i<n)
{
if(i+5<=n&&s.substr(i,5)=="mapie")
cnt++,i+=5;
else if(i+3<=n&&s.substr(i,3)=="map")
cnt++,i+=3;
else if(i+3<=n&&s.substr(i,3)=="pie")
cnt++,i+=3;
else
i++;
}
printf("%d\n",cnt);
}
return Ratio;
}
D - Rudolf and the Ball Game
一眼转圈问题 这道题难在有个"
接下来 请出本场
众所周知(其实我
因此 在这道可能性很多且易重复的题里面
学习
#include<bits/stdc++.h>
#define fo(x,y,z) for(int (x)=(y);(x)<=(z);(x)++)
#define fu(x,y,z) for(int (x)=(y);(x)>=(z);(x)--)
inline int qr()
{
char ch=getchar();int x=0,f=1;
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);
return x*f;
}
#define qr qr()
typedef long long ll;
using namespace std;
const int Ratio=0;
const int N=200005;
const int maxx=INT_MAX;
int n,m,x;
int dis;
char c;
int main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
int T=qr;
while(T--)
{
n=qr,m=qr,x=qr;
set<int>dh,yy;
dh.insert(x-1);
fo(i,1,m)
{
dis=qr;
cin>>c;
if(c=='0')
for(auto i:dh)
yy.insert((dis+i)%n);
else if(c=='1')
for(auto i:dh)
yy.insert((i+n-dis)%n);
else if(c=='?')
for(auto i:dh)
{
yy.insert((dis+i)%n);
yy.insert((i+n-dis)%n);
}
dh=yy;
yy.clear();
}
printf("%d\n",dh.size());
for(auto i:dh)
printf("%d ",i+1);
printf("\n");
}
return Ratio;
}
E - Rudolf and k Bridges
一眼
首先 在输入桥时直接求出每一行的最优值
然后直接一个
记得开 !!!
插叙
第一遍
const int maxx=INT_MAX;
第二遍
"哦 不对 是long long"
const int maxx=1e18;
第三遍
const ll maxx=1e18..
乐
#include<bits/stdc++.h>
#define fo(x,y,z) for(int (x)=(y);(x)<=(z);(x)++)
#define fu(x,y,z) for(int (x)=(y);(x)>=(z);(x)--)
inline int qr()
{
char ch=getchar();int x=0,f=1;
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);
return x*f;
}
#define qr qr()
typedef long long ll;
using namespace std;
const int Ratio=0;
const int N=200005;
const ll maxx=1e18;
int n,m,k,d;
int dh[N];
ll dp[N],cost[N];
int main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
int T=qr;
while(T--)
{
n=qr,m=qr,k=qr,d=qr;
fo(k,1,n)
{
fo(i,1,m)
dh[i]=qr,dp[i]=maxx;
deque<pair<ll,ll> >q;//钱 位置
dp[1]=1;
q.push_back(make_pair(1,1));
for(int i=2;i<=m;i++){
dp[i]=min(dp[i],q.front().first+dh[i]+1);
while(!q.empty()&&dp[i]<=q.back().first)
q.pop_back();
q.push_back(make_pair(dp[i],i));
if(i-d>q.front().second)
q.pop_front();
}
// cout<<dp[m]<<endl;
cost[k]=dp[m];
// cost[k]=cost[k-1]+dp[m];
// cout<<cost[k]<<"||||||||"<<endl;
}
ll ans=maxx;
fo(i,1,n-k+1)
{
ll res=0;
fo(j,i,i+k-1)
res+=cost[j];
ans=min(ans,res);
}
printf("%lld\n",ans);
}
return Ratio;
}
F - Rudolf and Imbalance
严格单增 完美契合
一开始直接找初始
然后对最大差进行操作 用给的
然后还是
别的没什么太要紧的了 关于
#include<bits/stdc++.h>
#define fo(x,y,z) for(int (x)=(y);(x)<=(z);(x)++)
#define fu(x,y,z) for(int (x)=(y);(x)>=(z);(x)--)
typedef long long ll;
inline ll qr()
{
char ch=getchar();ll x=0,f=1;
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);
return x*f;
}
#define qr qr()
using namespace std;
const int Ratio=0;
const int N=200005;
const int maxint=INT_MAX;
const ll maxll=1e18;
int n,m,k;
ll a[N];
ll deta,detaa,lb,rb,ans;
set<ll>f,d;
int main()
{
// freopen("1.inll","r",stdin);
// freopen("1.out","w",stdout);
int T=qr;
while(T--)
{
n=qr,m=qr,k=qr;
f.clear(),d.clear();
deta=0,detaa=0;
fo(i,1,n)
{
a[i]=qr;
if(i!=1)//输入时直接寻找最大差和次小差
if(deta<a[i]-a[i-1])
{
detaa=deta;
deta=a[i]-a[i-1];
lb=a[i-1],rb=a[i];
//由于单增排序 左边界为小
}
else if(detaa<a[i]-a[i-1])
detaa=a[i]-a[i-1];
}
fo(i,1,m)
{
ll dd=qr;
d.insert(dd);
}
fo(i,1,k)
{
ll ff=qr;
f.insert(ff);
}
ans=deta;
for(auto i:f)
{
auto dh=d.lower_bound((lb+rb)/2-i),yy=dh;
//找最接近中间的 分开后两差大的尽量小
ll dh1=*dh,yy1=*yy;
//lower_bound值是指针类型无法运算 加*
ans=min(ans,max(dh1+i-lb,rb-i-dh1));
if(yy!=d.begin())
//不是队首 指针需向上取 保证答案最优
{
yy--;
yy1=*yy;
ans=min(ans,max(yy1+i-lb,rb-i-yy1));
}
}
cout<<max(detaa,ans)<<endl;
//此时再次比较次大值和更改后最大值
}
return Ratio;
}//
G - Rudolf and Subway
太蒻了 还没做出来。。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】