http://acm.whu.edu.cn/learn/problem/detail?problem_id=1124

题目大意:有N支球队,你们是第N支。每个队伍已经有一些分数了,接下来还有M场比赛。每场比赛有两支参赛队伍,赢得队得2分,输的队不得分,平局各得一分。现在你可以操控所有比赛的胜负。问你最后你们队是否能成为第一名(分数严格大于其他所有队分数)

分析:第一道用满流来解决问题的题。首先明确我们能做两种伎俩。一是我们参与的比赛肯定选我们赢。然后我们不参与的比赛就通过压制分数高的队让他们分数没有我们高,这个trick比较难不是贪心能解决的。首先对于有N参加的比赛,肯定是赢了最好,暂时先不考虑其他的比赛,这是如果各队的积分有大于或等于第N队的,那么肯定是输出NO的。接下来考虑其他的比赛,对于任意队伍i而言,得分是不等等于或者超过score[N]的,因此可以将i和汇点连一条容量为score[N]-score[i]-1的边,由于比赛的总积分是2,自然谁参加哪场比赛就对应连若干容量为2的边即可,这样做最大流,如果最后能够满流就说明所有的比赛都能安排妥当。

建边方案:

1)将源点拆成若干个,分别对应每场比赛,如a和b比一场,则S--2-->S',S'--2-->a,S'--2-->b;

2)不拆点,若a和b比一场,则S--2-->a,a--2(注意不能是inf)-->b;(反例:如a和b赛,b和c赛,则存在a:b:c=0:0:4的结果。)

