250pt:

给定50个整数点,范围-500-500之间。然后在这些点上选2个点作为中心,画边长为整数的正方形,并且正方形不能重叠(可以不平行),而且而且边长不同为不同方案。求有多少种方案。。

思路:枚举两个点,计算两点的方案数。

  1. #include <cstdlib>
  2. #include <cctype>
  3. #include <cstring>
  4. #include <cstdio>
  5. #include <cmath>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <string>
  9. #include <iostream>
  10. #include <sstream>
  11. #include <map>
  12. #include <set>
  13. #include <queue>
  14. #include <stack>
  15. #include <fstream>
  16. #include <numeric>
  17. #include <iomanip>
  18. #include <bitset>
  19. #include <list>
  20. #include <stdexcept>
  21. #include <functional>
  22. #include <utility>
  23. #include <ctime>
  24. using namespace std;
  25.  
  26. #define PB push_back
  27. #define MP make_pair
  28.  
  29. #define REP(i,n) for(i=0;i<(n);++i)
  30. #define FOR(i,l,h) for(i=(l);i<=(h);++i)
  31. #define FORD(i,h,l) for(i=(h);i>=(l);--i)
  32. #define eps 1e-8
  33. typedef vector<int> VI;
  34. typedef vector<string> VS;
  35. typedef vector<double> VD;
  36. typedef long long LL;
  37. typedef pair<int,int> PII;
  38.  
  39. class TurretPlacement
  40. {
  41. public:
  42. double dist(int x1, int y1, int x2, int y2){
  43. double x = x1 - x2;
  44. double y = y1 - y2;
  45. return * sqrt(x * x + y * y);
  46. }
  47. long long count(vector <int> x, vector <int> y)
  48. {
  49. long long ans = ;
  50. int n = x.size();
  51. long long d;
  52. for (int i = ; i < n; ++i)
  53. for (int j = i + ; j < n; ++j){
  54. d = floor(dist(x[i], y[i], x[j], y[j]) + eps);
  55. ans += (d - ) * d / ;
  56. }
  57. return ans;
  58. }
  59. };

500pt:

给定最多50个炮台, 50个基地,50个供电厂的位置,并且每个炮台攻击范围为L,而对于每个基地,摧毁它或者摧毁他的供电设施会使他无法工作,求使这些基地都无法工作最少需要的能量为多少(攻击一次能量消耗为距离的平方和)

思路:对于每个基地,摧毁它显然要选择能量最少的炮台,供电厂也同样。那么其实就是一个最小割模型。

对于S,对每个基地i建一条流量为摧毁它能量大小的边

对于T,建一条供电厂j到T,流量为摧毁它能量大小的边

对于基地i与供电厂j,如果供电厂j给基地供电,建i->j,流量为Inf的边,

