Playoff

时间限制: 5 Sec  内存限制: 128 MB
提交: 56  解决: 13
[提交] [状态] [讨论版] [命题人:admin]

题目描述

The Minato Mirai Football Association hosts its annual championship as a single round-robin tournament, in which each team plays a single match against all the others. Unlike many other round-robin tournaments of football, matches never result in a draw in this tournament. When the regular time match is a tie, overtime is played, and, when it is a tie again, a penalty shootout is played to decide the winner.
If two or more teams won the most number of matches in the round-robin, a playoff is conducted among them to decide the champion. However, if the number of teams is an odd number, it is possible that all the teams may have the same number of wins and losses, in which case all the teams participate in the playoff, called a "full playoff" here.
Now, some of the tournament matches have already been played and we know their results. Whether or not a full playoff will be required may depend on the results of the remaining matches. Write a program that computes the number of win/loss combination patterns of the remaining matches that lead to a full playoff.
The first datatset of the Sample Input represents the results of the first three matches in a round-robin tournament of five teams, shown in the following table. In the table, gray cells indicate the matches not played yet.

In this case, all the teams win the same number of matches with only two win/loss combination patterns of the remaining matches, which lead to a full playoff, as shown below. In the two tables, the differences are indicated in light yellow.

输入

The input consists of multiple datasets, each in the following format.
n
m
x1 y1 
... 
xm ym 
n is an odd integer, 3, 5, 7, or 9, indicating the number of teams participating in the tournament. m is a positive integer less than n(n−1)/2, which is the number of matches already finished. xi and yi give the result of the i-th match that has already taken place, indicating that team xi defeated team yi. Each of xi and yi is an integer 1 through n which indicates the team number. No team plays against itself, that is, for any i, xi ≠ yi. The match result of the same team pair appears at most once. That is, if i ≠ j, then (xi,yi) ≠ (xj,yj) and (xi,yi) ≠ (yj,xj) hold.

The end of the input is indicated by a line containing a zero. The number of datasets does not exceed 100.

输出

For each dataset, output a single line containing one integer which indicates the number of possible future win/loss patterns that a full playoff will be required.

样例输入

5
3
3 2
4 1
5 1
3
1
1 2
3
2
1 2
3 2
5
4
4 1
4 2
5 1
5 2
5
3
4 1
4 2
5 1
5
4
3 2
4 1
5 1
5 2
9
11
6 1
6 4
7 2
7 3
7 4
8 2
8 3
8 4
9 1
9 3
9 5
9
10
6 1
6 4
7 2
7 3
7 4
8 2
8 3
8 4
9 1
9 3
5
6
4 3
2 1
5 1
2 4
1 3
2 3
9
1
1 2
0

样例输出

2
1
0
0
1
0
0
16
0
1615040

[吐槽]:    做题的时候 UPC 没有提交标程 ,所以 显示的  时间限制是 1s,.....  推出要用DFS,但是 感觉 复杂度要超的感觉,

1s 内 跑不完啊,   果然 赛后  , 显示 时间 5s / / QAQ/

[题意]:  给定  n 个人 (奇数)  比赛 ,   已知 m 个  比赛 状态,  现在 求  使得 所有人 的 输赢 次数 一致,  的比赛填法.

说白了就是 把  win 和 lose 填入表格,  x -y  是 对应的,  使每个人的 win  的次数 和 lose 的次数 是一样的.

[思路]

dfs 呗,  3,5,9,  每个人 最终一定是 1,2,4

然后 安装 行 扫描,  行结束扫描 列,

相当于 dfs 枚举了,  暴力 -- -

注意 自己 和自己 不能打

注意:  刚刚UPC 又 改时间限制了, 卡在2s.   然后 3s  挂掉了...    无Fuck言,..

时间 : 3000ms

[代码]


#include <bits/stdc++.h>
#include <stdio.h>#define rep(i,a,n) for(int i = a ;i <=n;i++)
#define per(i,a,n) for(int i =n;i>=a;i--)typedef long long ll;
using namespace std;
const int maxn =1e5+10;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;int mp[10][10];
int win[10];
int t,n,m ;
int ans ;
void dfs(int x,int y)
{if( x== n && y == n){ans ++;return ;}if( y == n ){x ++;y = 1;}if( x == y || mp[x][y] !=0) // itself or has been it dfs(x,y+1);else{if( win[x] < t){mp[x][y] = 1;mp[y][x] = -1;win[x] ++;dfs(x,y+1);mp[x][y] = 0;mp[y][x] = 0;win[x]--;}if( win[y] < t){mp[x][y] = -1;mp[y][x] = 1;win[y] ++;dfs(x,y+1);mp[x][y] = 0;mp[y][x] = 0;win[y]--;  }}
}
int main()
{while(~scanf("%d %d",&n,&m)){if(n == 0) break;memset(mp,0,sizeof(mp));memset(win,0,sizeof(win));int x,y;ans = 0;for(int i =1; i<=m;i++){scanf("%d %d",&x,&y);mp[x][y] = 1;mp[y][x] = -1;win[x] ++;}int flag = 0;t = (n-1)/2;rep(i,1,n){if(win[i] > t ){printf("0\n");flag = 1;break;}}if( flag == 1)continue;dfs(1,1);printf("%d\n",ans);}return 0;
}

修改算法后,  时间 260ms

既然是对称的 , 那么  只扫 三角形就可以了, 扫一半,   增加一个lose  数组,   用mp  标记.

代码:


