zoukankan      html  css  js  c++  java
  • bzoj 1001

    Description

    现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,
    而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个网格的地形:

     

    左上角点为(1,1),右下角点为(N,M)(上图中N=4,M=5).有以下三种类型的道路 
    1:(x,y)<==>(x+1,y) 
    2:(x,y)<==>(x,y+1) 
    3:(x,y)<==>(x+1,y+1) 
    道路上的权值表示这条路上最多能够通过的兔子数,道路是无向的. 左上角和右下角为兔子的两个窝,
    开始时所有的兔子都聚集在左上角(1,1)的窝里,现在它们要跑到右下解(N,M)的窝中去,狼王开始伏击
    这些兔子.当然为了保险起见,如果一条道路上最多通过的兔子数为K,狼王需要安排同样数量的K只狼,
    才能完全封锁这条道路,你需要帮助狼王安排一个伏击方案,使得在将兔子一网打尽的前提下,参与的
    狼的数量要最小。因为狼还要去找喜羊羊麻烦.

    Input

    第一行为N,M.表示网格的大小,N,M均小于等于1000.
    接下来分三部分
    第一部分共N行,每行M-1个数,表示横向道路的权值. 
    第二部分共N-1行,每行M个数,表示纵向道路的权值. 
    第三部分共N-1行,每行M-1个数,表示斜向道路的权值. 
    输入文件保证不超过10M

    Output

    输出一个整数,表示参与伏击的狼的最小数量.

    Sample Input

    3 4
    5 6 4
    4 3 1
    7 5 3
    5 6 7 8
    8 7 6 5
    5 5 5
    6 6 6

    Sample Output

    14

    HINT

     2015.4.16新加数据一组,可能会卡掉从前可以过的程序。

    Source

    最短路加对偶图。这道题本质上是求一个最小割,我们想一下,最小割,就是切断一些边,现在我们把边横起来,切断原先的边,把那些空档当成点然后再设立一个源点和汇点,就好了,源点和汇点分别连接图的两条边。

    #include<iostream>
    #include<string.h>
    #include<vector>
    #include<queue>
    #include<cstdio>
    #define mp make_pair
    using namespace std;
    const int N=2000100;
    int n,m;
    int d[N],used[N];
    typedef pair<int,int> PII; 
    vector<PII>graph[N];
    priority_queue<PII,vector<PII>,greater<PII> >q;
    void add(int u,int v,int l)
    {
    	graph[u].push_back(mp(v,l));
    	graph[v].push_back(mp(u,l));
    }
    void dijiestra()
    {	
    	memset(used,0,sizeof(used));
    	for(int i=1;i<=2*n*m+1;i++) d[i]=1<<29;
    	q.push(PII(0,0));
    	while(!q.empty())
    	{
    		PII x=q.top();q.pop();
    		int u=x.second;
    		if(used[u]) continue;
    		used[u]=1;
    		for(int i=0;i<graph[u].size();i++)
    		{
    			x=graph[u][i];
    			int v=x.first,val=x.second;
    			if(d[v]>d[u]+val){d[v]=d[u]+val;q.push(PII(d[v],v));}
    		}
    	}
    	cout<<d[2*n*m+1]<<endl;
    }
    int main()
    {
    	cin>>n>>m;
    	int tot=1<<29;
    	int u=0,v=0,l=0,k=0;
    	for(int i=1;i<m;i++)
    	{
    		scanf("%d",&l);
    		tot=min(tot,l);
    		u+=2;
    		add(u,0,l);
    	}
    	k=u;
    	for(int i=2;i<n;i++)
    	{
    		if(i==n-1) k=u;
    		for(int j=1;j<m;j++)
    		{
    			scanf("%d",&l);
    			tot=min(tot,l);
    			u+=2;
    			add(u,u-2*(m-1)-1,l);
    		}
    	}
    	k--;
    	for(int i=1;i<m;i++)
    	{
    		scanf("%d",&l);
    		tot=min(tot,l);
    		k+=2;
    		add(k,2*n*m+1,l);
    	}
    	u=1;
    	for(int i=1;i<n;i++)
    	{
    		for(int j=1;j<=m;j++)
    		{
    			scanf("%d",&l);
    			tot=min(tot,l);
    			if(j==1)
    			{
    				add(u,2*n*m+1,l);
    			}
    			else if(j==m)
    			{
    				add(u+1,0,l);
    				u+=2;
    			}
    			else 
    			{
    				u+=2;
    				add(u,u-1,l);
    			}
    		}
    	}
    	u=0;
    	for(int i=1;i<n;i++)
    		for(int j=1;j<m;j++)
    		{
    			scanf("%d",&l);
    			tot=min(tot,l);
    			u+=2;
    			add(u,u-1,l);
    		}
    	if(n==1||m==1)
    	{
    		cout<<tot<<endl;
    		return 0;
    	}
    	dijiestra();
    	return 0;
    }
    
  • 相关阅读:
    Powershell数据处理
    Powershell About Active Directory Group Membership of a domain user
    Powershell About Active Directory Server
    Oracle Schema Objects——Tables——TableStorage
    Oracle Schema Objects——Tables——TableType
    English Grammar
    Oracle Database Documentation
    Oracle Schema Objects——Tables——Oracle Data Types
    Oracle Schema Objects——Tables——Overview of Tables
    What is Grammar?
  • 原文地址:https://www.cnblogs.com/19992147orz/p/5971037.html
Copyright © 2011-2022 走看看