当前位置: 首页 > news >正文

【过题记录】 8.3

补一下昨天的,晚上头痛就先回去了
上次比赛碰到了网络流,发现还没点,今天只做了几个网络流的板子

网络最大流

#include<bits/stdc++.h>
using namespace std;#define int long longconst int N = 5e3+100,inf = 1e18;
int n,m;
struct Node{int y,Next,v;
}e[2*N];
int len = 1,Linkk[N];
int inv[N];
int st,ed;void Insert(int x,int y,int z){e[++len] = (Node){y,Linkk[x],z};Linkk[x] = len;
}int maxf = 0;
bool vis[N];
int pre[N];
bool bfs(){queue < int > q;memset(vis,0,sizeof vis);inv[st] = inf;q.push(st); vis[st] = 1;while (q.size()){int x = q.front(); q.pop();for (int i = Linkk[x]; i; i = e[i].Next){int y = e[i].y;if (e[i].v == 0) continue; if(vis[y]) continue; vis[y] = 1; inv[y] = min(inv[x],e[i].v);q.push(y); pre[y] = i;if (y == ed) return 1;}}return 0;
}void Upd(){
//	cout<<"OK";int now = ed;
//	cout<<inv[ed]<<endl;while (now != st){
//		cout<<"now = "<<now<<endl;int nowe = pre[now];e[nowe].v-=inv[ed];e[nowe^1].v+=inv[ed];now = e[nowe^1].y;}
//	cout<<"now = "<<now<<endl;maxf+=inv[ed];
//	cout<<"macf = "<<maxf<<endl;
}signed main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);cin>>m>>n; st = 1; ed = n;for (int i = 1,x,y,z; i <= m; i++)cin>>x>>y>>z,Insert(x,y,z),Insert(y,x,0);while (bfs()) Upd();cout<<maxf;return 0; 
}
/*
7 10 1 7
1 2 4
1 3 5
2 3 1
2 4 5
3 5 5
3 4 2
5 4 6
4 7 5
5 6 3
6 7 4
*/ 

二分图匹配

#include<bits/stdc++.h>
using namespace std;

const int N = 1e5+100,inf = 1e9;
int n,m,ee;
struct Node{
int y,Next,v;
}e[2*N];
int len = 1,Linkk[N];
int maxf,inv[N];
int d[N];
int st,ed;

void Insert(int x,int y,int v){
e[++len] = (Node){y,Linkk[x],v};
Linkk[x] = len;
}

queue < int > q;
bool bfs(){
for (int i = 1; i <= n+m+2; i++) d[i] = 0;
while (q.size()) q.pop();
q.push(st); d[st] = 1;
while (q.size()){
int x = q.front(); q.pop();
for (int i = Linkk[x]; i; i = e[i].Next){
int y = e[i].y;
if (!e[i].v || d[y]) continue;
q.push(y);
d[y] = d[x]+1;
if (y == ed) return 1;
}
}
return 0;
}

int dicnic(int x,int flow){
if (x == ed) return flow;
int re = flow,k;
for (int i = Linkk[x]; i; i = e[i].Next){
int y = e[i].y;
if (!e[i].v || d[y]!=d[x]+1) continue;
k = dicnic(y,min(re,e[i].v));
if (!k) d[y] = 0;
e[i].v-=k; e[i^1].v+=k;
re-=k;
}
return flow-re;
}

int main(){
cin>>n>>m>>ee;
st = n+m+1; ed = n+m+2;
for (int i = 1; i<= n; i++) Insert(st,i,1),Insert(i,st,0);
for (int i = 1,x,y,v; i <= ee; i++)
cin>>x>>y,Insert(x,y+n,1),Insert(y+n,x,0);
for (int i = n+1; i <= n+m; i++)
Insert(i,ed,1),Insert(ed,i,0);
int flow = 0;
while (bfs())
while (flow=dicnic(st,inf)) maxf+=flow;
cout<<maxf<<endl;
return 0;
}


假期的宿舍

