题目戳我

\(\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】java生成炫酷验证码,不区分大小写。登陆,发送手机验证码,防止注册机,android开发

    作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985 QQ986945193 微博:http://weibo.com/mcxiaobing 首先给大家看一下 ...

  2. mac:app已损坏,打不开。你应该将它移到废纸篓。

    app已损坏,打不开.你应该将它移到废纸篓. http://bbs.feng.com/read-htm-tid-11230947.html http://www.codesec.net/view/50 ...

  3. Google Kick Start 2020 Round B T4 Wandering Robot

    题意 一个\(n \times m\)的矩形空间,起点是\((1,1)\),终点是\((n,m)\). 假设当前位于\((x,y)\): 如果当前位于最后一行,那么下一步只能走向\((x,y+1)\) ...

  4. 深度学习论文翻译解析(十三):Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks

    论文标题:Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks 标题翻译:基于区域提议(Regi ...

  5. Salesforce LWC学习(二十四) Array.sort 浅谈

    本篇参考:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/sort sal ...

  6. 小程序开发-小程序tabBar不显示的原因分析

    在尝试小程序开发时,tabBar这个是个非常常见的组件,但是今天在进行开发时,设置了TabBarb并没有显示,被这个问题困扰了近半小时,现在将排查问题后所得到的经验记录下来. 首先 如果tabBar不 ...

  7. ZT:通过Find命令找到你要找的东西

    https://os.51cto.com/art/202003/612049.htm find 命令有巨多的选项可以帮助你准确定位你在 Linux 系统上需要寻找的文件.这篇文章讨论了一系列非常有用的 ...

  8. 20190916-01linux文件与目录结构 000 001

    1./bin 是Binary的缩写,这个目录存放着最经常使用的命令 2./sbin s就是Super User的意思,这里存放的是系统管理员使用的系统管理程序 3./home 存放普通用户的主目录,在 ...

  9. 推荐掌握Linux shell中这7种运算命令

    #常见的算术运算符号 .+.-:加减 .*./.%:乘.除.取余 .**:幂运算 .++.--:增加记减少 .!.&&.||:取反,并且,或 .<,<=,>,=> ...

  10. 购书网站前端实现(HTML+CSS+JavaScript)

    购书+阅读静态网页设计与实现 一.主页设计HTML 1.效果展示及实现 2.完整代码 二.主页样式布局CSS 三.空间功能实现Javascript 主要功能 Javascript完整代码: 总结 购书 ...