8377: Playoff

题目描述:

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

【小结】:

不做不发现,原来自己的代码实现能力都不足以让我写出一个DFS了。

现在都开学了,自己多抽出时间来练习好这个搜索的基本功。

(搜索,DP-(背包,数位Dp,概率Dp,树形Dp),并查集,数论,树状数组,线段树)

上面的都要我去学,我都不太会,要是停留在做贪心,那就不叫算法竞赛了。

【题意】:

其实这个题非常好读懂,就是因为它是英语题目,让我困惑了不少。

其实你看看上面给你的三幅图,了解一下我下面说的。

题目说:有很多支队伍进行比赛,然后题目想达到的效果是????

它说,每一支队伍我想要知道,它    输和赢的次数       全部队伍都一样。

问有多少种这样的情况。(n给了最大就是9,肯定是一个奇数)。

【题解】:

这个题目想要统一一下有多少种方案,不如我们看一看示例给我们的极端例子。

9

1

1 2

这个例子最多才1e6的数据量,这不就是引领这我们去写深搜吗???

其实写深搜真的有点生疏了,这次还是二维的状态来深搜。

后来想明白才知道,原来它不会回去的,只要写两个方向的所出现的状况。

宏观调控一下就差不多了。

关键是剪枝,不剪枝的话   :2^36的复杂度,

剪枝:

1、如果题目给定了一些已有的条件已经超过了半数比赛的话。直接输出答案。

2、如果题目中不能走的情况,一定要标注好走两条路的情况。

贴上代码:

参考passer_by:https://blog.csdn.net/passer__/article/details/81987146

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=10;
int Lost[N],Win[N],vis[N][N];
int n,m,K,ans;
void dfs(int x,int y){if(y==n+1){x++;y=1+x;}//printf("X: %d , Y: %d\n",x,y);if(x==n){ans++;return ;}if(vis[x][y]==0){if(Win[x]<K&&Lost[y]<K){Win[x]++;Lost[y]++;dfs(x,y+1);Win[x]--;Lost[y]--;}if(Win[y]<K&&Lost[x]<K){Win[y]++;Lost[x]++;dfs(x,y+1);Win[y]--;Lost[x]--;}}else{dfs(x,y+1);}}
void solve(){memset(vis,0,sizeof(vis));memset(Lost,0,sizeof(Lost));memset(Win,0,sizeof(Win));scanf("%d",&m);int x,y;int flag=0;K=(n-1)/2;//printf("%d\n",K);for(int i=1;i<=m;i++){scanf("%d%d",&x,&y);vis[x][y]=vis[y][x]=1;Win[x]++;Lost[y]++;if(Win[x]>K||Lost[y]>K){flag=1;}}if(flag){printf("0\n");}else{ans=0;dfs(1,2);printf("%d\n",ans);}return ;
}
int main()
{while(~scanf("%d",&n),n){solve();}return 0;
}

upc 8377: Playoff(搜索-dfs)相关推荐

  1. upc 8377 Playoff(搜索)

    8377: Playoff 时间限制: 2 Sec  内存限制: 128 MB 题目描述 The Minato Mirai Football Association hosts its annual ...

  2. 8377: Playoff

    8377: Playoff 时间限制: 2 Sec  内存限制: 128 MB 提交: 99  解决: 28 [提交] [状态] [讨论版] [命题人:admin] 题目描述 The Minato M ...

  3. 树的广度优先搜索(BFS),深度优先搜索(DFS)

    BFS:Breadth First Search,广度优先搜索 DFS:Depth First Search,深度优先搜索 如图,A节点的下一级元素为B节点和C节点,B节点的下一级元素为D节点和E节点 ...

  4. 一文搞懂深度优先搜索、广度优先搜索(dfs、bfs)

    前言 你问一个人听过哪些算法,那么深度优先搜索(dfs)和宽度优先搜索(bfs)那肯定在其中,很多小老弟学会dfs和bfs就觉得好像懂算法了,无所不能,确实如此,学会dfs和bfs暴力搜索枚举确实利用 ...

  5. 一文搞定深度优先搜索(DFS)与广度优先搜索(BFS)【含完整源码】

    写在前面:博主是一位普普通通的19届双非软工在读生,平时最大的爱好就是听听歌,逛逛B站.博主很喜欢的一句话花开堪折直须折,莫待无花空折枝:博主的理解是头一次为人,就应该做自己想做的事,做自己不后悔的事 ...

  6. C++实现深度优先搜索DFS(附完整源码)

    C++实现深度优先搜索DFS C++实现深度优先搜索DFS完整源码(定义,实现,main函数测试) C++实现深度优先搜索DFS完整源码(定义,实现,main函数测试) #include <al ...

  7. C++用stack实现深度优先搜索DFS(附完整源码)

    C++用stack实现深度优先搜索DFS的实现 C++用stack实现深度优先搜索DFS的完整源码(定义,实现,main函数测试) C++用stack实现深度优先搜索DFS的完整源码(定义,实现,ma ...

  8. POJ 1321-棋盘问题-简单搜索DFS

    POJ 1321-棋盘问题-简单搜索DFS Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编 ...

  9. 记忆化搜索(DFS+DP) URAL 1223 Chernobyl’ Eagle on a Roof

    题目传送门 1 /* 2 记忆化搜索(DFS+DP):dp[x][y] 表示x个蛋,在y楼扔后所需要的实验次数 3 ans = min (ans, max (dp[x][y-i], dp[x-1][i ...

最新文章

  1. 原生JS完成“一对一、一对多”矩形DIV碰撞检测、碰撞检查,通过计算接触面积(重叠覆盖面积)大小来判断接触对象DOM
  2. 嵌入式中的 *(volatile unsigned int *)0x500 解释
  3. Ubuntu设置静态IP,解决重启后需要重新设置的问题。
  4. 高德深度信息接入的平台化演进
  5. 选择题微型计算机系统包括,全国计算机一级选择题专项训练及答案2016
  6. 点击显示隐藏盒子函数
  7. node --- 模块加载机制
  8. Win11更新22000.100后面部识别不可用怎么办
  9. Windows下的良心软件
  10. layUI数据表格可编辑扩展下拉框
  11. iOS POST 上传图片
  12. 阿里Q3财报:阿里云连续第7个季度翻番
  13. VS2017下载地址和安装教程(图解)
  14. Word2013的一级标题作为一页的第一行时,出现段前距失效问题如何解决?
  15. android dex2oat 编译,dex2oat代码阅读笔记
  16. element ul 日期插件
  17. python温度转换程序改写代码举一反三_006 实例1-温度转换
  18. 独立开发者为什么不需要运营也能月薪几万,甚至几十万?
  19. sqlyog安装详细步骤
  20. OpenSSL安装使用(二):OpenSSL安装说明

热门文章

  1. Excel筛选之后如何下拉递增
  2. 三种近距离技术ZigBee、蓝牙(Bluetooth)和WiFi介绍
  3. 黑马课件:docker实用篇
  4. 黑鲨4s和4spro的区别
  5. NUC是什么硬件设备?
  6. mac在前端配置的坑
  7. java基础笔记简单回忆
  8. nodejs框架express之使用中间件(初学)
  9. 世界睡眠日PPT模板
  10. 无限法则服务器错误登录期间发生错误,无限法则错误126的解决方案分享 Error126错误提示...