最后跑一边最大流即可

  1. // BEGIN CUT HERE
  2. /*
  3.  
  4. */
  5. // END CUT HERE
  6. #line 7 "GreenWarfare.cpp"
  7. #include <cstdlib>
  8. #include <cctype>
  9. #include <cstring>
  10. #include <cstdio>
  11. #include <cmath>
  12. #include <algorithm>
  13. #include <vector>
  14. #include <string>
  15. #include <iostream>
  16. #include <sstream>
  17. #include <map>
  18. #include <set>
  19. #include <queue>
  20. #include <stack>
  21. #include <fstream>
  22. #include <numeric>
  23. #include <iomanip>
  24. #include <bitset>
  25. #include <list>
  26. #include <stdexcept>
  27. #include <functional>
  28. #include <utility>
  29. #include <ctime>
  30. using namespace std;
  31.  
  32. #define PB push_back
  33. #define MP make_pair
  34. #define M0(a) memset(a, 0, sizeof(a))
  35. #define REP(i,n) for(i=0;i<(n);++i)
  36. #define FOR(i,l,h) for(i=(l);i<=(h);++i)
  37. #define FORD(i,h,l) for(i=(h);i>=(l);--i)
  38. #define maxn 1200
  39. #define Inf 0x3fffffff
  40. #define maxm 210000
  41. typedef vector<int> VI;
  42. typedef vector<string> VS;
  43. typedef vector<double> VD;
  44. typedef long long LL;
  45. typedef pair<int,int> PII;
  46. struct oo{
  47. int y, next, f;
  48. };
  49. struct MaxFlow{
  50. int n, S, T, tot;
  51. int son[maxn], dist[maxn], gap[maxn];
  52. oo e[maxm];
  53.  
  54. int sap(int x, int aug){
  55. if (x == T) return aug;
  56. int mind = n, sum = ;
  57. int y, f;
  58. for (int p = son[x]; p != -; p = e[p].next){
  59. y = e[p].y;
  60. if (dist[y] + == dist[x] && e[p].f){
  61. f = sap(y, min(e[p].f, aug - sum));
  62. e[p].f -= f;
  63. e[p^].f += f;
  64. sum += f;
  65. if (sum == aug || dist[S] >= n) return sum;
  66. }
  67. if (e[p].f) mind = min(mind, dist[y]);
  68. }
  69. if (!sum){
  70. if (!(--gap[dist[x]])) dist[S] = n;
  71. ++gap[dist[x] = mind + ];
  72. }
  73. return sum;
  74. }
  75.  
  76. void add_edge(int x, int y, int f){
  77. e[tot].y = y; e[tot].f = f;
  78. e[tot].next = son[x]; son[x] = tot++;
  79. e[tot].y = x; e[tot].f = ;
  80. e[tot].next = son[y]; son[y] = tot++;
  81. }
  82.  
  83. void init(int S, int T, int n){
  84. memset(son, -, sizeof(son));
  85. tot = ;
  86. this->S = S, this->T = T, this->n = n;
  87. }
  88. int maxflow(){
  89. M0(gap);
  90. M0(dist);
  91. gap[] = n;
  92. int ans = ;
  93. while (dist[S] < n) ans += sap(S, Inf);
  94. return ans;
  95. }
  96. } F;
  97.  
  98. class GreenWarfare
  99. {
  100. public:
  101. int n, m, k;
  102. int dist(int x1, int y1, int x2, int y2){
  103. int x = x1 - x2;
  104. int y = y1 - y2;
  105. return x * x + y * y;
  106. }
  107. int minimumEnergyCost(vector <int> cX, vector <int> cY, vector <int> bX, vector <int> bY, vector <int> pX, vector <int> pY, int SPL)
  108. {
  109. n = cX.size(), m = bY.size(), k = pX.size();
  110. F.init(, m + k + , m + k + );
  111. //printf("%d %d\n", F.T, F.n);
  112. for (int i = ; i < m; ++i)
  113. for (int j = ; j < k; ++j)
  114. if (dist(bX[i], bY[i], pX[j], pY[j]) <= SPL * SPL) F.add_edge(i + , m + j + , Inf);
  115. for (int i = ; i < m; ++i){
  116. int d = Inf;
  117. for (int j = ; j < n; ++j)
  118. d = min(d, dist(bX[i], bY[i], cX[j], cY[j]));
  119. F.add_edge(, i + , d);
  120. }
  121. for (int i = ; i < k; ++i){
  122. int d = Inf;
  123. for (int j = ; j < n; ++j)
  124. d = min(d, dist(pX[i], pY[i], cX[j], cY[j]));
  125. F.add_edge(i + + m, F.T, d);
  126. }
  127. // for (int i = 0; i < F.tot; ++i)
  128. // printf("%d %d %d\n",F.e[i].y, F.e[i].f, F.e[i].next);
  129. return F.maxflow();
  130. }
  131.  
  132. };

SRM465的更多相关文章

随机推荐

  1. 多进程copy文件

    from multiprocessing import Pool,Manager import os,time def copyFileTask(fileName,oldFolderName,newF ...

  2. MacDev.GarbageCollectionIsDeprecated-WhenXcodeCompileMacAppProject

    Garbage Collection is not supported 当Xcode编译Mac OSX App时报错:"Garbage Collection is not supported ...

  3. spring+mybatis+mina+logback框架搭建

    第一次接触spring,之前从来没有学过spring,所以算是赶鸭子上架,花了差不多一个星期来搭建,中间遇到各种各样的问题,一度觉得这个框架搭建非常麻烦,没有一点技术含量,纯粹就是配置,很低级!但随着 ...

  4. ZOJ2412 Farm Irrigation(农田灌溉) 搜索

    Farm Irrigation Time Limit: 2 Seconds      Memory Limit: 65536 KB Benny has a spacious farm land to ...

  5. CentOS7安装ms8可能出现的错误

    参照<在Centos上安装MS8.0的详细过程>:http://muchong.com/html/201507/9145663.html 安装过程中如果库文件不全,会异常终止.报错情况如下 ...

  6. Django框架之验证码生成示例

    一.生成随机颜色的图片 1)前端代码展示 <!DOCTYPE html> <html lang="en"> <head> <meta ch ...

  7. HierSort(希尔)————Java

    利用Java进行希尔排序(元素中有0会有问题),步长经过调试length/2+1最合适. import java.util.Scanner; public class HierSort { priva ...

  8. Rest架构风格的实践(使用通用Mapper技术)

    1.根据用户 id 查询用户数据 1.1 controll控制器 @RequestMapping("restful/user") @Controller public class ...

  9. java.lang.NoClassDefFoundError: org/apache/solr/common/params/SolrParams

    启动tomcat服务,报错误java.lang.NoClassDefFoundError: org/apache/solr/common/params/SolrParams [2016-03-10 2 ...

  10. Graphviz 环境变量设置

    今天晚上解决了一个错误,如下: