2026.8.29-401-测试-总结
_starry_night · · 算法·理论
2026.8.29-401-测试-总结-在gonoi中
第一题:D26313
这道题老阴间了,我在这卡了足足1h,qwq
其实这道题就是模拟但是需要考虑很多地方
首先就是,有两个位置,一个是正在处理,另一个是在等待
所以我们要记录等待时间与到达时间,而不是记录他们的总和
然后就是,如果来了一个人就需要判断正在处理的处理完了没,没有就离开,处理完了不能直接搞完,还需要判断在等待的人能否直接搞定
最后再让来的人留下
code
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int xt,xs,yt,ys;
int n,sum;
int t,s;
signed main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
if(n<=2)
{
cout<<n;
return 0;
}
while(n--)
{
t=0,s=0;
cin>>t>>s;
if(t>=xt+xs)
{
if(t>=xt+xs+ys)
{
xt=t;
xs=s;
yt=0;
ys=0;
}
else
{
xt=max(xt+xs,yt);
xs=ys;
ys=s;
yt=t;
}
sum++;
}
else if(yt==0&&ys==0)
{
ys=s;
yt=t;
sum++;
}
// cout<<t<<' '<<s<<" "<<x<<" "<<y<<' '<<sum<<endl;
}
cout<<sum;
return 0;
}
第二题: D26312
如果移除一个包裹,那么这个差值->
我们定义
状态转移方程是:$ dp_i = 1 + [ai \not = a{i-1}]dp_{i-1} + [ai = a{i-2}]dp{i-2} + \sum {}{j \le i-3} [a_j \not = a_i] dp_j
code
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const int N=2e5+5;
const int mod=998244353;
int n;
int a[N];
ll dp[N];
map<int,ll>sum;
signed main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
ll all=0;
ll ans=0;
for(int i=1;i<=n;i++){
dp[i]=1;
ll val=((all-sum[a[i]])%mod+mod)%mod;
if(i>2&&a[i-2]==a[i]){
val=(val+dp[i-2])%mod;
}
if(i>2&&a[i-2]!=a[i]){
val=((val-dp[i-2])%mod+mod)%mod;
}
dp[i]=(dp[i]+val)%mod;
all=(all+dp[i])%mod;
sum[a[i]]=(sum[a[i]]+dp[i])%mod;
ans=(ans+dp[i])%mod;
}
cout<<ans<<endl;
return 0;
}