WHU1124 Football Match
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的更多相关文章
- cf493A Vasya and Football
A. Vasya and Football time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- A. Vasya and Football
A. Vasya and Football time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Elasticsearch Query DSL 整理总结(二)—— 要搞懂 Match Query,看这篇就够了
目录 引言 构建示例 match operator 参数 analyzer lenient 参数 Fuzziness fuzzniess 参数 什么是模糊搜索? Levenshtein Edit Di ...
- Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟
A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has starte ...
- POJ Football Game 【NIMK博弈 && Bash 博弈】
Football Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 451 Accepted: 178 Descr ...
- 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 ...
- zoj 3356 Football Gambling II【枚举+精度问题】
题目: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3356 http://acm.hust.edu.cn/vjudge/ ...
- 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 ...
- C - Football
Problem description Petya loves football very much. One day, as he was watching a football match, he ...
随机推荐
- 20165304 2017-2018-2《Java程序设计》学习总结
20165304 2017-2018-2<Java程序设计>学习总结 一.每周作业及实验报告链接汇总 1.我期望的师生关系 2.20165304学习基础和C语言基础调查 3.linux系统 ...
- ide调试
F8: 程序向下执行一行(如果当前行有方法调用,这个方法将被执行完毕返回,然后到下一行) F7: 程序向下执行一行.如果该行有自定义方法,则运行进入自定义方法(不会进入官方类库的方法) Alt + ...
- 云笔记项目-Java反射知识学习
在云笔记项目中,补充了部分反射的知识,反射这一部分基础知识非常重要,前面学习的框架Spring和MyBatis读取xml配置文件创建对象,以及JDBC加载驱动等都用了反射,但只知道有这个东西,具体不知 ...
- 动态加载、移除js、css
本文简单介绍动态加载.移除.替换js/css文件 .有时候我们在写前端的时候,会有出现需要动态加载一些东如css js 这样能减轻用户加载负担,从而提高响应效率.下面贴出代码.//JS写法 <s ...
- jq怎么给图片绑定上传文件按钮
html代码 <img src="/img/zhengmian.png" alt="" class="file1"> <i ...
- centos查看系统版本
显示系统版本 cat /etc/redhat-release cat /proc/version uname -a 查看位数 file /bin/ls
- python爬虫之urllib
#coding=utf-8 #urllib操作类 import time import urllib.request import urllib.parse from urllib.error imp ...
- webserver
1. 控制台,浏览器输入http://localhost:8080/ using System; using System.Collections; using System.IO; using Sy ...
- linux debian 9 / centos 7配置postgresSQL数据库
#读者注意:本文可以选择不看解释,直接执行每段的0中的代码 (〇):一些概念(可以跳过直接使用(一)0的代码) 1. 客户端:psql.postgreSQL的命令行客户端程序,在终端输入psql进入p ...
- 数据库-mysql语句-查-WEB服务器
(1)MySQL中的查询 (2)WEB服务器 Order: 订单.排序 Set:设置.集合 Table:表.桌子 1.MySQL中的简单查询 —— 查询结果的排序 示例:查询出所有员工信息,要求按工 ...