zoukankan      html  css  js  c++  java
  • 【LOJ#3156】【NOI2019】—回家路线

    传送门

    明明可以bfsbfs写了个dijdij把自己强行玩wawa

    有2种做法

    第一种:

    考虑对于同一个点的入边i,ji,j转移给出边xx

    把式子列出来后发现是一个标准的斜率优化
    在凸包上二分就可以了

    复杂度O(mlogm)O(mlogm)

    第二种:

    发现时间很小
    f[i][j]f[i][j]表示在点ii时间jj时最小值
    mapmap存一下暴力转移也可以过

    复杂度O(mklogk)kO(mklogk),k是最大的时间
    常数很小也可以卡过

    UPDATE

    好像是原题简化版
    算了CCFCCF都让人家出题人做绿皮火车了也不奢求什么了


    #include<bits/stdc++.h>
    using namespace std;
    const int RLEN=1<<21|1;
    inline char gc(){
        static char ibuf[RLEN],*ib,*ob;
        (ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
        return (ib==ob)?EOF:*ib++;
    } 
    #define gc getchar
    inline int read(){
        char ch=gc();
        int res=0,f=1;
        while(!isdigit(ch))f^=ch=='-',ch=gc();
        while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
        return f?res:-res;
    }
    #define re register 
    #define ll long long
    #define pb push_back
    #define pii pair<int,int>
    #define fi first
    #define se second
    #define pob pop_back
    #define pf push_front
    #define pof pop_front
    const int N=100005,M=200005;
    int n,m;
    ll A,B,C;
    const ll inf=1e15;
    map<int,ll> f[N];
    #define IT map<int,ll>::iterator
    struct node{
    	int x,y,p,q;
    	friend inline bool operator <(const node &a,const node &b){
    		return a.p<b.p;
    	}
    }p[M];
    inline ll calc(ll x){
    	return A*x*x+B*x+C;
    }
    int main(){
    	n=read(),m=read(),A=read(),B=read(),C=read();
    	for(int i=1;i<=m;i++){
    		p[i].x=read(),p[i].y=read(),p[i].p=read(),p[i].q=read();
    		f[p[i].y][p[i].q]=inf;
    	}
    	sort(p+1,p+m+1);
    	f[1][0]=0;
    	for(int i=1;i<=m;i++){
    		for(IT it=f[p[i].x].begin();it!=f[p[i].x].end();it++){
    			if((*it).fi>p[i].p)break;
    			if((*it).se==inf)continue;
    			int x=p[i].p-(*it).fi;
    			ll res=calc(x);
    			if(f[p[i].y][p[i].q]>(*it).se+res)f[p[i].y][p[i].q]=(*it).se+res;
    		}
    	}
    	ll res=inf;
    	for(IT it=f[n].begin();it!=f[n].end();it++)res=min(res,(*it).fi+(*it).se);
    	cout<<res;
    }
    
  • 相关阅读:
    <ul>下<li>的list-style属性
    js字符数组转化为数字数组
    ES6学习之— 字符串扩展(二)
    ES6学习之— 字符串扩展
    ES6学习之—— 变量的解构赋值
    ES6学习之——let和const命令
    微信小程序中cover-view踩坑总结
    uni-app 元素在交叉轴(竖直方向)的对齐方式
    uni-app元素对齐方式
    uni-app 页面导入css样式
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/12328794.html
Copyright © 2011-2022 走看看