jzoj2701 【GDKOI2012模拟02.01】矩阵
传送门:https://jzoj.net/senior/#main/show/2701
【题目大意】
给出矩阵A,求矩阵B,使得
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAAB8CAIAAADYRapmAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAQs0lEQVR4nO2dvZKyPBvHL955DgW22PEI4AhgGytbOyihubudee5nZrttoITO1spGcgRyBI6F5FzyFuFT+UgwImB+lesCifg35OO6/lEIISCRLIX/vboCEolIpKAli0IKWrIopKAli0IK+vngwFAUxUGAHEVRFCPAr67RgpGCHggOjFyayFEUB7UeiY6wS309spTDmpDYHq2KE6W8XTgwum7cIKSgh4ADQ/NW8clVGQ42XReO+8SOSWgCOkSrD5az3gHVPcVgiX1kzUjQODA6W8IRK7L1wE9Dk/mM9JLYaxMA0CGy1yYKZK8jwwxTH7ytuPsxE0EjR1G0/SYlHCp6Wl1+vcT+Zmqc8zMOkf6pZX9ElnL44Dl74ajut514v6IaqjkIGgeGFel+yvaEfzboEEEpTybMkGR1N0NCyBR+lVNC+9QhOghS9PQFjYOtl+j+bhJqBsDXM+ibr2lUZhmoHyuA81VMr2PygsbHfQJ8T/inkl6SV1dhcWifOiSXVMi1pi5ofNwnvE/4Z4KvZwA5TzFdpi7o9JLM6wlPV1EGMIX5mxchss8xcUHPr0FU3Z2v05d2TFhI8+PfFnw9C7vWxAWdXibV4cjobkwKSUcWU6tb+QlIHmbaghb50xWD+rGC3gFMRdJMq2Dq1+atFZ1eEmHP4WkLGgBm1uPIUN0TDdpImFbB1I/V06v0Jkxb0BOcI9M+dbYBjBlySNoM33i1BV/PIKxjOW1BTxCmPgfFDOl4L/G0oVMYPYF8U4a96iJ7HFLQ3DA30cA/PqyBHEU5rGe7UG6GhKwPDKIW2kBLQXPD0URDpTPNKWkcGNaZK6Jviphh6p/7PrjQBloKmh/tk29KIu9MM055AMCQiL6JorrfNsNvWdzUrBT0CHCNDwEAB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89YDsAvWhexWWHgeNE5EM5422pLiN1mmkd7uHB/eD6OlxyN0mHkBomuy0W2hp/ibhZNqCFrvj1wPInu4TETpxN3FBT2TrTY7bzRFfP1f7uqfwLltSaJ86JPvjyxXNjOqesqFll1NL3+r9WyHUf3Tqgla/Nq/udHCMWZBTUW1DFl8xwdi2ev++vI2DP03PFObaMKQG7N0eM4xtufTHy4C91NuZvKCp9xCXCZVoOEam1VD3B83h3oaBzoEtTF/QmfdQ4mmvkgN7Dn8t1L2ryyEpwMd9IjC3ZQ6CBtrnTDf7xy0yBsGqaI74euRQh43IevN2W7CeJ571PR1YEpbHMumaLQ03UWzKN5FJsqyYYaeb7Evi6+cPtcMentrTgBQ0K9Q3rKUj/5L4+pmDHEXzVg+n9twgBc2O6p5e2JFfFOK87G5RCHncOEoimQqyhZYsCiloyaKQgpYsCiloyaL4PxvpaoK+qwJnAAAAAElFTkSuQmCC" alt="" width="240" height="124" />
最小,矩阵B每个元素在[L,R]内
n<=200,1<=Aij,L,R<=1000, L<=R
【题解】
我们二分答案x,然后对行列建点,每行向每列连[L,R]的边,然后S向每行连[max(S[i]-x), S[i]+x]的边,每列向T连[max(T[i]-x), T[i]+x]的边,判断是否有可行流即可。
其中S[i]表示A中第i行的和,T[i]表示A中第i列的和。
判断有源汇上下界可行流:按照无源汇那样建边,多来一条(T->S,[0,inf])即可。
然后跑dinic,判断从SS流出的边是否全流满。
# include <queue>
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h> using namespace std; typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = + , N = 5e5 + , inf = 1e9;
const int mod = 1e9+; # define RG register
# define ST static int n, m, a[M][M], s1[M], s2[M], S, T, L, R;
int head[M * ], nxt[N], to[N], flow[N], tot, indeg[M * ];
inline void add(int u, int v, int fl) {
++tot; nxt[tot] = head[u]; head[u] = tot;
to[tot] = v; flow[tot] = fl;
}
inline void adde(int u, int v, int fl) {
add(u, v, fl), add(v, u, );
} inline void tadd(int u, int v, int lf, int rf) {
adde(u, v, rf-lf);
indeg[v] += lf;
indeg[u] -= lf;
} namespace MF {
queue<int> q; int c[M * ], cur[M * ];
inline bool bfs() {
for (int i=; i<=n+m+; ++i) c[i] = -;
while(!q.empty()) q.pop();
q.push(S); c[S] = ;
while(!q.empty()) {
int top = q.front(); q.pop();
for (int i=head[top]; i; i=nxt[i]) {
if(c[to[i]] != - || flow[i] == ) continue;
c[to[i]] = c[top] + ;
q.push(to[i]);
if(to[i] == T) return ;
}
}
return ;
} inline int dfs(int x, int low) {
if(x == T) return low;
int r = low, fl;
for (int i=cur[x]; i; i=nxt[i]) {
if(c[to[i]] != c[x]+ || flow[i] == ) continue;
fl = dfs(to[i], min(r, flow[i]));
flow[i] -= fl; flow[i^] += fl; r -= fl;
if(flow[i] > ) cur[x] = i;
if(!r) return low;
}
if(r == low) c[x] = -;
return low-r;
} inline int main() {
int ans = ;
while(bfs()) {
for (int i=; i<=n+m+; ++i) cur[i] = head[i];
ans += dfs(S, inf);
}
return ans;
}
} # define line(x) (x)
# define row(x) (x+n) inline void build(int x) {
int SS = n+m+, TT = n+m+;
S = n+m+, T = n+m+;
for (int i=; i<=n+m+; ++i) indeg[i] = ;
for (int i=; i<=n; ++i)
for (int j=; j<=m; ++j)
tadd(line(i), row(j), L, R);
for (int i=; i<=n; ++i)
tadd(SS, line(i), max(, s1[i]-x), s1[i]+x);
for (int i=; i<=m; ++i)
tadd(row(i), TT, max(, s2[i]-x), s2[i]+x);
tadd(TT, SS, , inf);
for (int i=; i<=n+m+; ++i) {
if(indeg[i] < ) adde(i, T, -indeg[i]);
else adde(S, i, indeg[i]);
}
} inline bool chk(int x) {
tot = ; memset(head, , sizeof head);
build(x);
MF::main();
// cout << x << endl;
for (int i=head[S]; i; i=nxt[i]) {
// cout << flow[i] << ' ';
if(flow[i] != ) {
// cout << endl;
return false;
}
}
// cout << endl;
return true;
} inline void gans(int ans) {
for (int i=; i<=n; ++i, puts("")) {
for (int j=; j<=m; ++j) {
for (int p=head[line(i)]; p; p=nxt[p]) {
if(to[p] == row(j)) {
printf("%d ", flow[p^] + L);
break;
}
}
}
}
} int main() {
freopen("mat.in", "r", stdin);
freopen("mat.out", "w", stdout);
cin >> n >> m;
for (int i=; i<=n; ++i)
for (int j=; j<=m; ++j) {
scanf("%d", &a[i][j]);
s1[i] += a[i][j];
s2[j] += a[i][j];
}
cin >> L >> R;
int l = , r = 2e5, mid, ans = ;
while() {
if(r-l <= ) {
for (int i=l; i<=r; ++i)
if(chk(i)) {
ans = i;
break;
}
break;
}
mid = l+r>>;
if(chk(mid)) r = mid;
else l = mid;
}
cout << ans << endl;
gans(ans);
return ;
}
jzoj2701 【GDKOI2012模拟02.01】矩阵的更多相关文章
- jzoj2700 【GDKOI2012模拟02.01】数字
传送门:https://jzoj.net/senior/#main/show/2700 [题目大意] 令n为正整数,S(n)为n的各位数字之和,令
- [JZOJ2702] 【GDKOI2012模拟02.01】探险
题目 题目大意 给你一个每条边正反权值不一定相同的无向图,求起点为111点的最小环. 思考历程 一看到这题,就觉得是一个经典模型. 然后思考先前做过最小环的经历,发现没个卵用. 我突然想到,既然这一个 ...
- http://www.cnblogs.com/draem0507/archive/2013/02/01/2889317.html
http://www.cnblogs.com/draem0507/archive/2013/02/01/2889317.html
- oracle问题 《经由直接路径由 EXPORT:V10.02.01 创建的导出文件 IMP-00013: 只有 DBA 才能导入由其他 DBA 导出的文件》
问题: 经由直接路径由 EXPORT:V10.02.01 创建的导出文件 : 只有 DBA 才能导入由其他 DBA 导出的文件 解决方法:用sys 登录,给当前用户授权,授权语句:grant dba ...
- 2016.02.01日,UdoOS系统项目正式开通了
2016.02.01日,UdoOS系统项目正式开通了,源代码即将开放 Copyright (c) 2016
- [EOJ Monthly 2018.10][C. 痛苦的 01 矩阵]
题目链接:C. 痛苦的 01 矩阵 题目大意:原题说的很清楚了,不需要简化_(:з」∠)_ 题解:设\(r_i\)为第\(i\)行中0的个数,\(c_j\)为第\(j\)列中0的个数,\(f_{i,j ...
- 02.02.01 第1章 简介及基础操作(Power BI商业智能分析)
02.02.01.01 powerbi简介 00:10:59 02.02.01.02 query数据导入 00:03:26 具体操作实例如下: 02.02.01.03导入access数据 00:05: ...
- http://www.cnblogs.com/langtianya/archive/2013/02/01/2889682.html
http://www.cnblogs.com/langtianya/archive/2013/02/01/2889682.html
- Leetcode 542.01矩阵
01矩阵 给定一个由 0 和 1 组成的矩阵,找出每个元素到最近的 0 的距离. 两个相邻元素间的距离为 1 . 示例 1: 输入: 0 0 0 0 1 0 0 0 0 输出: 0 0 0 0 1 0 ...
随机推荐
- Cadence17.2下载ALTERA的FPGA封装库
1. 在Cadence的安装目录里面找了下,发现都没有Altera的FPGA型号的函数库,下面的虽然是ALTERA,但是没有FPGA的器件封装 2. 去intel的官网看能不能下载到,INTEL网址, ...
- Windows2008新建域时Administrator 帐户密码不符合要求
Windows 2008 系统安装完毕后,(环境:在安装的时间,系统没有设置密码.做好系统后,进入制面板添加了密码或按ctrl + alt + del 设置密码后 在服务器管理-角色 ...
- springmvc常用jar包
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans ...
- springmvc基础篇—拆分配置文件
一般来讲,在企业实际项目中通常会将配置文件设置为两个:spring-mvc.xml.beans.xml,各自管各自的内容,方便管理. 一.在src下增加如下配置文件: <?xml version ...
- Python 3基础教程25-异常处理
在Python中,异常处理,主要是try except语句,通常语法格式如下. try: 代码块1 except Exception as e: print(e) 代码2 接着前面读取CSV文件,如果 ...
- SPOJ 1812 Longest Common Substring II(后缀自动机)(LCS2)
A string is finite sequence of characters over a non-empty finite set Σ. In this problem, Σ is the s ...
- 文件特殊权限:SUID,SGID,SBIT
我们之前认识的文件的权限仅局限于r,w,x,但如果我们执行命令“ll /tmp; ll /usr/bin/passwd”,会出现除了r,w,x之外的其他字母: 即出现了特殊权限(s跟t). [SetU ...
- java课程设计——2048
1.团队介绍 2.项目git地址 [https://gitee.com/SMTwula/java036.git] 3.项目git提交记录截图 沈梦婷 田亚琴 4.项目功能架构图与主要功能流程图 5.项 ...
- python practive
定义新的操作指令,并将其组合到一起以便能够做一些有意义的事情,这就是编程工作的核心和灵魂. 计算型思维: 1,强调概念化,而非程序化.计算机科学不是计算机程序.像计算机科学家一样的思考,不只是说要编程 ...
- 算法(10)Subarray Sum Equals K
题目:在数组中找到一个子数组,让子数组的和是k. 思路:先发发牢骚,这两天做题是卡到不行哇,前一个题折腾了三天,这个题上午又被卡住,一气之下,中午睡觉,下午去了趟公司,竟然把namespace和cgr ...