World Cup
Input file: Standard Input
Output file: Standard Ouptut
Time limit: 1 second
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.
Limits
• 1 ≤ T ≤ 100.
• 0 ≤ A, B, C, D ≤ 100.
Sample Input
3
9 6 3 0
6 6 6 0
10 6 3 0
Sample Output
Case #1: Yes
Case #2: No
Case #3: Wrong 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.
大意:根据世界杯赛制, 每轮有四场比赛, 每支队伍与其他三支队伍各打一场比赛, 一共有六场比赛。给出四支球队分别的得分,能否确定唯一的胜负关系。
思路:此题可以暴力枚举出所有的情况与输入分数进行匹配。根据匹配成功的次数可以判断最终结果。
#include<bits/stdc++.h> using namespace std; int score[4]; int cnt; int gget[4]; int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r",stdin); freopen("out.txt", "w",stdout); #endif // ONLINE_JUDGE int T; cin >> T; for(int t = 1; t <= T; t++) { printf("Case #%d: ", t); int sum; for(int i = 0; i < 4; i++) cin >> score[i]; cnt = 0; for(int g1 = -1; g1 < 2; g1++) for(int g2 = -1; g2 < 2; g2++) for(int g3 = -1; g3 < 2; g3++) for(int g4 = -1; g4 < 2; g4++) for(int g5 = -1; g5 < 2; g5++) for(int g6 = -1; g6 < 2; g6++) { memset(gget,0,sizeof(gget)); if(g1 == 1) { gget[0] += 3; } else if(g1 == 0) { gget[0] += 1; gget[1] += 1; } else if(g1 == -1) { gget[1] += 3; } if(g2 == 1) { gget[0] += 3; } else if(g2 == 0) { gget[0] += 1; gget[2] += 1; } else if(g2 == -1) { gget[2] += 3; } if(g3 == 1) { gget[0] += 3; } else if(g3 == 0) { gget[0] += 1; gget[3] += 1; } else if(g3 == -1) { gget[3] += 3; } if(g4 == 1) { gget[1] += 3; } else if(g4 == 0) { gget[1] += 1; gget[2] += 1; } else if(g4 == -1) { gget[2] += 3; } if(g5 == 1) { gget[1] += 3; } else if(g5 == 0) { gget[1] += 1; gget[3] += 1; } else if(g5 == -1) { gget[3] += 3; } if(g6 == 1) { gget[2] += 3; } else if(g6 == 0) { gget[2] += 1; gget[3] += 1; } else if(g6 == -1) { gget[3] += 3; } // for(int i = 0; i < 4; i++) // cout << gget[i] << " "; // cout << endl; int flag = 1; for(int i = 0; i < 4; i++) if(score[i] != gget[i]) flag = 0; if(flag)cnt++; } //printf("cnt:%d ",cnt); if(cnt == 0) { printf("Wrong Scoreboard "); } else if(cnt == 1) { printf("Yes "); } else { printf("No "); } } }