#include <bits/stdc++.h>
#include <stdio.h>#define rep(i,a,n) for(int i = a ;i <=n;i++)
#define per(i,a,n) for(int i =n;i>=a;i--)typedef long long ll;
using namespace std;
const int maxn =1e5+10;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
int mp[10][10];
int win[10];
int lose[10];
int t,n,m ;
int ans ;
void dfs(int x,int y)
{if( x == n ){ans ++;return ;}if( y == x ){x ++;y = 1;}if( mp[x][y] ){dfs(x,y+1);}else{if( win[x] < t && lose[y] < t ){win[x] ++;lose[y]++; dfs(x,y+1);win[x]--;lose[y]--;}if( win[y] < t && lose[x] < t){win[y] ++;lose[x] ++;dfs(x,y+1);win[y]--; lose[x]--;}     }}
int main()
{while(~scanf("%d %d",&n,&m)){if(n == 0) break;memset(win,0,sizeof(win));memset(lose,0,sizeof(lose));memset(mp,0,sizeof(mp));int x,y;ans = 0;for(int i =1; i<=m;i++){scanf("%d %d",&x,&y);mp[x][y] = 1;mp[y][x] = 1;win[x] ++;lose[y]++;}int flag = 0;t = (n-1)/2;rep(i,1,n){if(win[i] > t || lose[i] > t ){printf("0\n");flag = 1;break;}}if( flag == 1)continue;dfs(2,1);printf("%d\n",ans);}return 0;
}

@UPC8377 @ACM-ICPC-2018-ASIA YOKAHAMA REGIONAL D: Playoff (DFS)相关推荐

  1. UVA1342 That Nice Euler Circuit(ACM - ICPC 2004 Asia - Shanghai)(计算几何、欧拉定理)

    整理的算法模板合集: ACM模板 欧拉定理:设平面图的顶点数.边数和面数分别为V,E,F,则V+F-E=2. #include<bits/stdc++.h> using namespace ...

  2. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 【bfs + 记忆化搜索 + 剪枝】 AC 代码

    ACM 北京区域赛 bfs+剪枝+ms 第一个一遍过的题目,基本没有看题解 记忆搜索当中,注意初始化成一个特殊值:而在访问之后,每个点就会有一个不同于INF(或者 -1等特殊标记)的值 先到先得,适者 ...

  3. ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)A ASCII Area

    A: 给你一个矩阵求'/' 和 '\' 围成的图形,简单签到题,有一些细节要考虑. 题解:一行一行的跑,遇到'/'和'\' 就加0.5, 在面积里面的'.' 就加1.用一个flag来判断是否在围住的图 ...

  4. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 Tomb Raider(map+二进制枚举)

    #1829 : Tomb Raider 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Lara Croft, the fiercely independent daugh ...

  5. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 80 Days(双向队列+尺取法)

    #1831 : 80 Days 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 80 Days is an interesting game based on Jules ...

  6. ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)G GCD Guessing Game

    G: 要你去才Paul的年龄,Paul的年龄在1~n之间,你每猜一个Paul会告诉你,你猜的这个数和他年龄的gcd,问在最坏情况下最少要猜多少次. 题解: 什么是最坏情况,我们直到如果他的年龄是1的话 ...

  7. ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)B Binary Encoding

    B: 现在有一种新的2进制表示法,要你求出0~m-1的每个数的表示. 规则如下:n 是满足 m<=2n 最小数. 而0~m-1的数只能够用n-1个位和n个位来表示. 对于n个位表示的数来说不能有 ...

  8. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 D【队列】

    #1831 : 80 Days 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 80 Days is an interesting game based on Jules ...

  9. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 D. 80 Days

    题解 题目大意 n个点组成一个环形 初始钱为m 从i走到j需要-b[i] + a[j] 要求按照顺时针走完所有的点(不用再回到起点) 过程中m不能小于0 输出最小的起点编号 直接把a[i]和b[i]合 ...

最新文章

  1. linux内核模块的优缺点
  2. oracle dg状态查询,oracle dg状态检查及相关命令
  3. wordpress功能集成(二):基础知识-wordpress钩子(转)
  4. 2017.9.28 产品加工 思考记录
  5. android8按键布局,机身按键接口布局合理_手机Android频道-中关村在线
  6. mysqlserver输入密码后闪退_iOS降级教程:iOS 14 后如何降级到ios13?
  7. c语言数据结构判断回文数,C++数据结构与算法之判断一个链表是否为回文结构的方法...
  8. Extreme以5500万美元收购Brocade数据中心网络资产
  9. php遍历文件夹(获得文件名)
  10. 编写安全代码:小心使用浮点数
  11. 逆天通用水印扩展篇~新增剪贴板系列的功能和手动配置,卸除原基础不常用的功能...
  12. docker菜鸟入门
  13. 房产经纪人拿楼市新政炒作涨价
  14. Pettitt突变点检测
  15. 网易云课堂-数据结构-练习题实现-00,打印沙漏
  16. 华师大计算机在线作业,华东师范大学计算机考研复试机试习题
  17. linux 写镜像工具下载,镜像写入工具下载
  18. 嵌入式Linux(十三)RTC实时时钟
  19. OpenCV_11高反差保留
  20. c# 解决:Panel 添加自定义控件后滚动条跳动问题

热门文章

  1. 丝雨学姐小灶班——Week 3
  2. 设A是n*n的对称矩阵,将A的对角线及对角线上方的元素以列为主的次序存放在一维数组B[1..n(n+1)/2]中,对上述任一元素aij(1=i,j=n,且i=j)在B中的位置为()
  3. Python数据特征分析-对比分析
  4. Linux无法联网解决办法
  5. 全面深入理解卷积神经网络与LeNet 5 的结构
  6. Linux Usage
  7. 计算机存储一个像素点需要多大内存,占了多少字节?
  8. cross frequency coupling
  9. oracle 数据库 时间前一天前一年前一个月
  10. 由Python位运算到原码反码补码