题目链接:

Sewage Treatment

时间限制:2000ms
单点时限:2000ms
内存限制:256MB

描述

After years of suffering, people could not tolerate the pollution in the city any more, and started a long-lasting protest. Eventually, the municipal government made up its mind to deal with the sewage discharged by factories. The government planned to deploy some Pollution-Killer Utilities (PKUs) in order to clean all the sewage, and meanwhile, minimize the total cost.

The city can be approximately considered as a plane. There are n factories discharging sewage. The i-th one is located at (xi, yi), and discharges si units of sewage every day. The government has built m PKUs. The PKUs' locations are also fixed, and the j-th one is located at (xj, yj). Two features of PKUs are essential, and you will need to find the best choice of them: u is the upper limit of units of sewage that can be cleaned by one PKU every day, and c is the coverage radius of one PKU (which means, only if the distance between the PKU and the factory does not exceed the coverage radius, sewage discharged by this factory can be cleaned by this PKU). Note that all the PKUs share the same u and c. Because of some technical reasons, u has to be a positive integer.

Here is your task. The cost of deploying these PKUs can be weighed by an empirical formula:

f = u×sqrt(c)

You need to calculate the minimum value of f, and guarantee all the sewage is treated.

输入

There are no more than 15 test cases. Each test case starts with a line containing two positive integers n and m (1 <= n, m <= 100), representing the number of factories and PKUs. Then n lines follow, the i-th line contains three integers xi, yi, si (-10000 <= xi, yi <= 10000, 1 <= si <= 100), representing the i-th factory's location and the quantity of sewage discharged by it every day. In the next following m lines, the j-th line contains two integers xj, yj (-10000 <= xj, yj <= 10000), representing the j-th PKU's location. After each test case there is an empty line. After all the test cases there is a line "0 0", which indicates the end of the input, and should not be processed.

输出

For each test case, output a single line containing a number, which is the minimum value of f. This number should be rounded to an integer.

提示

Test case 1:

When u = 12 and c = 2, f has the minimum value of 12 * sqrt(2) = 16.97 = 17.

Test case 2:

When u = 10, c = sqrt(2), f has the minimum value of 10 * sqrt(sqrt(2)) = 11.89 = 12.

The input guarantees that there is always a valid solution. You may assume that the factories and PKUs are uniformly randomly distributed on the plane.

样例输入
  1. 3 1
  2. -1 0 5
  3. 2 0 3
  4. 0 1 4
  5. 0 0
  6.  
  7. 4 2
  8. 0 0 4
  9. 3 0 5
  10. 3 2 3
  11. 0 2 6
  12. 1 1
  13. 2 1
  14.  
  15. 0 0
