250pt:

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

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

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i)
#define eps 1e-8
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII; class TurretPlacement
{
public:
double dist(int x1, int y1, int x2, int y2){
double x = x1 - x2;
double y = y1 - y2;
return * sqrt(x * x + y * y);
}
long long count(vector <int> x, vector <int> y)
{
long long ans = ;
int n = x.size();
long long d;
for (int i = ; i < n; ++i)
for (int j = i + ; j < n; ++j){
d = floor(dist(x[i], y[i], x[j], y[j]) + eps);
ans += (d - ) * d / ;
}
return ans;
}
};

500pt:

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

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

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

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

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

最后跑一边最大流即可

 // BEGIN CUT HERE
/* */
// END CUT HERE
#line 7 "GreenWarfare.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair
#define M0(a) memset(a, 0, sizeof(a))
#define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i)
#define maxn 1200
#define Inf 0x3fffffff
#define maxm 210000
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
struct oo{
int y, next, f;
};
struct MaxFlow{
int n, S, T, tot;
int son[maxn], dist[maxn], gap[maxn];
oo e[maxm]; int sap(int x, int aug){
if (x == T) return aug;
int mind = n, sum = ;
int y, f;
for (int p = son[x]; p != -; p = e[p].next){
y = e[p].y;
if (dist[y] + == dist[x] && e[p].f){
f = sap(y, min(e[p].f, aug - sum));
e[p].f -= f;
e[p^].f += f;
sum += f;
if (sum == aug || dist[S] >= n) return sum;
}
if (e[p].f) mind = min(mind, dist[y]);
}
if (!sum){
if (!(--gap[dist[x]])) dist[S] = n;
++gap[dist[x] = mind + ];
}
return sum;
} void add_edge(int x, int y, int f){
e[tot].y = y; e[tot].f = f;
e[tot].next = son[x]; son[x] = tot++;
e[tot].y = x; e[tot].f = ;
e[tot].next = son[y]; son[y] = tot++;
} void init(int S, int T, int n){
memset(son, -, sizeof(son));
tot = ;
this->S = S, this->T = T, this->n = n;
}
int maxflow(){
M0(gap);
M0(dist);
gap[] = n;
int ans = ;
while (dist[S] < n) ans += sap(S, Inf);
return ans;
}
} F; class GreenWarfare
{
public:
int n, m, k;
int dist(int x1, int y1, int x2, int y2){
int x = x1 - x2;
int y = y1 - y2;
return x * x + y * y;
}
int minimumEnergyCost(vector <int> cX, vector <int> cY, vector <int> bX, vector <int> bY, vector <int> pX, vector <int> pY, int SPL)
{
n = cX.size(), m = bY.size(), k = pX.size();
F.init(, m + k + , m + k + );
//printf("%d %d\n", F.T, F.n);
for (int i = ; i < m; ++i)
for (int j = ; j < k; ++j)
if (dist(bX[i], bY[i], pX[j], pY[j]) <= SPL * SPL) F.add_edge(i + , m + j + , Inf);
for (int i = ; i < m; ++i){
int d = Inf;
for (int j = ; j < n; ++j)
d = min(d, dist(bX[i], bY[i], cX[j], cY[j]));
F.add_edge(, i + , d);
}
for (int i = ; i < k; ++i){
int d = Inf;
for (int j = ; j < n; ++j)
d = min(d, dist(pX[i], pY[i], cX[j], cY[j]));
F.add_edge(i + + m, F.T, d);
}
// for (int i = 0; i < F.tot; ++i)
// printf("%d %d %d\n",F.e[i].y, F.e[i].f, F.e[i].next);
return F.maxflow();
} };

SRM465的更多相关文章

随机推荐

  1. linux系统web站点设置-http基础设置

    一.httpd2.2的组成: /etc/httpd:服务器的根目录 conf/httpd.conf,conf.d/*:配置文件 conf/magic:MIME的配置文件 logs:日志文件的存放路径, ...

  2. jzoj P1163 生日派对灯

    在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码.这些灯都连接到四个按钮:  按钮1:当按下此按钮,将改变所有的灯:本来亮着的灯就熄灭,本来是 ...

  3. ES开发的一些坑(一)

    一.ES-Hadoop导数据的时候报"Could not write all entries"异常  ES-Hadoop是一个开源的数据导入项目,支持数据从hdfs,hive,sp ...

  4. Two Sum IV - Input is a BST LT653

    Given a Binary Search Tree and a target number, return true if there exist two elements in the BST s ...

  5. Scrapy的安装和基本使用方法

    Scrapy的安装 1. Windows下安装流程: 方法一: 命令行执行pip install scrapy 安装scrapy 注意:如果有anaconda,也可以打开“Anaconda promp ...

  6. App上架流程[利用Archive进行上传]

    作者 M_Lee2016.01.22 10:47 写了14852字,被32人关注,获得了49个喜欢 [iOS]App上架流程[利用Archive进行上传] 字数2186 阅读507 评论3 喜欢9 今 ...

  7. python学习 day5 (3月6日)

    字典映射,{}键值对,key 唯一的 ,可哈希,容器型数据类型 可变的(不可哈希): 字典 列表 集合 都不可做键 不可变的(可哈希): 数字 字符串 bool 元组 frozeset() 可以做键 ...

  8. IOS 单击手势和cell点击冲突

    环境: view上添加tableView,给view添加单击手势,点击cell却走的是手势方法. 解决: UITapGestureRecognizer *tap=[[UITapGestureRecog ...

  9. 2018.11.06 洛谷P1099 树网的核(最短路+枚举)

    传送门 之前看李煜东的书一直感觉是道神题. 然后发现这题数据范围只有300?300?300? 直接上floydfloydfloyd然后暴力就完了啊. 代码: #include<bits/stdc ...

  10. python code(1)

    from collections import UserList class MthChianList(UserList): def filter(self,predicste): return Mt ...