【雅礼联考DAY02】Revolution
#include<cstdio>
#include<queue>
using namespace std;
const int N = 210 , M = 210000 , INF = 2147483647;
int a[N + 5][N + 5] , b[N + 5][N + 5] , n , m , s , t , ans;
char str[N + 5];
int dep[N * N + 5] , cur[N * N + 5] , h[N * N + 5] , tot = 1;
struct edge{
int to , nxt , v;
}e[M + 5];
int fx[4][2] = {-1 , 0 , 0 , -1 , 1 , 0 , 0 , 1};
inline void add(int x , int y , int v)
{
e[++tot].to = y;
e[tot].nxt = h[x];
e[tot].v = v;
h[x] = tot;
}
inline void Add(int x , int y , int v) {add(x , y , v) , add(y , x , 0);}
inline int id(int x , int y) {return (x - 1) * m + y;}
inline int calc(char ch)
{
if(ch >= '0' && ch <= '9')
return ch - '0';
if(ch >= 'a' && ch <= 'z')
return ch - 'a' + 10;
if(ch >= 'A' && ch <= 'Z')
return ch - 'A' + 36;
}
inline bool pd(int x , int y)
{
if (x <= 0 || y <= 0 || x > n || y > m) return false;
return true;
}
inline int bfs(int s , int t)
{
for(register int i = s; i <= t; i++) dep[i] = 0 , cur[i] = h[i];
queue<int> Q;
dep[s] = 1;
Q.push(s);
while (!Q.empty())
{
int now = Q.front();
Q.pop();
for(register int i = h[now]; i; i = e[i].nxt)
{
int v = e[i].to;
if (e[i].v == 0 || dep[v] != 0) continue;
dep[v] = dep[now] + 1;
Q.push(v);
}
}
return dep[t];
}
inline int dfs(int x , int fa , int mi)
{
if (x == t || mi <= 0) return mi;
int flow = 0;
for(register int i = cur[x]; i; i = e[i].nxt)
{
cur[x] = i;
int v = e[i].to;
if (v == fa || dep[x] + 1 != dep[v] || e[i].v == 0) continue;
int f = dfs(v , x , min(mi , e[i].v));
if (f <= 0) continue;
mi -= f , e[i].v -= f , e[i ^ 1].v += f , flow += f;
if (mi <= 0) break;
}
return flow;
}
inline int dinic(int s , int t)
{
int res = 0;
while (bfs(s , t)) res += dfs(s , 0 , INF);
return res;
}
inline void build()
{
for(register int i = 1; i <= n; i++)
for(register int j = 1; j <= m; j++)
{
int x = id(i , j);
if ((i + j) & 1)
{
Add(3 * x , 3 * x + 1 , b[i][j]);
Add(3 * x + 1 , 3 * x + 2 , a[i][j]);
Add(3 * x + 2 , t , INF);
}
else{
Add(s , 3 * x , INF);
Add(3 * x , 3 * x + 1 , a[i][j]);
Add(3 * x + 1 , 3 * x + 2 , b[i][j]);
for(register int k = 0; k < 4; k++)
{
int xx = i + fx[k][0] , yy = j + fx[k][1];
if (!pd(xx , yy)) continue;
int y = id(xx , yy);
Add(3 * x + 1 , 3 * y , INF);
Add(3 * x + 2 , 3 * y + 1 , INF);
}
}
}
}
int main()
{
// freopen("Revolution.in" , "r" , stdin);
scanf("%d%d" , &n , &m);
t = id(n , m) * 3 + 3;
for(register int i = 1; i <= n; i++)
{
scanf("%s" , str + 1);
for(register int j = 1; j <= m; j++)
a[i][j] = calc(str[j]);
}
for(register int i = 1; i <= n; i++)
{
scanf("%s" , str + 1);
for(register int j = 1; j <= m; j++)
b[i][j] = calc(str[j]) , ans += b[i][j];
}
build();
printf("%d" , ans - dinic(s , t));
}
【雅礼联考DAY02】Revolution的更多相关文章
- 【NOIP2016提高A组模拟8.17】(雅礼联考day1)总结
考的还ok,暴力分很多,但有点意外的错误. 第一题找规律的题目,推了好久.100分 第二题dp,没想到. 第三题树状数组.比赛上打了个分段,准备拿60分,因为时间不够,没有对拍,其中有分段的20分莫名 ...
- 【NOIP2016提高A组模拟8.19】(雅礼联考day2)总结
第一题又有gcd,又有xor,本来想直接弃疗,不过后来想到了个水法: 当两个相邻的数满足条件时,那么他们的倍数也可能满足条件.然后没打,只打了个暴力. 正解就是各种结论,各种定理搞搞. 第二题,想都不 ...
- 【NOIP2016提高A组模拟8.19】(雅礼联考day2)公约数
题目 给定一个正整数,在[1,n]的范围内,求出有多少个无序数对(a,b)满足gcd(a,b)=a xor b. 分析 显然a=b是一定不满足, 我们设\(a>b\), 易得gcd(a,b)&l ...
- 【NOIP2016提高A组模拟8.19】(雅礼联考day2)树上路径
题目 给出一棵树,求出最小的k,使得,且在树中存在路径p,使得k>=S且k<=E.(k为路径p上的边的权值和). 分析 点分治,设当前为x的,求在以x为根的子树中,经过x的路径(包括起点或 ...
- 【NOIP2016提高A组模拟8.17】(雅礼联考day1)Binary
题目 分析 首先每个数对\(2^i\)取模.也就是把每个数的第i位以后删去. 把它们放进树状数组里面. 那么当查询操作, 答案就位于区间\([2^i-x,2^{i-1}-1-x]\)中,直接查询就可以 ...
- 【NOIP2016提高A组模拟8.17】(雅礼联考day1)Value
题目 分析 易证,最优的答案一定是按\(w_i\)从小到大放. 我们考虑dp, 先将w从小到大排个序,再设\(f_{i,j}\)表示当前做到第i个物品,已选择了j个物品的最大值.转移就是\[f_{i, ...
- 【NOIP2016提高A组模拟8.17】(雅礼联考day1)Matrix
题目 分析 假设,我们从\(F_{i,2}\)出发,那么对\(F_{n,n}\)的贡献就是\(某个系数乘以a^{n-i}b^{n-1}r_i\): 同理,如果从\(F_{2,i}\)出发,那么对\(F ...
- [JZOJ4759] 【雅礼联考GDOI2017模拟9.4】石子游戏
题目 描述 题目大意 在一棵树上,每个节点都有些石子. 每次将mmm颗石子往上移,移到根节点就不能移了. 双方轮流操作,问先手声还是后手胜. 有三种操作: 1. 询问以某个节点为根的答案. 2. 改变 ...
- 雅礼集训1-9day爆零记
雅礼集训1-9day爆零记 先膜一下虐爆我的JEFF巨佬 Day0 我也不知道我要去干嘛,就不想搞文化科 (文化太辣鸡了.jpg) 听李总说可以去看(羡慕)各路大佬谈笑风声,我就报一个名吧,没想到还真 ...
- NOIp2018集训test-10-6/test-10-7 (联考五day1/day2)
昨天考完月考,明天初赛,dcoi2017级今天终于开始停课准备noip了,大概没有比本弱校停课更晚的学校了吧.本来就够菜了,怕是要凉透哦. DAY1 T1石头剪刀布 据说爆搜随便做,但是我觉得我的O( ...
随机推荐
- SUPERVISOR监控tomcat配置文件
Supervisor安装教程参考:https://www.cnblogs.com/brad93/p/16639953.html tomcat安装教程参考:https://www.cnblogs.com ...
- 10-排序6 Sort with Swap(0, i) (25point(s))
10-排序6 Sort with Swap(0, i) (25point(s)) Given any permutation of the numbers {0, 1, 2,..., N−1}, it ...
- SourceGenerator 使用姿势(1):生成代理类,实现简单的AOP
SourceGenerator 已经出来很久了,也一直在关注.之前观摩大佬 xljiulang 的 WebApiClient 使用 SourceGenerator 生成接口代理类,深受启发,准备拿过来 ...
- 如何搭建自己的CICD流水线,实现自动编译部署功能?
之前使用过GitLab的CICD流水线,有多种环境,点击即可编译部署,十分的方便. 如何在个人项目中搭建自己的CICD流水线,实现push代码后自动编译并部署呢?这里使用到阿里云 云效DevOps,阿 ...
- 用openpyxl创建工作簿和工作表
import osimport openpyxl #设置默认路径os.chdir(r'D:/openpyxl/') #创建工作簿变量 wb = openpyxl.Workbook() #创建工作表变量 ...
- Kubernetes(k8s)存储管理之数据卷volumes(四):持久卷Persistent Volume
目录 一.系统环境 二.前言 三.持久卷(Persistent Volume) 3.1 持久卷(Persistent Volume)概览 3.2 持久卷和持久卷申领的生命周期 3.3 持久卷的类型 3 ...
- 链接脚本中 AT> 的作用
缘由 这两天在梳理芯片的启动流程, 研究到了链接脚本(样本为stm32cube ide 中的 stm32f407 的 flash 链接脚本). 产生了一个疑问AT>是什么? 答案 AT>就 ...
- python各种小知识
一.三元表达式 1. 简化步骤1:代码简单且只有一行,可以直接在冒号后面编写 三元表达式: 数据值1+ if 条件+else 数据值2条件成立则使用数据值1,条件不成立则使用数据值2: 当结果是二选一 ...
- 虚假新闻检测(CADM)《Unsupervised Domain Adaptation for COVID-19 Information Service with Contrastive Adversarial Domain Mixup》
论文信息 论文标题:Unsupervised Domain Adaptation for COVID-19 Information Service with Contrastive Adversari ...
- Codeforces Hello 2023 CF 1779 A~F 题解
点我看题 A. Hall of Fame 先把不用操作就合法的情况判掉.然后发现交换LL,RR,RL都是没用的,只有交换LR是有用的,这样可以照亮相邻的两个位置.所以我们就是要找到一个位置i,满足\( ...