51nod-3978列车
https://class.51nod.com/Html/Textbook/Problem.html#problemId=3978&textbookChapterId=724
https://class.51nod.com/Html/Textbook/ChapterIndex.html#textbookId=126&chapterId=337
这里一次发车的转移是
最后一个式子min中下面的部分错了,应该再加一个
而且
插入都在尾部,弹出都在开头。
如果弹空了,此时只有上面情况,
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=1000010;
int n,t[N],q[N];
ll f[N],s;
int main(){
#ifdef LOCAL
freopen("1.txt","r",stdin);
#endif
#ifndef LOCAL
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
#endif
cin>>n>>s;
t[0]=-1;
for(int i=1;i<=n;++i)cin>>t[i],t[i]=max(t[i],t[i-1]+1);
memset(f+1,0x3f,n*8);
int hh=0,tt=0;
#define j q[hh]
for(int i=1;i<=n;++i){
while(hh<=tt&&f[j]-j-1<t[i]-i)++hh;
ll K=hh>tt?i-1:j-1;
if(K>=0)f[i]=s-1ll+s+i+t[i]-K;
if(hh<=tt)
f[i]=min(f[i],s+s-2ll+i+i+f[(K+1)]-(K+1)-(K+1));//
q[++tt]=i;
}
cout<<f[n];
return 0;
}
本文作者:wscqwq
本文链接:https://www.cnblogs.com/wscqwq/p/18323838
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
2023-07-25 棋盘制作
2023-07-25 最大正方形II
2023-07-25 最大正方形
2023-07-25 OneMoreGridTask2
2023-07-25 玉蟾宫
2023-07-25 OneMoreGridTask