【题解】CF1426E Rock, Paper, Scissors
\(\text{Solution:}\)
考虑第二问,赢的局数最小,即输和平的局数最多。
考虑网络流,\(1,2,3\)表示\(Alice\)选择的三种可能性,\(4,5,6\)同理。
它们像源点和汇点连的是局数为容量的边,然后对于能和它平的和输的连边,边权为\(inf\),因为源点和汇点已经限制了流量,这里直接\(inf\)即可。
第一问就是三个数的三个最小值相加。
#include<bits/stdc++.h>
using namespace std;
int n,a[4],b[4],S=0,T=100;
int ans1=1e9+1,ans2=1e9+1;
const int MAXN=5000;
const int inf=(1<<30);
int head[MAXN],tot=1,cur[MAXN],dep[MAXN];
struct E{int nxt,to,flow;}e[MAXN];
inline void add(int x,int y,int w){
e[++tot].to=y;e[tot].nxt=head[x];e[tot].flow=w;head[x]=tot;
e[++tot].to=x;e[tot].nxt=head[y];e[tot].flow=0;head[y]=tot;
}
bool bfs(int s,int t){
memset(dep,0,sizeof dep);
cur[s]=head[s];dep[s]=1;
queue<int>q;q.push(s);
while(!q.empty()){
s=q.front();q.pop();
for(int i=head[s];i;i=e[i].nxt){
int j=e[i].to;
if(!dep[j]&&e[i].flow){
dep[j]=dep[s]+1;
cur[j]=head[j];
if(j==t)return true;
q.push(j);
}
}
}
return false;
}
int dfs(int s,int flow,int t){
if(flow<=0||s==t)return flow;
int rest=flow;
for(int i=cur[s];i;i=e[i].nxt){
int j=e[i].to;
if(dep[j]==dep[s]+1&&e[i].flow){
int tmp=dfs(j,min(e[i].flow,rest),t);
if(tmp<=0)dep[j]=0;
rest-=tmp;e[i].flow-=tmp;e[i^1].flow+=tmp;
if(rest<=0)break;
}
}
return flow-rest;
}
int dinic(int s,int t){
int ans=0;
for(;bfs(s,t);)ans+=dfs(s,inf,t);
return ans;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=3;++i)scanf("%d",&a[i]),add(S,i,a[i]);
for(int i=1;i<=3;++i)scanf("%d",&b[i]),add(i+3,T,b[i]);
for(int i=1;i<=3;++i)add(i,i+3,inf);
for(int i=1;i<=3;++i)add(i,(i+1)%3+4,inf);
ans1=min(a[1],b[2])+min(a[2],b[3])+min(a[3],b[1]);
ans2=dinic(S,T);
swap(ans1,ans2);
cout<<n-ans1<<" "<<ans2<<endl;
return 0;
}
【题解】CF1426E Rock, Paper, Scissors的更多相关文章
- 题解 CF1426E - Rock, Paper, Scissors
一眼题. 第一问很简单吧,就是每个 \(\tt Alice\) 能赢的都尽量让他赢. 第二问很简单吧,就是让 \(\tt Alice\) 输的或平局的尽量多,于是跑个网络最大流.\(1 - 3\) 的 ...
- 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)
2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...
- SDUT 3568 Rock Paper Scissors 状压统计
就是改成把一个字符串改成三进制状压,然后分成前5位,后5位统计, 然后直接统计 f[i][j][k]代表,后5局状压为k的,前5局比和j状态比输了5局的有多少个人 复杂度是O(T*30000*25*m ...
- FFT(Rock Paper Scissors Gym - 101667H)
题目链接:https://vjudge.net/problem/Gym-101667H 题目大意:首先给你两个字符串,R代表石头,P代表布,S代表剪刀,第一个字符串代表第一个人每一次出的类型,第二个字 ...
- Gym - 101667H - Rock Paper Scissors FFT 求区间相同个数
Gym - 101667H:https://vjudge.net/problem/Gym-101667H 参考:https://blog.csdn.net/weixin_37517391/articl ...
- Gym101667 H. Rock Paper Scissors
将第二个字符串改成能赢对方时对方的字符并倒序后,字符串匹配就是卷积的过程. 那么就枚举字符做三次卷积即可. #include <bits/stdc++.h> struct Complex ...
- HDOJ(HDU) 2164 Rock, Paper, or Scissors?
Problem Description Rock, Paper, Scissors is a two player game, where each player simultaneously cho ...
- HDU 2164 Rock, Paper, or Scissors?
http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two pl ...
- 1090-Rock, Paper, Scissors
描述 Rock, Paper, Scissors is a classic hand game for two people. Each participant holds out either a ...
随机推荐
- 轻轻松松学CSS:background
background是复合属性,它可以分解为8个属性,其中5个属于CSS,另外3个属于CSS3一.CSS 1.background-color:背景色 2.background-image ...
- unity3d插入android有米广告
有米官网:http://www.youmi.net/register?r=MTI0MDg= 国内的广告,我觉得万普和有米还不错,我也只试了这两个,其他的都是看评价的,呵呵~~~首先我们去有米官网注册一 ...
- 【HttpRunner v3.x】笔记 ——3. 录制生成测试用例
在正式手动编写case之前,我们可以先来熟悉下httprunner的录制生成用例功能. 用postman的童鞋都知道,里面有个功能可以将接口转换成代码,可以直接copy过来使用,提升case编写效率. ...
- VS提交码云权限问题
提交代码时出现Git failed with a fatal error. Authentication failed的问题. 如果没有像当前代码库提交过代码(所有项目),那么提交时会提示输入账号密码 ...
- Activiti7 流程部署
首先先绘制一个流程图 创建bpmn文件 然后绘制好节点 然后修改节点信息 指定负责人 点击背景,修改ID和名称 保存 然后重命名成xml 使用diagram打开 导出png 然后包xml改回bpmn ...
- 20190923-02Linux文件目录类 000 010
pwd 显示当前工作目录的绝对路径 pwd:print working directory 打印工作目录 1.基本语法 pwd (功能描述:显示当前工作目录的绝对路径) 2.案例实操 (1)显示当前工 ...
- AutoGenerator自动生成代码
程序猿学社: https://blog.csdn.net/qq_16855077/article/details/105316295
- pytest封神之路第二步 132个命令行参数用法
在Shell执行pytest -h可以看到pytest的命令行参数有这10大类,共132个 序号 类别 中文名 包含命令行参数数量 1 positional arguments 形参 1 2 gene ...
- 再深入一点|binlog和relay-log到底长啥样?
上一篇mysql面试的文章之后收到不少朋友的意见,希望深入讲讲复制.日志的格式这些,今天,我们就来深挖一下mysql的复制机制到底有哪一些,以及binlog和relay-log的结构到底是什么样子的. ...
- 吴恩达《深度学习》-第二门课 (Improving Deep Neural Networks:Hyperparameter tuning, Regularization and Optimization)-第一周:深度学习的实践层面 (Practical aspects of Deep Learning) -课程笔记
第一周:深度学习的实践层面 (Practical aspects of Deep Learning) 1.1 训练,验证,测试集(Train / Dev / Test sets) 创建新应用的过程中, ...