题意:

f个食物,d杯饮料,每个牛都有想吃的食物和想喝的饮料,但食物和饮料每个只有一份 求最多能满足多少头牛。。。。

解析:

一道简单的无源汇拆点最大流   无源汇的一个最大流,先建立超级源s和超级汇t, 把s和食物连接 权值为食物的数量1  ,饮料和t连接  权值为饮料的数量1, 因为牛只要一个就好,所以牛的结点容量为1  把牛拆成u和u’ 中间权值为1,  牛和喜欢的食物、饮料分别建边  权值为INF和1都行

这道题和hdu4292 很相似 传送门:https://www.cnblogs.com/WTSRUVF/p/9202751.html

代码如下:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <queue>
  7. #define mem(a,b) memset(a, b, sizeof(a))
  8. using namespace std;
  9. const int maxn = , INF = 0x7fffffff;
  10. int head[maxn], d[maxn], cur[maxn];
  11. int n, m, s, t, F, D;
  12. int cnt;
  13. typedef long long LL;
  14. struct node{
  15. int u, v, c, next;
  16. }Node[maxn*];
  17.  
  18. void add_(int u, int v, int c)
  19. {
  20. Node[cnt].u = u;
  21. Node[cnt].v = v;
  22. Node[cnt].c = c;
  23. Node[cnt].next = head[u];
  24. head[u] = cnt++;
  25. }
  26.  
  27. void add(int u, int v, int c)
  28. {
  29. add_(u, v, c);
  30. add_(v, u, );
  31. }
  32.  
  33. bool bfs()
  34. {
  35. queue<int> Q;
  36. mem(d, );
  37. Q.push(s);
  38. d[s] = ;
  39. while(!Q.empty())
  40. {
  41. int u = Q.front(); Q.pop();
  42. for(int i=head[u]; i!=-; i=Node[i].next)
  43. {
  44. node e = Node[i];
  45. if(!d[e.v] && e.c > )
  46. {
  47. d[e.v] = d[e.u] + ;
  48. Q.push(e.v);
  49. // cout<< e.v << " " << t <<endl;
  50. if(e.v == t) return ;
  51. }
  52. }
  53. }
  54. return d[t] != ;
  55. }
  56.  
  57. int dfs(int u, int cap)
  58. {
  59. if(u == t || cap == )
  60. return cap;
  61. int ret = ;
  62. for(int &i=cur[u]; i!=-; i=Node[i].next)
  63. {
  64. node e = Node[i];
  65. if(d[e.v] == d[e.u] + && e.c > )
  66. {
  67. int V = dfs(e.v, min(cap, e.c));
  68. Node[i].c -= V;
  69. Node[i^].c += V;
  70. cap -= V;
  71. ret += V;
  72. if(cap == ) break;
  73. }
  74. }
  75. return ret;
  76. }
  77.  
  78. int dinic()
  79. {
  80. int ans = ;
  81. while(bfs())
  82. {
  83. // cout<< 2111 <<endl;
  84. memcpy(cur, head, sizeof(head));
  85. ans += dfs(s, INF);
  86. // cout<< ans <<endl;
  87. }
  88. return ans;
  89. }
  90.  
  91. int main()
  92. {
  93. cnt = ;
  94. mem(head, -);
  95. cin>> n >> F >> D;
  96. s = , t = F + D + n + n + ;
  97. for(int i=; i<=F; i++)
  98. add(s, i, );
  99. for(int i=; i<=D; i++)
  100. add(F+i, t, );
  101. for(int i=; i<=n; i++)
  102. add(F+D+i, F+D+n+i, );
  103. for(int i=; i<=n; i++)
  104. {
  105. int r, l;
  106. cin>> r >> l;
  107. for(int j=; j<r; j++)
  108. {
  109. int u;
  110. cin>> u;
  111. add(u, F+D+i, INF);
  112. }
  113. for(int j=; j<=l; j++)
  114. {
  115. int v;
  116. cin>> v;
  117. add(F+D+n+i, F+v, INF);
  118. }
  119. }
  120.  
  121. cout<< dinic() <<endl;
  122.  
  123. return ;
  124. }