样例输出
  1. 17
  2. 12
  3.  
  4. 题意:
  5.  
  6. 给出n个工厂,每个工厂的坐标和每天产生的污水量,再给mpku,现在要求f=u*sqrt(r)的最小值,要求所有的污水都处理完;
    只有工厂的与pku的距离<=r时这个工厂的污水才能给pku处理,而且给的量是任意的,而且所有的ur是一样的;
  7.  
  8. 思路:
  9.  
  10. 枚举所有的距离,然后二分u,建图的时候源点s到所有的工厂连边,容量为每天产生的污水量,所有的pku到汇点连边,容量为u,然后相距<=rpku与工厂连边,容量无穷;
    跑最大流看是否==sum;
    AC代码:
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <bits/stdc++.h>
  7. #include <stack>
  8. #include <map>
  9.  
  10. using namespace std;
  11.  
  12. #define For(i,j,n) for(int i=j;i<=n;i++)
  13. #define mst(ss,b) memset(ss,b,sizeof(ss));
  14.  
  15. typedef long long LL;
  16.  
  17. template<class T> void read(T&num) {
  18. char CH; bool F=false;
  19. for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
  20. for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
  21. F && (num=-num);
  22. }
  23. int stk[70], tp;
  24. template<class T> inline void print(T p) {
  25. if(!p) { puts("0"); return; }
  26. while(p) stk[++ tp] = p%10, p/=10;
  27. while(tp) putchar(stk[tp--] + '0');
  28. putchar('\n');
  29. }
  30.  
  31. const LL mod=1e9+7;
  32. const double PI=acos(-1.0);
  33. const int inf=1e9;
  34. const int N=(1<<20)+10;
  35. const int maxn=205;
  36. const double eps=1e-12;
  37.  
  38. struct Edge
  39. {
  40. int from,to,cap,flow;
  41. };
  42. vector<Edge>edge;
  43. vector<int>G[maxn];
  44. bool vis[maxn];
  45. int cur[maxn],n,m,fn,s,t,d[maxn];
  46. int dis[210][210];
  47. int x[maxn],y[maxn],fs[maxn],sum,lower,upper,cnt;
  48. double ans;
  49. struct po
  50. {
  51. int from,to,dis;
  52. }a[105*105];
  53. int cmp(po u,po v)
  54. {
  55. return u.dis<v.dis;
  56. }
  57. inline void add_edge(int from,int to,int cap)
  58. {
  59. edge.push_back((Edge){from,to,cap,0});
  60. edge.push_back((Edge){to,from,0,0});
  61. m=edge.size();
  62. G[from].push_back(m-2);
  63. G[to].push_back(m-1);
  64. }
  65. bool bfs()
  66. {
  67. mst(vis,0);
  68. queue<int>Q;
  69. Q.push(s);
  70. d[s]=0;
  71. vis[s]=1;
  72. while(!Q.empty())
  73. {
  74. int x=Q.front();Q.pop();
  75. int len=G[x].size();
  76. for(int i=0;i<len;i++)
  77. {
  78. Edge& e=edge[G[x][i]];
  79. if(!vis[e.to]&&e.cap>e.flow)
  80. {
  81. vis[e.to]=1;
  82. d[e.to]=d[x]+1;
  83. Q.push(e.to);
  84. }
  85. }
  86. }
  87. return vis[t];
  88. }
  89.  
  90. int dfs(int x,int a)
  91. {
  92. if(x==t||a==0)return a;
  93. int flow=0,f,len=G[x].size();
  94. for(int& i=cur[x];i<len;i++)
  95. {
  96. Edge& e=edge[G[x][i]];
  97. if(d[x]+1==d[e.to]&&(f=dfs(e.to,min(a,e.cap-e.flow)))>0)
  98. {
  99. e.flow+=f;
  100. edge[G[x][i]^1].flow-=f;
  101. flow+=f;
  102. a-=f;
  103. if(a==0)break;
  104. }
  105. }
  106. return flow;
  107. }
  108.  
  109. int maxflow()
  110. {
  111. int flow=0;
  112. while(bfs())
  113. {
  114. mst(cur,0);
  115. flow+=dfs(s,inf);
  116. }
  117. return flow;
  118. }
  119. inline void Init(int k,int hi)
  120. {
  121. edge.clear();
  122. for(int i=0;i<=t;i++)G[i].clear();
  123. for(int i=1;i<=k;i++)
  124. {
  125. add_edge(a[i].from,a[i].to,inf);
  126. }
  127. for(int i=k+1;i<=cnt;i++)
  128. {
  129. if(a[i].dis>a[k].dis)break;
  130. add_edge(a[i].from,a[i].to,inf);
  131. }
  132. for(int i=1;i<=n;i++)add_edge(s,i,fs[i]);
  133. for(int i=n+1;i<=n+fn;i++)add_edge(i,t,hi);
  134. }
  135. inline int check(int k,int flow)
  136. {
  137. Init(k,flow);
  138. int ans=maxflow();
  139. if(ans==sum)return 1;
  140. return 0;
  141. }
  142. double solve(int k)
  143. {
  144. double dist=sqrt(sqrt(a[k].dis*1.0));
  145. int l=lower,r=min(upper,(int)(ceil(ans/dist)));
  146. while(l<r)
  147. {
  148. int mid=(l+r)>>1;
  149. if(check(k,mid))r=mid;
  150. else l=mid+1;
  151. }
  152. upper=r;
  153. return dist*r;
  154. }
  155. int main()
  156. {
  157. while(1)
  158. {
  159. read(n);read(fn);
  160. if(!n&&!fn)break;
  161. sum=0;
  162. for(int i=1;i<=n;i++)
  163. {
  164. read(x[i]);read(y[i]);read(fs[i]);
  165. sum=sum+fs[i];
  166. }
  167. for(int i=n+1;i<=n+fn;i++)
  168. {
  169. read(x[i]);read(y[i]);
  170. }
  171. cnt=0;
  172. for(int i=1;i<=n;i++)
  173. {
  174. for(int j=n+1;j<=n+fn;j++)
  175. {
  176. int dist=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
  177. a[++cnt].from=i;
  178. a[cnt].to=j;
  179. a[cnt].dis=dist;
  180. }
  181. }
  182. sort(a+1,a+cnt+1,cmp);
  183. a[0].dis=-1;
  184. s=0,t=n+fn+1;
  185. ans=inf;
  186. lower=(sum+fn-1)/fn,upper=1e4;
  187. for(int i=1;i<=cnt;i++)
  188. {
  189. if(a[i].dis==a[i-1].dis)continue;
  190. double temp=solve(i);
  191. ans=min(temp,ans);
  192. }
  193. printf("%.0lf\n",ans);
  194. }
  195. return 0;
  196. }

  

  1.  

