zoukankan      html  css  js  c++  java
  • bzoj1003: [ZJOI2006]物流运输

    dp+最短路。暴力枚举就可以了。O(n3logn)。样例中m=n然后测样例过了。然后 54行习惯性的dis[n]然后就WA了!!!。 

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    using namespace std;
    #define rep(i,s,t) for(int i=s;i<=t;i++)
    #define dwn(i,s,t) for(int i=s;i>=t;i--)
    #define clr(x,c) memset(x,c,sizeof(x))
    #define qwq(x) for(edge *o=head[x];o;o=o->next)
    int read(){
    	int x=0,f=1;char c=getchar();
    	while(!isdigit(c)) {
    		if(c=='-') f=-1;c=getchar();
    	}
    	while(isdigit(c)) x=x*10+c-'0',c=getchar();
    	return x;
    } 
    const int nmax=105;
    const int maxn=10005;
    const int inf=0x7f7f7f7f;
    struct edge{
    	int to,dist;edge *next;
    };
    edge es[maxn],*pt=es,*head[nmax];
    int dis[nmax],dp[nmax],n,m,K,e,P;bool vis[nmax][nmax],on[nmax];
    void add(int u,int v,int d){
    	pt->to=v;pt->dist=d;pt->next=head[u];head[u]=pt++;
    	pt->to=u;pt->dist=d;pt->next=head[v];head[v]=pt++;
    }
    struct node{
    	int x,dist;
    	node(int x,int dist):x(x),dist(dist){};
    	node(){};
    	bool operator<(const node&rhs)const{
    	  return dist>rhs.dist;}
    };
    priority_queue<node>q;
    int get(int s,int t){
    	clr(on,1);
    	rep(i,1,m) rep(j,s,t) if(!vis[i][j]) on[i]=0;
    	clr(dis,0x7f);dis[1]=0;q.push(node(1,0));
    	node oo;int tx,td;
    	while(!q.empty()){
    		oo=q.top();q.pop();
    		tx=oo.x;td=oo.dist;
    		if(dis[tx]!=td) continue;
    		qwq(tx) if(on[o->to]&&dis[o->to]>td+o->dist){
    			dis[o->to]=td+o->dist;
    			q.push(node(o->to,dis[o->to]));
    		}
    	}
    	if(dis[m]==inf) return inf;
    	else return dis[m]*(t-s+1);
    }
    void mins(int &a,int b){
    	if(a>b) a=b;
    }
    int main(){
    	n=read(),m=read(),K=read(),e=read();int u,v,d;
    	rep(i,1,e) u=read(),v=read(),d=read(),add(u,v,d);
    	P=read();clr(vis,1);
    	rep(i,1,P) {
    		u=read(),v=read(),d=read();
    		rep(j,v,d) vis[u][j]=0;
    	}
    	rep(i,1,n) {
    		dp[i]=get(1,i);
    		rep(j,2,i) mins(dp[i],dp[j-1]+get(j,i)+K);
    	}
    	printf("%d
    ",dp[n]);
    	return 0;
    }
    

    1003: [ZJOI2006]物流运输

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 6255  Solved: 2578
    [Submit][Status][Discuss]

    Description

      物流公司要把一批货物从码头A运到码头B。由于货物量比较大,需要n天才能运完。货物运输过程中一般要转
    停好几个码头。物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格的管理和跟踪。由于各种
    因素的存在,有的时候某个码头会无法装卸货物。这时候就必须修改运输路线,让货物能够按时到达目的地。但是
    修改路线是一件十分麻烦的事情,会带来额外的成本。因此物流公司希望能够订一个n天的运输计划,使得总成本
    尽可能地小。

    Input

      第一行是四个整数n(1<=n<=100)、m(1<=m<=20)、K和e。n表示货物运输所需天数,m表示码头总数,K表示
    每次修改运输路线所需成本。接下来e行每行是一条航线描述,包括了三个整数,依次表示航线连接的两个码头编
    号以及航线长度(>0)。其中码头A编号为1,码头B编号为m。单位长度的运输费用为1。航线是双向的。再接下来
    一行是一个整数d,后面的d行每行是三个整数P( 1 < P < m)、a、b(1< = a < = b < = n)。表示编号为P的码
    头从第a天到第b天无法装卸货物(含头尾)。同一个码头有可能在多个时间段内不可用。但任何时间都存在至少一
    条从码头A到码头B的运输路线。

    Output

      包括了一个整数表示最小的总成本。总成本=n天运输路线长度之和+K*改变运输路线的次数。

    Sample Input

    5 5 10 8
    1 2 1
    1 3 3
    1 4 2
    2 3 2
    2 4 4
    3 4 1
    3 5 2
    4 5 2
    4
    2 2 3
    3 1 1
    3 3 3
    4 4 5

    Sample Output

    32
    //前三天走1-4-5,后两天走1-3-5,这样总成本为(2+2)*3+(3+2)*2+10=32

    HINT

     

    Source

     
    [Submit][Status][Discuss]
  • 相关阅读:
    Python笔记_第一篇_面向过程_第一部分_7.文件的操作(.txt)
    Python笔记_第一篇_面向过程_第一部分_6.语句的嵌套
    Python笔记_第一篇_面向过程_第一部分_6.其他控制语句(with...as等)
    Python笔记_第一篇_面向过程第一部分_6.循环控制语句(while 和 for)_
    Python笔记_第一篇_面向过程_第一部分_6.条件控制语句(if)
    matplot 代码实例
    python下的MySQLdb使用
    vim操作笔记
    使用k-近邻算法改进约会网站的配对效果
    python 读取文本
  • 原文地址:https://www.cnblogs.com/fighting-to-the-end/p/5801193.html
Copyright © 2011-2022 走看看