Dining POJ - 3281的更多相关文章

  1. B - Dining - poj 3281(最大流)

    题目大意:有一群牛,还有一些牛喜欢的食物和喜欢的饮料,不过这些牛都很特别,他们不会与别的牛吃同一种食物或者饮料,现在约翰拿了一些食物和饮料,同时他也知道这些牛喜欢的食物和饮料的种类,求出来最多能让多少 ...

  2. AC日记——Dining poj 3281

    [POJ-3281] 思路: 把牛拆点: s向食物连边,流量1: 饮料向t连边,流量1: 食物向牛1连边,流量1: 牛2向饮料连边,流量1: 最大流: 来,上代码: #include <cstd ...

  3. kuangbin专题专题十一 网络流 Dining POJ - 3281

    题目链接:https://vjudge.net/problem/POJ-3281 题目:有不同种类的食物和饮料,每种只有1个库存,有N头牛,每头牛喜欢某些食物和某些饮料,但是一头牛 只能吃一种食物和喝 ...

  4. B - Dining POJ - 3281 网络流

    Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will c ...

  5. poj 3281 Dining 网络流-最大流-建图的题

    题意很简单:JOHN是一个农场主养了一些奶牛,神奇的是这些个奶牛有不同的品味,只喜欢吃某些食物,喝某些饮料,傻傻的John做了很多食物和饮料,但她不知道可以最多喂饱多少牛,(喂饱当然是有吃有喝才会饱) ...

  6. POJ 3281 Dining (网络流)

    POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certai ...

  7. POJ 3281 Dining(最大流)

    POJ 3281 Dining id=3281" target="_blank" style="">题目链接 题意:n个牛.每一个牛有一些喜欢的 ...

  8. POJ 3281 网络流dinic算法

    B - Dining Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit S ...

  9. poj 3281 最大流+建图

    很巧妙的思想 转自:http://www.cnblogs.com/kuangbin/archive/2012/08/21/2649850.html 本题能够想到用最大流做,那真的是太绝了.建模的方法很 ...

随机推荐

  1. wifidog源码分析 - 客户端检测线程

    引言 当wifidog启动时,会启动一个线程(thread_client_timeout_check)维护客户端列表,具体就是wifidog必须定时检测客户端列表中的每个客户端是否在线,而wifido ...

  2. Oracle 把查询的多个字段赋值给多个变量

    select f1,f2,f3 into v1,v2,v3 from tab1

  3. Spring-bean的循环依赖以及解决方式

    链接:https://blog.csdn.net/u010853261/article/details/77940767 https://www.jianshu.com/p/6c359768b1dc

  4. CF1105E Helping Hiasat 最大团

    传送门 发现自己不会求最大团了可海星 如果将每一个朋友看做点,将两个\(1\)之间存在\(2\)操作的所有朋友之间互相连边,那么我们最后要求的就是这个图的最大独立集. 某个图的最大独立集就是反图的最大 ...

  5. React-页面路由参数传递的两种方法

    list页->detail页 方法一:路由参数 路由导航: 用“/” <Link to={'/detail/'+item.get('id')} key={index}> 路由map: ...

  6. .NET Core 3.0 跟踪

    Preview1: https://blogs.msdn.microsoft.com/dotnet/2018/12/04/announcing-net-core-3-preview-1-and-ope ...

  7. (原创)odoo关系字段在视图中的行为控制 总结

    字段类型 选项或属性 格式示例 描述 many2one , many2many_tags(widget) no_create options='{"no_create":True} ...

  8. 汇编 指令lodsb,lodsw,lodsd

    知识点: 汇编指令 lodsb,lodsw,lodsd 一.汇编指令LODSB //scasb scasw scasd //stosb stosw stosd 1. __asm lodsb //作用 ...

  9. [React]全自动数据表格组件——BodeGrid

    表格是在后台管理系统中用的最频繁的组件之一,相关的功能有数据的新增和编辑.查询.排序.分页.自定义显示以及一些操作按钮.我们逐一深入进行探讨以及介绍我的设计思路:   新增和编辑 想想我们最开始写新增 ...

  10. SqlServer 案例:已有汽车每日行驶里程数据,计算其每日增量

    需求说明 某公司某项业务,需要获得用户每日行车里程数.已知能获得该车每日提交的总里程数,如何通过 T-SQL 来获得其每日增量里程? 解决方案 首选需要对数据进行编号,利用开窗函数 OVER() 实现 ...