题目戳我

\(\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的更多相关文章

  1. 题解 CF1426E - Rock, Paper, Scissors

    一眼题. 第一问很简单吧,就是每个 \(\tt Alice\) 能赢的都尽量让他赢. 第二问很简单吧,就是让 \(\tt Alice\) 输的或平局的尽量多,于是跑个网络最大流.\(1 - 3\) 的 ...

  2. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)

    2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...

  3. SDUT 3568 Rock Paper Scissors 状压统计

    就是改成把一个字符串改成三进制状压,然后分成前5位,后5位统计, 然后直接统计 f[i][j][k]代表,后5局状压为k的,前5局比和j状态比输了5局的有多少个人 复杂度是O(T*30000*25*m ...

  4. FFT(Rock Paper Scissors Gym - 101667H)

    题目链接:https://vjudge.net/problem/Gym-101667H 题目大意:首先给你两个字符串,R代表石头,P代表布,S代表剪刀,第一个字符串代表第一个人每一次出的类型,第二个字 ...

  5. Gym - 101667H - Rock Paper Scissors FFT 求区间相同个数

    Gym - 101667H:https://vjudge.net/problem/Gym-101667H 参考:https://blog.csdn.net/weixin_37517391/articl ...

  6. Gym101667 H. Rock Paper Scissors

    将第二个字符串改成能赢对方时对方的字符并倒序后,字符串匹配就是卷积的过程. 那么就枚举字符做三次卷积即可. #include <bits/stdc++.h> struct Complex ...

  7. HDOJ(HDU) 2164 Rock, Paper, or Scissors?

    Problem Description Rock, Paper, Scissors is a two player game, where each player simultaneously cho ...

  8. HDU 2164 Rock, Paper, or Scissors?

    http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two pl ...

  9. 1090-Rock, Paper, Scissors

    描述 Rock, Paper, Scissors is a classic hand game for two people. Each participant holds out either a ...

随机推荐

  1. 【Android】安卓开发之activity如何传值到fragment,activity与fragment传值

    作者:程序员小冰,GitHub主页:https://github.com/QQ986945193 新浪微博:http://weibo.com/mcxiaobing 大家知道,我们利用activity使 ...

  2. 解决warning MSB8012:问题

    问题描述: C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(990,5): warning M ...

  3. Unity坑之 传递默认枚举类型参数

    今天在编写一个通用模块的时候,遇到一个奇怪的问题,vs编译时没有任何问题,但是轮到unity编译时,却报错: error CS0103: The name `PrintInt' does not ex ...

  4. 如何设置Tomact的标题,运行Tomcat显示为自己程序的命名

    当我们使用Tomcat部署好一个web系统后,在窗口处默认会显示Tomcat名字.但如果我们用多个Tomcat部署时,则需要区分这些窗口,这是需要修改Tomact的配置,来设置一个我们需要显示的标题. ...

  5. 洛谷P1712 [NOI2016]区间 尺取法+线段树+离散化

    洛谷P1712 [NOI2016]区间 noi2016第一题(大概是签到题吧,可我还是不会) 链接在这里 题面可以看链接: 先看题意 这么大的l,r,先来个离散化 很容易,我们可以想到一个结论 假设一 ...

  6. 反向代理搭建隧道,服务器系统为Ubuntu18.04

    该文章参考了实验室师兄写的教程,并记录了自己在实操过程中的坑. 1.内网机器配置 假设现在有一台公用服务器和一台内网服务器,现在想通过反向代理的方式来访问内网服务器.假设公用服务器为A,内网服务器为B ...

  7. 《C语言进阶剖析》课程目录

    <C语言进阶剖析>学习笔记                                                         本文总结自狄泰软件学院唐佐林老师的<C语言 ...

  8. [LeetCode] 17. 电话号码的字母组合(回溯)

    题目 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:"23" 输出:[& ...

  9. [LeetCode]55. 跳跃游戏(贪心)

    题目 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] 输出: tr ...

  10. CentOS7使用PackageCloud安装RabbitMQ

    环境:CentOS Linux release 7.6.1810 (Core) RabbitMQ:3.7.17Erlang: 22.0.7 使用PackageCloud安装RabbitMQ是最简单的安 ...