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. sendmail报错Relaying denied

    配置好sendmail后,使用php的mail()发送邮件,出现 SMTP server response: 550 5.7.1 Relaying denied. IP name lookup fai ...

  2. nexus的安装和简介(2)

    上传jar包到私服 1. 配置settings.xml 需要在客户端即部署dao工程的电脑上配置 maven环境,并修改 settings.xml 文件,配置连接私服的用户和密码 . 此用户名和密码用 ...

  3. [phvia/firman] PHP多进程服务器模型中的惊群

    [ 典型场景 ] 典型的多进程服务器模型是这样的,主进程绑定ip,监听port,fork几个子进程,子进程安装信号处理器,随后轮询资源描述符检查是否可读可写: 子进程的轮询又涉及到 IO复用,acce ...

  4. vue.js插值,插入图片,属性

    <html><head><title>Insert title here</title><script type="text/javas ...

  5. cmake find_package 中,include_directories,target_link_libraries 的值怎么知道?

    拿Sophus库为例: find_package(Sophus REQUIRED) include_directories(${Sophus_INCLUDE_DIRS}) target_link_li ...

  6. Unity之AssetBundle打包

    AssetBundle Resources:表示U3D自动将资源打成一个AssetBundle包,所有放在Resources下的文件夹都会打成一个AssetBundle包,资源非常大,Resource ...

  7. Python开发——基础

    注释 单行注释 # 被注释的内容 多行注释 """ 被注释的内容 """ 解释器路径 #!/usr/bin/env python # 用于L ...

  8. angular模拟web API

    现象:angular Cannot find module 'angular-in-memory-web-api'报错找不动“angular-in-memory-web-api”模块 解决:1.控制台 ...

  9. 解决安装xcode后git使用报错的问题

    一.现象: htmlxdeMacBook-Pro:demo htmlx$ git status Agreeing to the Xcode/iOS license requires admin pri ...

  10. MySQL终章

    视图 什么是视图 是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据 视图的特点 . 视图的列可以来自不同的表,是表的抽象和逻辑意义上建立的新关系. . 视图是由基本表 ...