hihocoder-1389&&2016北京网赛07 Sewage Treatment(二分+网络流)的更多相关文章

  1. hihoCoder1388 Periodic Signal(2016北京网赛F:NTT)

    题目 Source http://hihocoder.com/problemset/problem/1388 Description Profess X is an expert in signal ...

  2. hihoCoder 1391 Countries【预处理+排序+优先队列】2016北京网络赛

    题目:http://hihocoder.com/problemset/problem/1391 题目大意: A和B两个国家互射导弹,每个国家都有一个防御系统,在防御系统开启的时间内可以将到达本国的导弹 ...

  3. ACM学习历程—Hihocoder 1233 Boxes(bfs)(2015北京网赛)

    hihoCoder挑战赛12 时间限制:1000ms 单点时限:1000ms 内存限制:256MB   描述 There is a strange storehouse in PKU. In this ...

  4. 2016北京网络赛 hihocoder 1391 Countries 树状数组

    Countries   描述 There are two antagonistic countries, country A and country B. They are in a war, and ...

  5. 北京网赛I题 hiho1391 (树状数组、区间覆盖最大值问题)

    题目链接:http://hihocoder.com/problemset/problem/1391 题意:A国和B国向对方分别投射N枚和M枚导弹(发射时间,飞行时间,伤害值),同时两国各自都有防御系统 ...

  6. 2015年北京网赛 boxes(bfs)

    题目链接: http://hihocoder.com/problemset/problem/1233 题目描述: 给定最多七个箱子,每个箱子的重量都不相同,每次都可以将一个箱子放在相邻的位置上,如果相 ...

  7. hihocoder-1391&&北京网赛09 Countries(优先队列)

    题目链接: Countries 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are two antagonistic countries, country ...

  8. hihocoder 1236(2015北京网络赛 J题) 分块bitset乱搞题

    题目大意: 每个人有五门课成绩,初始给定一部分学生的成绩,然后每次询问给出一个学生的成绩,希望知道在给定的一堆学生的成绩比这个学生每门都低或者相等的人数 因为强行要求在线查询,所以题目要求,每次当前给 ...

  9. hiho 1227 找到一个恰好包含n个点的圆 (2015北京网赛 A题)

    平面上有m个点,要从这m个点当中找出n个点,使得包含这n个点的圆的半径(圆心为n个点当中的某一点且半径为整数)最小,同时保证圆周上没有点. n > m 时要输出-1 样例输入43 2 0 0 1 ...

随机推荐

  1. 转载Quandl R Package

    Quandl R Package 通过Quandl API可以快速准确地获取宏观经济数据.(https://www.quandl.com/docs/api) 分享两个国外的优秀网站 R和Python在 ...

  2. mac下eclipse的svn(即svn插件)怎么切换账号?

    以mac os x为例(Unix/Linux类似) 打开命令行窗口,即用户的根目录(用户的home目录) cd ~ 即可进入home目录. 执行命令 ls -al 会列出home目录下的所有文件及文件 ...

  3. [Architecture Pattern] Singleton Locator

    [Architecture Pattern] Singleton Locator 目的 组件自己提供Service Locator模式,用来降低组件的耦合度. 情景 在开发系统时,底层的Infrast ...

  4. JAVA书写规范

    java程序书写规范 命名规范    1.一般概念        1.尽量使用完整的英文描述符        2.采用适用于相关领域的术语        3.采用大小写混合使名字可读        4 ...

  5. Math对象常用方法汇总

    前几天翻阅<JavaScript权威指南>,看到了Math对象,于是汇总了一下. Math对象不同于其他的对象,它可以说是一个公共数学类,里面有很多数学方法,用于各种数学运算,但是Math ...

  6. android 数据文件存取至储存卡

    来自:http://blog.csdn.net/jianghuiquan/article/details/8569233 <?xml version="1.0" encodi ...

  7. C++ RTTI

    一.定义:RTTI:Run Time Type Identification ,运行时类型识别:指程序能够使用基类的指针或引用来检索其所指对象的实际派生类型.二.使用方式:C++中有两个操作符提供RT ...

  8. cell自适应高度

    MyModel.h #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface MyModel : ...

  9. 通知中心NSNotificationCenter的使用

    通知中心NSNotificationCenter的使用 Cocoa框架中,通知中心以及KVO都属于设计模式中的观察者. Source 在使用通知中心之前,对通知中心类进行了简单的封装,以便可读性更强. ...

  10. APP原型设计工具,哪家强?转自知乎

    著作权归作者所有. 商业转载请联系作者获得授权,非商业转载请注明出处. 作者:李志超 链接:http://www.zhihu.com/question/20403141/answer/25329730 ...