牛客暑假多校第二场 F trade
题意: 白兔有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的更多相关文章
- 牛客暑假多校第二场J-farm
一.题意 White Rabbit has a rectangular farmland of n*m. In each of the grid there is a kind of plant. T ...
- 牛客暑假多校第二场 K carpet
题意:给你一个n*m的矩阵 ,每个位置都有一个字符并且都有一个值,现在需要找到一个p*q的子矩阵, 原来的矩阵可以由现在这个矩阵无限复制然后截取其中的一部分得到,并且要求 子矩阵里最大的值 * (p+ ...
- 2019 牛客暑期多校 第二场 H Second Large Rectangle (单调栈)
题目:https://ac.nowcoder.com/acm/contest/882/H 题意:一个大的01矩阵,然后现在要求第二大的全一矩阵是多少 思路:在这里我们首先学习一下另一个东西,怎么求直方 ...
- 2019牛客暑期多校第二场题解FH
F.Partition problem 传送门 题意:有2n个人,分两组,每组n个,要求sum(vij)最大值. 题解:n并不大我们可以枚举每个人是在1组还是2组爆搜. 代码: #include &l ...
- 牛客暑假多校第一场J-Different Integers
一.题目描述: 链接:https://www.nowcoder.com/acm/contest/139/JGiven a sequence of integers a1, a2, ..., an an ...
- 牛客暑假多校第一场 J Different Integers
题意:给你一个数组, q次询问, 每次询问都会有1个[l, r] 求 区间[1,l] 和 [r, n] 中 数字的种类是多少. 解法1, 莫队暴力: 代码: #include<bits/stdc ...
- 2019牛客暑假多校赛(第二场) F和H(单调栈)
F-Partition problem https://ac.nowcoder.com/acm/contest/882/F 题意:输入一个数n,代表总共有2n个人,然后每个人对所有人有个贡献值,然后问 ...
- 优化剪枝搜索——牛客多校第二场F
试了很多种爆搜和剪枝,最后发现还是状压的比较好用 #include <bits/stdc++.h> using namespace std; // #define IO #define f ...
- 2019牛客多校第二场F Partition problem 暴力+复杂度计算+优化
Partition problem 暴力+复杂度计算+优化 题意 2n个人分成两组.给出一个矩阵,如果ab两个在同一个阵营,那么就可以得到值\(v_{ab}\)求如何分可以取得最大值 (n<14 ...
随机推荐
- 微信小程序登陆流程图时序图
微信小程序登录 小程序可以通过微信官方提供的登录能力方便地获取微信提供的用户身份标识,快速建立小程序内的用户体系. 微信小程序登录流程时序图 说明 调用 wx.login() 获取 临时登录凭证cod ...
- springboot-权限控制shiro(二)
目录 1. 场景描述 2. 解决方案 1. 场景描述 (1)最近有点小忙,公司真实项目内容有点小多以及不想只介绍理论,就使用springboot单独部署了个shiro的demo项目,还是理论和实际项结 ...
- 【Python-Django后端】用户注册通用逻辑,用户名、手机号重名检测,注册成功后状态保持!!!
用户注册后端逻辑 1. 接收参数 username = request.POST.get('username') password = request.POST.get('password') pas ...
- 技巧:结合Zabbix与SNMP监控嵌入式设备
在如何利用Zabbix监控网络设备三篇文章的前两篇中,我们介绍了如何通过Zabbix代理监控网络设备.但有些设备无法安装Zabbix代理,需要采用其他方法监控.需要考虑无法安装软件的嵌入式设备或应用程 ...
- c#小灶——注释和代码规范
为什么要写注释? 早上我写完了代码,我和我的朋友们都能看懂,到了晚上,我还能看懂,一周后,就只有上帝能看懂了…… 将来我们写的代码量是很大的,代码又不像我们自然语言这么好理解,可能过段时间我们就不认识 ...
- 理解分布式一致性与Raft算法
理解分布式一致性与Raft算法 永远绕不开的CAP定理 出于可用性及负载方面考虑,一个分布式系统中数据必然不会只存在于一台机器,一致性简单地说就是分布式系统中的各个部分保持数据一致 但让数据保持一致往 ...
- Office2019 VOL版本 自定义安装组件
众所周知,Office VOL版本可以连接KMS服务器激活,但是office2019没有镜像可以下载,所以只能依靠Office Deployment Tool来进行操作.注:Office2019 Re ...
- ieda控制台缓冲区限制问题
一.现象 控制台输出数据若超过默认值时,将从后向前取默认值大小数据(1024) 二.解决方案 1.配置文件(idea安装目录/bin/idea.properties) 2.找到该栏:idea.cycl ...
- java虚拟机学习笔记(四)---回收方法区
Java虚拟机规范中规定不要求虚拟机在方法区实现垃圾收集,而且在方法区实现垃圾收集性价比确实很低.在堆中,尤其是新生代,一次垃圾收集可以回收75%-95%的空间,而永久代的垃圾回收效率远低于此. 永久 ...
- Python 參考網站
Python 3 Readiness : http://py3readiness.org/ Python Speed Center : https://speed.python.org/ Python ...