#include<bits/stdc++.h>
using namespace std;const int N = 2000,inf = 1e9;
int t;
int n;
struct Node{int y,Next,v;
}e[2*N];
int Linkk[N],len = 1;
bool iss[N],ish[N];
int st,ed;void Insert(int x,int y,int v){e[++len] = (Node){y,Linkk[x],v};Linkk[x] = len;
}int cnt = 0,maxf;
queue < int > q;
int d[N];bool bfs(){for (int i = 1; i <= 2*n+2; i++) d[i] = 0;while (q.size()) q.pop();q.push(st); d[st] = 1;while (q.size()){int x = q.front(); q.pop();for (int i = Linkk[x]; i; i = e[i].Next){int y = e[i].y; if (!e[i].v || d[y]) continue;d[y] = d[x]+1; q.push(y);if (y == ed) return 1;} }return 0;
}
int b[N];
int dicnic(int x,int flow){if (x == ed) return flow;int re = flow,k;for (int i = Linkk[x]; i; i = e[i].Next){int y = e[i].y;if (!e[i].v || d[y]!=d[x]+1) continue;k = dicnic(y,min(re,e[i].v));if (!k) d[y] = 0;e[i].v-=k; e[i^1].v+=k;re-=k;}return flow-re;
}void Work(){scanf("%d",&n);len = 1;for (int i = 1; i <= n; i++) cin>>iss[i];for (int i = 1; i <= n; i++){int op; scanf("%d",&op);if (op != 0 && op != 1) continue;if (!iss[i]) continue;ish[i] = op;}
//	for (int i = 1; i <= n; i++) cout<<ish[i]<<endl;for (int i = 1; i <= n; i++)if (iss[i] && !ish[i]) Insert(i,i+n,1),Insert(i+n,i,0);for (int i = 1; i <= n; i++){if (iss[i] && ish[i]) continue;
//		cout<<"i = "<<i<<endl;cnt++;} st = 2*n+1; ed = 2*n+2;
//	cnt = 0;for (int i = 1; i <= n; i++){for (int j = 1; j <= n; j++) scanf("%d",&b[j]);
//		if (iss[i] && ish[i]) continue; cnt++;
//		if (iss[i]) {Insert(i,i+n,1),Insert(i+n,i,0);continue;}for (int j = 1; j <= n; j++)if(b[j] == 1 && iss[j]) Insert(i,j+n,1),Insert(j+n,i,0);}for (int i = 1; i <= n; i++) if (!iss[i] || !ish[i]) Insert(st,i,1),Insert(i,st,0);for(int i = n+1; i <= 2*n; i++) if (iss[i-n]) Insert(i,ed,1),Insert(ed,i,0); int flow = 0;while (bfs())while (flow = dicnic(st,inf)) maxf+=flow;
//	cout<<maxf<<' '<<cnt<<endl;if(maxf == cnt) cout<<"^_^"<<endl; else cout<<"T_T"<<endl;maxf = 0; cnt = 0;memset(iss,0,sizeof iss); memset(ish,0,sizeof ish); memset(Linkk,0,sizeof Linkk);return;
}int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);cin>>t; while (t--) Work();return 0; 
}

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • CTFHUB-SSRF-DNS重绑定 Bypass
  • [米联客-安路飞龙DR1-FPSOC] UDP通信篇连载-01 以太网协议介绍
  • ai web 1.0靶机漏洞渗透详解
  • 搭建个人的金融系统-----第一章,数据库设计
  • Arch Linux - 2-安装中文输入法
  • 解析 C# Dictionary 代码
  • Comfyui实例容器运行横向扩展
  • 【ROS 最简单教程 003/300】ROS 快速体验:Hello World
  • C# Where关键字
  • 数学建模--蒙特卡罗随机模拟
  • 嵌入式Linux系统中pinictrl框架基本实现
  • 数学建模--禁忌搜索
  • Kafka操作
  • 现代前端架构介绍(第三部分):深入了解状态管理层及其对前端App的影响
  • tcp westwood 比 reno,cubic 好在哪
  • 时间复杂度分析经典问题——最大子序列和
  • flutter的key在widget list的作用以及必要性
  • IDEA 插件开发入门教程
  • js正则,这点儿就够用了
  • Laravel深入学习6 - 应用体系结构:解耦事件处理器
  • leetcode98. Validate Binary Search Tree
  • Linux链接文件
  • MYSQL如何对数据进行自动化升级--以如果某数据表存在并且某字段不存在时则执行更新操作为例...
  • webpack入门学习手记(二)
  • 悄悄地说一个bug
  • 使用Maven插件构建SpringBoot项目,生成Docker镜像push到DockerHub上
  • 用Canvas画一棵二叉树
  • 用Visual Studio开发以太坊智能合约
  • nb
  • No resource identifier found for attribute,RxJava之zip操作符
  • 微龛半导体获数千万Pre-A轮融资,投资方为国中创投 ...
  • ​iOS安全加固方法及实现
  • #LLM入门|Prompt#3.3_存储_Memory
  • #QT(QCharts绘制曲线)
  • #systemverilog# 之 event region 和 timeslot 仿真调度(十)高层次视角看仿真调度事件的发生
  • #微信小程序(布局、渲染层基础知识)
  • (2024,LoRA,全量微调,低秩,强正则化,缓解遗忘,多样性)LoRA 学习更少,遗忘更少
  • (pt可视化)利用torch的make_grid进行张量可视化
  • (第61天)多租户架构(CDB/PDB)
  • (附源码)计算机毕业设计SSM疫情社区管理系统
  • (黑马出品_高级篇_01)SpringCloud+RabbitMQ+Docker+Redis+搜索+分布式
  • (六)软件测试分工
  • (十) 初识 Docker file
  • (原創) 如何讓IE7按第二次Ctrl + Tab時,回到原來的索引標籤? (Web) (IE) (OS) (Windows)...
  • (转)人的集合论——移山之道
  • ***汇编语言 实验16 编写包含多个功能子程序的中断例程
  • .Net 4.0并行库实用性演练
  • .NET Core引入性能分析引导优化
  • .NET 常见的偏门问题
  • .NET 读取 JSON格式的数据
  • .NET 事件模型教程(二)
  • .NET 项目中发送电子邮件异步处理和错误机制的解决方案
  • .Net的DataSet直接与SQL2005交互
  • .NET与 java通用的3DES加密解密方法
  • @angular/cli项目构建--http(2)