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=;
  5. const int maxv=;
  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=;
  16. memset(head,-,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,,sizeof(vis));
  32. int q[maxm],cnt=;
  33. q[++cnt]=s;
  34. vis[s]=;
  35. d[s]=;
  36. for(int i=;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]>){
  40. d[point[j]]=d[u]+;
  41. q[++cnt]=point[j];
  42. vis[point[j]]=;
  43. }
  44. }
  45. }
  46. return vis[t];
  47. }
  48.  
  49. int dfs(int x,int a){
  50. if(x==t||a==)return a;
  51. int ans=,f;
  52. for(int i=head[x];~i;i=nxt[i]){
  53. if(d[point[i]]==d[x]+&&flow[i]>){
  54. f=dfs(point[i],a<flow[i]?a:flow[i]);
  55. flow[i]-=f;
  56. flow[i^]+=f;
  57. ans+=f;
  58. a-=f;
  59. if(a==)break;
  60. }
  61. }
  62. if(ans==)d[x]=-;
  63. return ans;
  64. }
  65.  
  66. int mf(){
  67. int ans=;
  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=;q<=T;q++){
  78.  
  79. init();
  80. scanf("%d%d",&n,&m);
  81. int i,j,minx,maxx;
  82. for(i=;i<=n;i++){
  83. int x,y;
  84. scanf("%d%d",&x,&y);
  85. if(i==){
  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=;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\n",mf());
  107. }
  108. return ;
  109. }

hdu4280 Island Transport 最大流的更多相关文章

  1. HDU4280 Island Transport —— 最大流 ISAP算法

    题目链接:https://vjudge.net/problem/HDU-4280 Island Transport Time Limit: 20000/10000 MS (Java/Others)   ...

  2. Hdu4280 Island Transport 2017-02-15 17:10 44人阅读 评论(0) 收藏

    Island Transport Problem Description In the vast waters far far away, there are many islands. People ...

  3. HDU4280 Island Transport

    ISAP求最大流模板 #include<cstdio> #include<cstring> #include<algorithm> #include<iost ...

  4. HDU4280:Island Transport(最大流)

    Island Transport Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  5. HDU 4280 Island Transport(网络流,最大流)

    HDU 4280 Island Transport(网络流,最大流) Description In the vast waters far far away, there are many islan ...

  6. Hdu 4280 Island Transport(最大流)

    Island Transport Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  7. HDU 4280 Island Transport(dinic+当前弧优化)

    Island Transport Description In the vast waters far far away, there are many islands. People are liv ...

  8. Island Transport

    Island Transport http://acm.hdu.edu.cn/showproblem.php?pid=4280 Time Limit: 20000/10000 MS (Java/Oth ...

  9. HDU 4280 Island Transport

    Island Transport Time Limit: 10000ms Memory Limit: 65536KB This problem will be judged on HDU. Origi ...

随机推荐

  1. lubuntu16.04 安装过程以及ssd测试模型的环境配置

    1.系统启动盘(ultraISO)制作启动盘, 1/5 文件->打开,打开我们的iso镜像 2/5 选择我们的u盘, 3/5 点击启动->写入硬盘映像 4/5 写入方式选择raw,格式化然 ...

  2. 每天CSS学习之line-height

    line-height是CSS的一个属性,其作用是设置行高.其有以下几种值: 1.normal:自动设置合理的行间距.该值是默认值.如下示例: p{ line-height:normal; } 结果: ...

  3. 直接插入排序(Straight Insertion Sort)

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  4. tf多线程读取数据

    多线程读取数据的机制 tf中多线程读取数据跟常规的python多线程思路一致,是基于Queue的多线程编程. 主线程读取数据,然后计算,在读数据这部分有两个线程,一个线程读取文件名,生成文件名队列,另 ...

  5. Java语法基础学习DayTwo

    一.数据类型补充问题 数据类型的自动转换等级: byte,short,char -- int -- long -- float -- double long是8个字节,float是4个字节,为什么是这 ...

  6. L299 EST 科技英语翻译-美学取向 (下)

    4. Ordering(有序美) DescriptiveExpositoryArgumentative Chinese: end focus 句尾焦点English: beginning focus ...

  7. 用python从符合一定格式的txt文档中逐行读取数据并按一定规则写入excel(openpyxl支持Excel 2007 .xlsx格式)

    前几天接到一个任务,从gerrit上通过ssh命令获取一些commit相关的数据到文本文档中,随后将这些数据存入Excel中.数据格式如下图所示 观察上图可知,存在文本文档中的数据符合一定的格式,通过 ...

  8. ios轮播图片用法

    // // ZQRViewController.m // 04-图片轮播器 // // Created by apple on 17-08-24. // Copyright (c) 2017年 zzq ...

  9. 团队-爬取豆瓣电影TOP250-需求分析

    需求: 1.搜集相关电影网址 2.实现相关逻辑的代码 项目步骤: 1.通过豆瓣网搜索关键字,获取相关地址 2.根据第三方包实现相关逻辑  

  10. python day08作业答案

    1. a f=open('11.txt','r',encoding='utf-8') a=f.read() print(a) f.flush() f.close() b. f=open('11.txt ...