题意: 白兔有n个仓库,每个仓库有啊ai个货物,在每个仓库白兔可以装上任意数量的货物,也可以卸下任意数量的货物,现在有k个圆形信号阻隔器,然后有m个顾客下个一个订单,每个顾客的收货量有一个上限, 在每个订单中,白兔都会走过si个仓库, 从s[0] 按(输入)顺序依次遍历所有仓库, 当白兔遍历完所有仓库之后白兔会就会把车上的货物送到顾客家里。如果某个仓库和顾客的连线在某个圆形信号阻隔器的覆盖范围之内,那么白兔就不会去这个仓库。 求最后白兔给所有顾客的总的货物最多是多少。

题解:由于白兔在每个仓库的时候可以拿/放任意货物, 也就相当于白兔走过的仓库就已经是连起来了, 所以每次到一个新的仓库之后, 他就可以与前一个仓库所链接的所有仓库相连接了(单向),因为可以将连接的仓库的所有货物都放在这个仓库, 然后这个仓库到下一个仓库的时候就可以将这些货物带到下一个仓库, 也就是说仓库(单向)相连了, 可以任意的从前面的仓库把货物拿过来。 然后就是网络流模型了, 将每个仓库都与源点相连, 边值为货物数量上限, 每个顾客与可以走的仓库连线,边值为inf,所有顾客再与汇点相连,边值为顾客的最大收货量。 再跑一遍 s -> t的最大网络流就是答案了。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define db double
double eps = 1e-;
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 2e3+;
const int M = 3e6+;
int n, m, k;
bitset<N>bit[N];
int x1[N], y11[N], x3[N], y3[N], r[N], a[N];
int x2[N], y2[N];
struct Point{
double x, y;
Point(double _x, double _y){x = _x, y = _y;}
double len(){return sqrt(x * x + y * y);}
Point operator-(const Point &_){
return Point(x - _.x, y - _.y);
}
double operator*(const Point &_){
return x * _.y - y * _.x;
}
double operator%(const Point &_){
return x * _.x + y * _.y;
}
}; bool ok(int x, int y, int id){
for (int h = ; h <= k; h ++){
Point A = Point(x1[id], y11[id]), B = Point(x, y), P = Point(x3[h], y3[h]);
Point result(, );
double t = ((P - A) % (B - A)) / ((B - A) % (B - A));
if (t >= && t <= ){
result = Point(A.x + (B.x - A.x) * t, A.y + (B.y - A.y) * t);
}
else{
if ((P - A) % (P - A) < (P - B) % (P - B))
result = A;
else
result = B;
}
if ((P - result) % (P - result) < r[h] * r[h] + eps) return ;
}
return ;
} int head[N], to[M], nx[M];
LL w[M];
int deep[N], cur[N];
int tot;
int sz;
void add(int u, int v, LL val){
w[tot] = val; to[tot] = v;
nx[tot] = head[u]; head[u] = tot++;
}
int bfs(int s, int t){
queue<int> q;
memset(deep, , sizeof(int)*sz);
q.push(s);
deep[s] = ;
while(!q.empty()){
int u = q.front();
q.pop();
for(int i = head[u]; ~i; i = nx[i]){
if(w[i] > && deep[to[i]] == ){
deep[to[i]] = deep[u] + ;
q.push(to[i]);
}
}
}
return deep[t] > ;
}
LL Dfs(int u, int t, LL flow){
if(u == t) return flow;
for(int &i = cur[u]; ~i; i = nx[i]){
if(deep[u]+ == deep[to[i]] && w[i] > ){
LL di = Dfs(to[i], t, min(w[i], flow));
if(di > ){
w[i] -= di, w[i^] += di;
return di;
}
}
}
return ;
}
LL Dinic(int s, int t){
LL ans = , tmp;
while(bfs(s, t)){
for(int i = ; i <= sz; i++) cur[i] = head[i];
while(tmp = Dfs(s, t, INF)) ans += tmp;
}
return ans;
}
void init(int _sz){
memset(head, -, sizeof(head));
tot = ;
sz = _sz;
} int main(){
scanf("%d%d%d", &n, &m, &k);
int s = , t = n+m+;
init(t+);
for(int i = ; i <= n; i++){
scanf("%d%d%d", &x1[i], &y11[i], &a[i]);
add(s,i,a[i]);
add(i,s,);
bit[i][i] = ;
}
for(int i = ; i <= k; i++)
scanf("%d%d%d", &x3[i], &y3[i], &r[i]);
int x, y, lim, b, c;
for(int i = ; i <= m; i++){
scanf("%d%d%d%d", &x, &y, &b, &lim);
int last = ;
while(b--){
scanf("%d", &c);
if(ok(x,y,c)) {
if(last) bit[c] |= bit[last];
last = c;
}
}
if(!last) continue;
add(n+i, t, lim);
add(t, n+i, );
for(int j = ; j <= n; j++)
if(bit[last][j]){
add(j, n+i, INF);
add(n+i, j, );
}
}
printf("%lld\n",Dinic(s,t));
return ;
}

