World Cup(The 2016 ACM-ICPC Asia China-Final Contest dfs搜索)
Posted sykline
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了World Cup(The 2016 ACM-ICPC Asia China-Final Contest dfs搜索)相关的知识,希望对你有一定的参考价值。
题目:
Here is World Cup again, the top 32 teams come together to fight for the World Champion. The teams are assigned into 8 groups, with 4 teams in each group. Every two teams in the same group will play a game (so there are totally 6 games in each group), and the winner of this game gets 3 points, loser gets 0 point. If it is a tie game, both teams get 1 point. After all games finished, we get the scoreboard, but we forget the result of each game, can you help us to figure the result of each game? We only care about the win/lose/tie result of each game, but we don’t care the goals in each game.
Input:
The input starts with one line containing exactly one integer T, which is the number of test cases. Each test case contains four space-separated integers A, B, C, D, in a line, which indicate the points each team gets after all 6 games.
Output:
For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is “Yes” if you can point out the result of each game, or “No” if there are multiple game results satisfy the scoreboard, or “Wrong Scoreboard” if there is no game result matches the scoreboard.
Note:
In sample case #1, the only scenaro will be: the first team wins all the three games it plays, the second team loses to the first team and wins the other two, the third team only wins the game with the fourth, and the fourth team lose all the games.
In sample case #2, the fourth team loses all the games, and the first three teams get into a winning-cycle, but there may be two different winning-cycles: first team wins second team, second team wins third team, third team wins first team OR first team wins third team, third team wins second team, second team wins first team. We can’t figure which winning-cycle is the actual game result.
In sample case #3, the first team get 10 points, but no team could get more than 9 points by play three games, so it is a wrong scoreboard.
题意:世界杯比赛的一个小组中有4支队伍,队伍两两之间要进行一场比赛,赢得队伍得3分,输的队伍得0分,平局双方得1分。给出四支队伍的比赛完后的得分情况,问能不能确定具体的输赢情况。
思路:每组比赛一共有如下六种情况,那就dfs枚举六种情况下每个队伍输赢的所有的分情况,如果和给出的得分情况有多组相同,就是“No”,一组相同就是“Yes”,没有相同情况就是“Wrong Scoreboard”。
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <queue> #include <map> #include <set> #include <vector> using namespace std; typedef long long ll; const int maxn = 1e5+10; int a,b,c,d,ans; int buf[5]; void dfs(int x) { if(x == 7) { if(a == buf[0] && b==buf[1] && c==buf[2]&& d==buf[3]) ans++; return; } if(x==1) { buf[0]+=3;//1队伍赢 dfs(x+1); buf[0]-=3; buf[0]+=1,buf[1]+=1;//两队平局 dfs(x+1); buf[0]-=1,buf[1]-=1; buf[1]+=3;//2队伍赢 dfs(x+1); buf[1]-=3; } else if(x==2) { buf[0]+=3;//1队伍赢 dfs(x+1); buf[0]-=3; buf[0]+=1,buf[2]+=1;//两队平局 dfs(x+1); buf[0]-=1,buf[2]-=1; buf[2]+=3;//3队伍赢 dfs(x+1); buf[2]-=3; } else if(x==3) { buf[0]+=3;//1队伍赢 dfs(x+1); buf[0]-=3; buf[0]+=1,buf[3]+=1;//两队平局 dfs(x+1); buf[0]-=1,buf[3]-=1; buf[3]+=3;//4队伍赢 dfs(x+1); buf[3]-=3; } else if(x==4) { buf[1]+=3;//2队伍赢 dfs(x+1); buf[1]-=3; buf[1]+=1,buf[2]+=1;//两队平局 dfs(x+1); buf[1]-=1,buf[2]-=1; buf[2]+=3;//3队伍赢 dfs(x+1); buf[2]-=3; } else if(x==5) { buf[1]+=3;//2队伍赢 dfs(x+1); buf[1]-=3; buf[1]+=1,buf[3]+=1;//两队平局 dfs(x+1); buf[1]-=1,buf[3]-=1; buf[3]+=3;//4队伍赢 dfs(x+1); buf[3]-=3; } else if(x==6) { buf[2]+=3;//3队伍赢 dfs(x+1); buf[2]-=3; buf[2]+=1,buf[3]+=1;//两队平局 dfs(x+1); buf[2]-=1,buf[3]-=1; buf[3]+=3;//4队伍赢 dfs(x+1); buf[3]-=3; } } int main() { int T,cnt = 1; scanf("%d",&T); while(T--) { ans = 0; memset(buf,0,sizeof(buf)); scanf("%d%d%d%d",&a,&b,&c,&d); dfs(1); if(ans==0) printf("Case #%d: Wrong Scoreboard ",cnt++); else if(ans == 1) printf("Case #%d: Yes ",cnt++); else printf("Case #%d: No ",cnt++); } return 0; }
以上是关于World Cup(The 2016 ACM-ICPC Asia China-Final Contest dfs搜索)的主要内容,如果未能解决你的问题,请参考以下文章
Gym 101194L / UVALive 7908 - World Cup - [三进制状压暴力枚举][2016 EC-Final Problem L]