贴代码(1):

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
const int maxn=,maxm=,inf=0x7fffffff;
int n,m,a,b,s,t,maxflow,tot=,flag,p,score[maxn],head[maxn],cur[maxn],h[maxn];
queue<int> q;
struct node{
int go,next,v;
}e[maxm];
inline int read(){
int x=;char ch=getchar();
while (ch>'' || ch<'')ch=getchar();
while (ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x;
}
inline void addedge(int x,int y,int v){
e[++tot]=(node){y,head[x],v};head[x]=tot;
e[++tot]=(node){x,head[y],};head[y]=tot;
}
bool bfs(){
for (int i=;i<=t;i++) h[i]=-;
q.push(s);h[s]=;
while (!q.empty()){
int x=q.front();q.pop();
for (int i=head[x];i;i=e[i].next){
if (e[i].v && h[e[i].go]==-){
q.push(e[i].go);
h[e[i].go]=h[x]+;
}
}
}
return h[t]!=-;
}
int dfs(int x,int f){
if (x==t) return f;
int tmp,used=;
for (int i=cur[x];i;i=e[i].next){
if (e[i].v && h[e[i].go]==h[x]+){
tmp=dfs(e[i].go,min(e[i].v,f-used));
e[i].v-=tmp;if (e[i].v) cur[x]=i;
e[i^].v+=tmp;used+=tmp;
if (used==f) return f;
}
}
if (!used) h[x]=-;
return used;
}
void dinic(){
maxflow=;
while (bfs()){
for (int i=;i<=t;i++) cur[i]=head[i];
maxflow+=dfs(s,inf);
}
}
int main(){
while (scanf("%d%d",&n,&m)!=EOF){
for (int i=;i<=t;i++) head[i]=;
tot=;s=n+;t=;p=;flag=;
for (int i=;i<=n;i++) score[i]=read();
for (int i=;i<=m;i++){
a=read();b=read();
if (a==n || b==n) score[n]+=;
else{
p+=;
addedge(s,i+s,);
addedge(i+s,a,);
addedge(i+s,b,);
}
}
for (int i=;i<n;i++){
if (score[i]>=score[n]) {flag=;printf("NO\n");break;}
else if (score[n]--score[i]) addedge(i,t,score[n]--score[i]);
}
if (flag) continue;
dinic();
if (maxflow==p) printf("YES\n");
else printf("NO\n");
}
return ;
}

贴代码(2):

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
const int maxn=,maxm=,inf=0x7fffffff;
int n,m,a,b,s,t,maxflow,tot=,flag,p,score[maxn],head[maxn],cur[maxn],h[maxn];
queue<int> q;
struct node{
int go,next,v;
}e[maxm];
inline int read(){
int x=;char ch=getchar();
while (ch>'' || ch<'')ch=getchar();
while (ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x;
}
inline void addedge(int x,int y,int v){
e[++tot]=(node){y,head[x],v};head[x]=tot;
e[++tot]=(node){x,head[y],};head[y]=tot;
}
bool bfs(){
for (int i=;i<=t;i++) h[i]=-;
q.push(s);h[s]=;
while (!q.empty()){
int x=q.front();q.pop();
for (int i=head[x];i;i=e[i].next){
if (e[i].v && h[e[i].go]==-){
q.push(e[i].go);
h[e[i].go]=h[x]+;
}
}
}
return h[t]!=-;
}
int dfs(int x,int f){
if (x==t) return f;
int tmp,used=;
for (int i=cur[x];i;i=e[i].next){
if (e[i].v && h[e[i].go]==h[x]+){
tmp=dfs(e[i].go,min(e[i].v,f-used));
e[i].v-=tmp;if (e[i].v) cur[x]=i;
e[i^].v+=tmp;used+=tmp;
if (used==f) return f;
}
}
if (!used) h[x]=-;
return used;
}
void dinic(){
maxflow=;
while (bfs()){
for (int i=;i<=t;i++) cur[i]=head[i];
maxflow+=dfs(s,inf);
}
}
int main(){
while (scanf("%d%d",&n,&m)!=EOF){
for (int i=;i<=t;i++) head[i]=;
tot=;s=n+;t=;p=;flag=;
for (int i=;i<=n;i++) score[i]=read();
for (int i=;i<=m;i++){
a=read();b=read();
if (a==n || b==n) score[n]+=;
else{
p+=;
addedge(s,a,);
addedge(a,b,);
}
}
for (int i=;i<n;i++){
if (score[i]>=score[n]) {flag=;printf("NO\n");break;}
else if (score[n]--score[i]) addedge(i,t,score[n]--score[i]);
}
if (flag) continue;
dinic();
if (maxflow==p) printf("YES\n");
else printf("NO\n");
}
return ;
}

WHU1124 Football Match的更多相关文章

  1. cf493A Vasya and Football

    A. Vasya and Football time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  2. A. Vasya and Football

    A. Vasya and Football time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. Elasticsearch Query DSL 整理总结(二)—— 要搞懂 Match Query,看这篇就够了

    目录 引言 构建示例 match operator 参数 analyzer lenient 参数 Fuzziness fuzzniess 参数 什么是模糊搜索? Levenshtein Edit Di ...

  4. Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟

    A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has starte ...

  5. POJ Football Game 【NIMK博弈 && Bash 博弈】

    Football Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 451   Accepted: 178 Descr ...

  6. Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力水题

    A. Vasya and Football time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  7. zoj 3356 Football Gambling II【枚举+精度问题】

    题目: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3356 http://acm.hust.edu.cn/vjudge/ ...

  8. Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力

    A. Vasya and Football   Vasya has started watching football games. He has learned that for some foul ...

  9. C - Football

    Problem description Petya loves football very much. One day, as he was watching a football match, he ...

随机推荐

  1. 保存xml报错 'UTF_8' is not a supported encoding name

    ArgumentException: 'UTF_8' is not a supported encoding name. For information on defining a custom en ...

  2. office 安装

    在 gaobo百度云下载安装包. 自定义安装,并在自定义界面选择安装路径. 破解:

  3. python入门(八):文件操作

    1.数据的保存: 1) 内存:常用的变量都是在内存里面的 缺点:关机或进程死掉数据丢失 解决方法:将数据保存至文件中 2 )文件:文本内容.二进制的文件内容 3 )数据库:保存    2.读文件: 1 ...

  4. react-native 新手爬坑经历(unable to load script from assets 和could not connect to development server.)

    按照https://reactnative.cn/docs/0.51/getting-started.html教程新建的项目 react-native init AwesomeProject cd A ...

  5. ubuntu下搭建svn服务器

    [ubuntu下搭建svn服务器] 1.创建目录 mkdir ~/svn/repository/ 2.创建仓库 svnadmin create repository 3.进入 repository/c ...

  6. MYSQL分组合并函数

    MySQL中group_concat函数完整的语法如下:group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔符' ...

  7. 语义分割之Dual Attention Network for Scene Segmentation

    Dual Attention Network for Scene Segmentation 在本文中,我们通过 基于自我约束机制捕获丰富的上下文依赖关系来解决场景分割任务.       与之前通过多尺 ...

  8. Es6(Symbol,set,map,filter)

    首先再讲这几个新东西之前,先说一个Es6中新出的扩展运算符(...) 1.展开运算符,就是把东西展开,可以用在array和object上 比如: let a=[,] let b=[,...a,]//[ ...

  9. java基础 ----- 选择结构

    ---------    流程控制 ------     流程图 ------   基本的  if  选择结构 import java.util.Scanner; public class GetPr ...

  10. journalctl 清理journal日志

    在CentOS 7开始使用的systemd使用了journal日志,这个日志的管理方式和以往使用syslog的方式不同,可以通过管理工具维护. 使用df -h检查磁盘文件,可以看到/run目录下有日志 ...