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. Android Spinner 设置setOnItemSelectedListener时,竟会默认触发一次事件!

    当然是关闭这坑货了: //禁止OnItemSelectedListener默认自动调用一次 spinnerDutyPerson.setSelection(0, true); //放到TagContai ...

  2. Spring再接触 模拟Spring

    项目分层: 1.最土的方法是直接写到main中去 2.分出model层 2.如下 4.在抽象一个对数据库的访问层(跨数据库实现) 面向抽象编程 User.java package com.bjsxt. ...

  3. 无法在正在进行内容生成时调用 StartAt

    刚遇到一个奇怪的问题,用户点击创建销售订单的时候,弹出个 无法在正在进行内容生成时调用 StartAt,查看详细报错. ystem.InvalidOperationException: 无法在正在进行 ...

  4. 常用的OO设计原则

    常用的OO设计原则: 1 封装变化:找出应用中可能需要变化之处,把它们独立出来,不要和哪些不需要变化的代码混在一起. 2 针对接口编程,而不是针对实现编程. 3 多用组合,少用继承. 4 松耦合:为了 ...

  5. 如何关闭wps热点,如何关闭wpscenter,如何关闭我的wps

    用wps已经快十年了,最开始的时候速度快,非常好用,甩office几条街,但最近这几年随着wps胃口越来越大,各种在线功能不断推出,植入广告越来越多,逐渐让人失去欢喜. 通过各种网帖的经验,我把网上流 ...

  6. html 中使用 iconfont、fontAwesome

    在HTML中尽量使用iconfont 替代图片有很多好处,而且方便,可以设置大小.颜色 等 可以用于字体的设置. 一.使用iconfont 1.打开iconfont 官网 iconfont.cn. 2 ...

  7. 2018面向对象程序设计(Java)第18周学习指导及要求

    2018面向对象程序设计(Java) 第18周学习指导及要求(2018.12.27-2018.12.30)   学习目标 (1) 综合掌握java基本程序结构: (2) 综合掌握java面向对象程序设 ...

  8. Python设计模式 - UML - 用例图(Use Case Diagram)

    简介 用例图主要是从用户的角度出发对软件产品的功能及执行者进行描述的. 用例图是从需求分析到软件交付的第一步,图示化展示参与者与参与者之间.参与者与用例之间.用例与用例之间的关系,帮助开发人员更好的理 ...

  9. http://ctf.bugku.com/challenges#love:bugku--love

      做了一道逆向题目,主要关联到base64编码的知识点.下面做一分析. 题目如下:   通过测试,可知它没有加壳.尝试使用IDA进行分析. 1.IDA分析文件   打开文件后,按[shift+F12 ...

  10. [leetcode]6. ZigZag Conversion字符串Z形排列

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...