【BZOJ 1305】[CQOI2009]dance跳舞
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
男生和女生每个人都分身成两个节点
即x[1],x[2]和y[1],y[2]
然后如果i和j不相互喜欢
那么add(x[i][2],y[j][2],1)
如果相互喜欢的话
add(x[i][1],y[j][1],1)
然后对于每个男生
add(x[i][1],y[i][1],k)
对于每个女生
add(y[i][2],y[i][1],k)
然后对于每个男生
add(s,x[i][1],mid)
add(y[i][1],t,mid)
这里的mid是二分的值。
这个mid就是舞会的轮数了。
如果能够满流显然每个人都能配对跳mid支舞
显然是有单调性的。
(然后发现原来的dicnic的模板是错的。。边数的计算要特别careful.
【代码】
#include <bits/stdc++.h>
using namespace std;const int N = 50;struct abc{int nex,en,flow;
}bian[2][N*N*2+8*N+10];int n,k,x[N+10][3],y[N+10][3],fir[2][N*4+10],tfir[N*4+10],totm,deep[N*4+10];
int cnt = 0;
bool bo[N+10][N+10];
char s[N+10];
queue<int> dl;//每个男人分为(x1,x2)
//每个女人分为(y1,y2)void add(int x,int y,int cost,int i){bian[i][totm].nex = fir[i][x];fir[i][x] = totm;bian[i][totm].en = y,bian[i][totm].flow = cost;totm++;bian[i][totm].nex = fir[i][y];fir[i][y] = totm;bian[i][totm].en = x,bian[i][totm].flow = 0;totm++;
}bool bfs(int s,int t){dl.push(s);memset(deep,255,sizeof deep);deep[s] = 0;while (!dl.empty()){int x = dl.front();dl.pop();for (int temp = fir[1][x]; temp!= -1 ;temp = bian[1][temp].nex){int y = bian[1][temp].en;if (deep[y]==-1 && bian[1][temp].flow>0){deep[y] = deep[x] + 1;dl.push(y);}}}return deep[t]!=-1;
}int dfs(int x,int t,int limit){if (x == t) return limit;if (limit == 0) return 0;int cur,f = 0;for (int temp = tfir[x];temp!=-1;temp = bian[1][temp].nex){tfir[x] = temp;int y = bian[1][temp].en;if (deep[y] == deep[x] + 1 && (cur = dfs(y,t,min(limit,bian[1][temp].flow))) ){f += cur;limit -= cur;bian[1][temp].flow -= cur;bian[1][temp^1].flow += cur;if (!limit) break;}}return f;
}int get_flow(){int now = 0;while (bfs(0,cnt)){for (int i = 0;i <= cnt;i++) tfir[i] = fir[1][i];int xxx = dfs(0,cnt,10000);now+=xxx;}return now;
}int main(){//freopen("F:\\program\\rush\\rush_in.txt","r",stdin);ios::sync_with_stdio(0),cin.tie(0);memset(fir[0],255,sizeof fir[0]);cin >> n >> k;for (int i = 1;i <= n;i++){cin >> (s+1);for (int j = 1;j <= n;j++)if (s[j]=='Y'){bo[i][j] = 1;}}for (int i = 1;i <= n;i++){for (int j = 1;j <= 2;j++)x[i][j] = ++cnt;}for (int i = 1;i <= n;i++)for (int j = 1;j <= 2;j++)y[i][j] = ++cnt;cnt++;for (int i = 1;i <= n;i++){for (int j = 1;j <= n;j++){if (bo[i][j])add(x[i][1],y[j][1],1,0);else{add(x[i][2],y[j][2],1,0);}}}for (int i = 1;i <= n;i++){add(x[i][1],x[i][2],k,0);add(y[i][2],y[i][1],k,0);}int l = 0,r = n+1,temp1 = 0;while (l<=r){int i = (l+r)>>1;for (int j = 0;j < totm;j++) bian[1][j] = bian[0][j];for (int j = 0;j <= cnt;j++) fir[1][j] = fir[0][j];int tt = totm;for (int j = 1;j <= n;j++){add(0,x[j][1],i,1);add(y[j][1],cnt,i,1);}int temp = get_flow();if (temp!=i*n){r = i-1;}else {temp1 = i;l = i+1;}totm = tt;}cout<<temp1<<endl;return 0;
}
转载于:https://www.cnblogs.com/AWCXV/p/9088540.html
【BZOJ 1305】[CQOI2009]dance跳舞相关推荐
- BZOJ 1305 [CQOI2009]dance跳舞
这是一道最大流的模版题 一定要记住不能开出来重点呀 #include <queue> #include <cstdio> #include <cstring> #i ...
- 【BZOJ - 1305】dance跳舞(拆点网络流,建图,最大流,残留网络上跑最大流)
题干: 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲.有一些男孩女孩相互喜欢,而其他相互不喜欢(不会"单向 ...
- 【BZOJ 1305】 [CQOI2009]dance跳舞
1305: [CQOI2009]dance跳舞 Time Limit: 5 Sec Memory Limit: 162 MB Submit: 1586 Solved: 666 [ Submit ...
- BZOJ1305 [CQOI2009]dance跳舞 【网络流】
1305: [CQOI2009]dance跳舞 Time Limit: 5 Sec Memory Limit: 162 MB Submit: 3714 Solved: 1572 [Submit][ ...
- 【BZOJ1305】 [CQOI2009]dance跳舞
Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲.有一些男孩女孩相互喜欢,而其他相互不喜欢(不会 ...
- [bzoj1305][CQOI2009]dance跳舞
Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲.有一些男孩女孩相互喜欢,而其他相互不喜欢(不会 ...
- BZOJ1305: [CQOI2009]dance跳舞
[传送门:BZOJ1305] 简要题意: 有n个男生和n个女生,男生和女生之间存在喜欢关系(只可能互相喜欢,不存在单向喜欢),给出一个字符矩阵代表男生女生之间的关系.他们要跳舞,跳舞的时候有歌,可以跳 ...
- bzoj1305【CQOI2009】dance 跳舞
1305: [CQOI2009]dance跳舞 Time Limit: 5 Sec Memory Limit: 162 MB Submit: 2041 Solved: 853 [ Submit ...
- 【CQOI2009】跳舞
[CQOI2009]跳舞 [题目描述] 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲. 有一些男孩女孩相互喜欢,而 ...
最新文章
- keras lstm 层理解
- python把图片另存为_pycharm sciview的图片另存为操作
- 添加nginx为系统服务(service nginx start/stop/restart)
- 十 Java集合框架(2):Set接口
- linux netbeans 中文乱码,浅谈Linux Netbeans字体反锯齿处理
- mysql call procedure into_mysql存储过程之创建(CREATE PROCEDURE)和调用(CALL)及变量...
- Dnn's Event Logging API
- mybatis resultType resultMap
- zoj1022 Parallel Expectations(DP)
- yum mysql安装 日志_yum 安装与使用MySQL
- Mnist数据集解析
- 电力系统自动化远程监控方案
- FTL 算法之Arbiter
- [6.837]A3:OpenG应用和Phong着色模型
- H型钢的尺寸的设计与使用(市场上可以轻松采购)
- OpenCV计算均值和方差
- PHP学习:PHP+Apache 安装/配置
- 手把手教你批量收藏宗介和波妞壁纸
- IIS如何防ASP木马
- 实战 Vue 之实现添加和删除常用应用功能
热门文章
- localtime、localtime_s、localtime_r的使用
- ethz-asl Hand-Eye-Calibration 实验之hand_eye_calibration_batch_estimation模块
- 注销计算机桌面的东西会没有么,电脑注销会删掉内容吗
- 2020CCPC绵阳D.Defuse the Bombs(二分)
- JavaWeb购物车项目二
- Loadrunner安装破解
- 如何压缩图片大小到200k以下?照片太大怎么压缩到200k?
- 【语义分割】语义分割经典模块
- 使用FreeType绘制字体
- 电脑软件连接ABB机器人控制柜