日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

2020 ICPC亚洲区域赛(沈阳)H-The Boomsday Project(双指针+dp)

發布時間:2023/12/3 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2020 ICPC亚洲区域赛(沈阳)H-The Boomsday Project(双指针+dp) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

H-The Boomsday Project

Code1

暴力我為人人區間轉移
O{N∑qlog?N}O\{N\sum q\log N \}O{NqlogN}

#include<bits/stdc++.h> using namespace std; using ll=long long; template <class T=int> T rd() {T res=0;T fg=1;char ch=getchar();while(!isdigit(ch)) {if(ch=='-') fg=-1;ch=getchar();}while( isdigit(ch)) res=(res<<1)+(res<<3)+(ch^48),ch=getchar();return res*fg; } ll f[300010*4],tag[300010*4]; const ll INF=0x3f3f3f3f3f3f3f3f; int n,m;ll RR; int tot;void update(int u,int l,int r,int L,int R,ll v) {if(L>R) return;if(L<=l&&r<=R) {tag[u]=min(tag[u],v);f[u]=min(f[u],v);return;}int mid=l+r>>1;if(L<=mid)update(u<<1,l,mid,L,R,v);if(R>mid)update(u<<1|1,mid+1,r,L,R,v); } ll query(int u,int l,int r,int pos,ll v) {if(l==r) return min(f[u],v);v=min(v,tag[u]);int mid=l+r>>1;if(pos<=mid) return query(u<<1,l,mid,pos,v);else return query(u<<1|1,mid+1,r,pos,v); } struct nodea {int d,k,c; }a[510]; int g[300010],h[300010]; struct nodeb {int p,q;bool operator<(const nodeb &o)const{return p<o.p;} }b[300010]; int mp[300010]; int main() {n=rd(),m=rd();RR=rd<ll>();for(int i=1;i<=n;i++) a[i].d=rd(),a[i].k=rd(),a[i].c=rd();for(int i=1;i<=m;i++) {b[i].p=rd();b[i].q=rd();mp[i]=b[i].p;}sort(mp+1,mp+1+m);sort(b+1,b+1+m);for(int i=1;i<=m;i++){b[i].p=lower_bound(mp+1,mp+1+m,b[i].p)-mp;for(int j=tot+1;j<=tot+b[i].q;j++) g[j]=b[i].p;h[b[i].p]=tot+b[i].q;tot+=b[i].q;}mp[++m]=2e9; memset(f,0x3f,sizeof f);memset(tag,0x3f,sizeof tag);update(1,0,tot,0,0,0);for(int i=0;i<tot;i++){ll v=query(1,0,tot,i,INF);update(1,0,tot,i+1,i+1,v+RR);for(int j=1;j<=n;j++) {int l=i+1,r;r=i+a[j].k;int d=lower_bound(mp+1,mp+1+m,g[i+1]+a[j].d-1)-mp;if(mp[d]>g[i+1]+a[j].d-1) --d;r=min(r,h[d]);update(1,0,tot,l,r,v+a[j].c);}}printf("%lld\n",query(1,0,tot,tot,INF));return 0; }

不需要區間覆蓋轉移,不難發現只需轉移右端點即可。由于具有單調性可以雙指針預處理。

Code2

#include<bits/stdc++.h> using namespace std; using ll=long long; template <class T=int> T rd() {T res=0;T fg=1;char ch=getchar();while(!isdigit(ch)) {if(ch=='-') fg=-1;ch=getchar();}while( isdigit(ch)) res=(res<<1)+(res<<3)+(ch^48),ch=getchar();return res*fg; }int n,m;ll R; int tot; struct nodea {int d,k,c; }a[510]; int g[300010]; ll f[300010]; struct nodeb {int p,q;bool operator<(const nodeb &o)const{return p<o.p;} }b[300010]; int to[510][300010]; int main() {n=rd(),m=rd();R=rd<ll>();for(int i=1;i<=n;i++) a[i].d=rd(),a[i].k=rd(),a[i].c=rd();for(int i=1;i<=m;i++) b[i].p=rd(),b[i].q=rd();sort(b+1,b+1+m);for(int i=1;i<=m;i++){for(int j=tot+1;j<=tot+b[i].q;j++) g[j]=b[i].p; //第j次騎車在第b[i].p天tot+=b[i].q;}for(int j=1;j<=n;j++)for(int i=0,k=1;i<tot;i++){while(k<=tot&&g[k]-g[i+1]+1<=a[j].d) k++;to[j][i]=k-1;}memset(f,0x3f,sizeof f);f[0]=0;for(int i=0;i<tot;i++){f[i+1]=min(f[i+1],f[i]+R);for(int j=1;j<=n;j++) {int r=min(i+a[j].k,to[j][i]);f[r]=min(f[r],f[i]+a[j].c);}}printf("%lld\n",f[tot]);return 0; }

總結

以上是生活随笔為你收集整理的2020 ICPC亚洲区域赛(沈阳)H-The Boomsday Project(双指针+dp)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。