zoukankan      html  css  js  c++  java
  • hdu4280 Island Transport 最大流

    In the vast waters far far away, there are many islands. People are living on the islands, and all the transport among the islands relies on the ships.
      You have a transportation company there. Some routes are opened for passengers. Each route is a straight line connecting two different islands, and it is bidirectional. Within an hour, a route can transport a certain number of passengers in one direction. For safety, no two routes are cross or overlap and no routes will pass an island except the departing island and the arriving island. Each island can be treated as a point on the XY plane coordinate system. X coordinate increase from west to east, and Y coordinate increase from south to north.
      The transport capacity is important to you. Suppose many passengers depart from the westernmost island and would like to arrive at the easternmost island, the maximum number of passengers arrive at the latter within every hour is the transport capacity. Please calculate it.

    题意:给出若干个点和点之间边的流量,问最西边的点到最东边的点的运量是多少

    题意描述就是一个裸的网络流最大流问题,直接跑dinic就可以了

      1 #pragma comment(linker,"/STACK:16777216")
      2 #include<stdio.h>
      3 #include<string.h>
      4 const int maxm=100100;
      5 const int maxv=200100;
      6 const int INF=0x3f3f3f3f;
      7 
      8 int s,t;
      9 int n,m;
     10 int d[maxm],cur[maxm];
     11 bool vis[maxm];
     12 int head[maxm],point[maxv],flow[maxv],nxt[maxv],size;
     13 
     14 void init(){
     15     size=0;
     16     memset(head,-1,sizeof(head));
     17 }
     18 
     19 void add(int a,int b,int c){
     20     point[size]=b;
     21     flow[size]=c;
     22     nxt[size]=head[a];
     23     head[a]=size++;
     24     point[size]=a;
     25     flow[size]=c;
     26     nxt[size]=head[b];
     27     head[b]=size++;
     28 }
     29 
     30 bool bfs(){
     31     memset(vis,0,sizeof(vis));
     32     int q[maxm],cnt=0;
     33     q[++cnt]=s;
     34     vis[s]=1;
     35     d[s]=0;
     36     for(int i=1;i<=cnt;i++){
     37         int u=q[i];
     38         for(int j=head[u];~j;j=nxt[j]){
     39             if(!vis[point[j]]&&flow[j]>0){
     40                 d[point[j]]=d[u]+1;
     41                 q[++cnt]=point[j];
     42                 vis[point[j]]=1;
     43             }
     44         }
     45     }
     46     return vis[t];
     47 }
     48 
     49 int dfs(int x,int a){
     50     if(x==t||a==0)return a;
     51     int ans=0,f;
     52     for(int i=head[x];~i;i=nxt[i]){
     53         if(d[point[i]]==d[x]+1&&flow[i]>0){
     54             f=dfs(point[i],a<flow[i]?a:flow[i]);
     55             flow[i]-=f;
     56             flow[i^1]+=f;
     57             ans+=f;
     58             a-=f;
     59             if(a==0)break;
     60         }
     61     }
     62     if(ans==0)d[x]=-1;
     63     return ans;
     64 }
     65 
     66 int mf(){
     67     int ans=0;
     68     while(bfs()){
     69         ans+=dfs(s,INF);
     70     }
     71     return ans;
     72 }
     73 
     74 int main(){
     75     int T;
     76     scanf("%d",&T);
     77     for(int q=1;q<=T;q++){
     78 
     79         init();
     80         scanf("%d%d",&n,&m);
     81         int i,j,minx,maxx;
     82         for(i=1;i<=n;i++){
     83             int x,y;
     84             scanf("%d%d",&x,&y);
     85             if(i==1){
     86                 minx=x;
     87                 maxx=x;
     88                 s=t=i;
     89             }
     90             else{
     91                 if(x>maxx){
     92                     maxx=x;
     93                     s=i;
     94                 }
     95                 else if(x<minx){
     96                     minx=x;
     97                     t=i;
     98                 }
     99             }
    100         }
    101         for(i=1;i<=m;i++){
    102             int a,b,v;
    103             scanf("%d%d%d",&a,&b,&v);
    104             add(a,b,v);
    105         }
    106         printf("%d
    ",mf());
    107     }
    108     return 0;
    109 }
    View Code
  • 相关阅读:
    FrameLayout和handle实现霓虹灯效果
    Table中collapseColumns,stretchColumns
    自定义View,随着手指运动的小球
    用代码创建视图
    Android scrollbar的设置
    Android安装和设置的方法
    将win7电脑无线网变身WiFi热点,让手机、笔记本共享上网
    同一个ImageView根据xml文件来显示不同的图片--level-list
    android获取屏幕长宽的方法
    Android实现图片裁剪
  • 原文地址:https://www.cnblogs.com/cenariusxz/p/6597997.html
Copyright © 2011-2022 走看看