牛客暑假多校第二场 F trade的更多相关文章

  1. 牛客暑假多校第二场J-farm

    一.题意 White Rabbit has a rectangular farmland of n*m. In each of the grid there is a kind of plant. T ...

  2. 牛客暑假多校第二场 K carpet

    题意:给你一个n*m的矩阵 ,每个位置都有一个字符并且都有一个值,现在需要找到一个p*q的子矩阵, 原来的矩阵可以由现在这个矩阵无限复制然后截取其中的一部分得到,并且要求 子矩阵里最大的值 * (p+ ...

  3. 2019 牛客暑期多校 第二场 H Second Large Rectangle (单调栈)

    题目:https://ac.nowcoder.com/acm/contest/882/H 题意:一个大的01矩阵,然后现在要求第二大的全一矩阵是多少 思路:在这里我们首先学习一下另一个东西,怎么求直方 ...

  4. 2019牛客暑期多校第二场题解FH

    F.Partition problem 传送门 题意:有2n个人,分两组,每组n个,要求sum(vij)最大值. 题解:n并不大我们可以枚举每个人是在1组还是2组爆搜. 代码: #include &l ...

  5. 牛客暑假多校第一场J-Different Integers

    一.题目描述: 链接:https://www.nowcoder.com/acm/contest/139/JGiven a sequence of integers a1, a2, ..., an an ...

  6. 牛客暑假多校第一场 J Different Integers

    题意:给你一个数组, q次询问, 每次询问都会有1个[l, r] 求 区间[1,l] 和 [r, n] 中 数字的种类是多少. 解法1, 莫队暴力: 代码: #include<bits/stdc ...

  7. 2019牛客暑假多校赛(第二场) F和H(单调栈)

    F-Partition problem https://ac.nowcoder.com/acm/contest/882/F 题意:输入一个数n,代表总共有2n个人,然后每个人对所有人有个贡献值,然后问 ...

  8. 优化剪枝搜索——牛客多校第二场F

    试了很多种爆搜和剪枝,最后发现还是状压的比较好用 #include <bits/stdc++.h> using namespace std; // #define IO #define f ...

  9. 2019牛客多校第二场F Partition problem 暴力+复杂度计算+优化

    Partition problem 暴力+复杂度计算+优化 题意 2n个人分成两组.给出一个矩阵,如果ab两个在同一个阵营,那么就可以得到值\(v_{ab}\)求如何分可以取得最大值 (n<14 ...

随机推荐

  1. Mybatis连接查询返回类型问题

    一对一映射 public class Card { private Integer id; private String num; private Student student; //重要 publ ...

  2. 刷脸即可解锁让iDevice取证不再难如登天

    最近有则取证相关的消息,链接如下,光看标题便知道与Apple的Face ID有关. https://www.cnet.com/news/fbi-unlocked-an-iphone-x-by-forc ...

  3. 使用Java 编写FTP中的长传文件和下载文件

    实现FTP文件上传与下载可以通过以下两种种方式实现(不知道还有没有其他方式,),分别为:1.通过JDK自带的API实现:2.通过Apache提供的API是实现. 第一种方法:通过JDK自带的API实现 ...

  4. centos7安装mongodb详解

    记录一下linux下安装mongodb数据库过程. 安装mongodb #下载linux版本的tar文件#  例如笔者下载的是:mongodb-linux-x86_64-rhel70-3.4.4.tg ...

  5. 2、大型项目的接口自动化实践记录--接口测试简介及RequestsLibrary关键字简介

    1.接口测试简介 1)先简单介绍下接口测试,那么什么是接口测试呢? 百科的回答:接口测试是测试系统组件间接口的一种测试.接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互点. 看起来有 ...

  6. linux CPU100%异常排查

    1.top查找出占CPU比例最高的进程(5881): 2.查看该进程正在执行的线程: top -H -p  5881 3.将线程转换成16进制 printf ‘%x\n’ 5950 4.查看异常线程执 ...

  7. JavaScript数据结构——树的实现

    在计算机科学中,树是一种十分重要的数据结构.树被描述为一种分层数据抽象模型,常用来描述数据间的层级关系和组织结构.树也是一种非顺序的数据结构.下图展示了树的定义: 在介绍如何用JavaScript实现 ...

  8. F#周报2019年第32期

    新闻 推出FSharp.Core 4.7,附带netstandard2支持 ML.NET 1.3.1发布 FSharp.SystemTextJson宣告:对于.NET Core的System.Text ...

  9. laravel新项目报错 No application encryption key has been specified.

    解决办法, 若文件根目录下没有 .env 1..env.example 改名使用命令 copy 修改为 .env 2.使用命令 php artisan key:generate  获取密码,自动保存到 ...

  10. XAMPP/LAMPP到底在哪里启用APACHE2的rewrite

    XAMPP/LAMPP是一套我们在个人建站过程中非常便捷常用的集成环境.特别是对于学习PHP开发和建站非常便捷. 最近在使用CentOS7环境下的XAMPP过程中,遇到了一个问题,也就是apache2 ...