本文主要是介绍Codeforces Contest 1089 problem A Alice the Fan —— dp求已知两人最终得分推每次得分,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Alice is a big fan of volleyball and especially of the very strong “Team A”.
Volleyball match consists of up to five sets. During each set teams score one point for winning a ball. The first four sets are played until one of the teams scores at least 25 points and the fifth set is played until one of the teams scores at least 15 points. Moreover, if one of the teams scores 25 (or 15 in the fifth set) points while the other team scores 24 (or 14 in the fifth set), the set is played until the absolute difference between teams’ points becomes two. The match ends when one of the teams wins three sets. The match score is the number of sets won by each team.
Alice found a book containing all the results of all matches played by “Team A”. The book is old, and some parts of the book became unreadable. Alice can not read the information on how many sets each of the teams won, she can not read the information on how many points each of the teams scored in each set, she even does not know the number of sets played in a match. The only information she has is the total number of points scored by each of the teams in all the sets during a single match.
Alice wonders what is the best match score “Team A” could achieve in each of the matches. The bigger is the difference between the number of sets won by “Team A” and their opponent, the better is the match score. Find the best match score or conclude that no match could end like that. If there is a solution, then find any possible score for each set that results in the best match score.
Input
The first line contains a single integer m (1≤m≤50000) — the number of matches found by Alice in the book.
Each of the next m lines contains two integers a and b (0≤a,b≤200) — the number of points scored by “Team A” and the number of points scored by their opponents respectively.
Output
Output the solution for every match in the same order as they are given in the input. If the teams could not score a and b points respectively, output “Impossible”.
Otherwise, output the match score formatted as “x:y”, where x is the number of sets won by “Team A” and y is the number of sets won by their opponent.
The next line should contain the set scores in the order they were played. Each set score should be printed in the same format as the match score, with x being the number of points scored by “Team A” in this set, and y being the number of points scored by their opponent.
Example
inputCopy
6
75 0
90 90
20 0
0 75
78 50
80 100
outputCopy
3:0
25:0 25:0 25:0
3:1
25:22 25:22 15:25 25:21
Impossible
0:3
0:25 0:25 0:25
3:0
25:11 28:26 25:13
3:2
25:17 0:25 25:22 15:25 15:11
题意:
给你两个队伍的最终得分,一次比赛可分为5场,前四场如果有人的分数大于25就结束,如果两个队分数相差1,那么直到打到相差2为止结束,最后一场是15分,如果有一个队赢了3场,直接结束比赛。让你重现这次比赛所有场次的比分,且每场比赛的绝对值的和最大。如果不可能,输出Impossible。
题解:
dp[i][j][x][y]表示第一队赢了x场,第二队赢了y场,第一队的比分为i,第二队的比分为j的可能性。ans就记录如果有这个可能性,它从上一个状态转移过来的两个比分。
#include<bits/stdc++.h>
using namespace std;
#define pi pair<int,int>
#define pb push_back
int dp[205][205][4][4];
vector<pi>ans[205][205][4][4];
int awin[]={3,3,3,2,1,0},bwin[]={0,1,2,3,3,3};
int main()
{dp[0][0][0][0]=1;for(int i=0;i<=200;i++){for(int j=0;j<=200;j++){for(int x=0;x<=2;x++){for(int y=0;y<=2;y++){if(!dp[i][j][x][y])continue;int mx;if(x==2&&y==2)mx=15;elsemx=25;for(int c=0;c<=mx-2;c++){if(i+mx<=200&&j+c<=200&&!dp[i+mx][j+c][x+1][y])dp[i+mx][j+c][x+1][y]=1,ans[i+mx][j+c][x+1][y]=ans[i][j][x][y],ans[i+mx][j+c][x+1][y].pb({mx,c});if(i+c<=200&&j+mx<=200&&!dp[i+c][j+mx][x][y+1])dp[i+c][j+mx][x][y+1]=1,ans[i+c][j+mx][x][y+1]=ans[i][j][x][y],ans[i+c][j+mx][x][y+1].pb({c,mx});}for(int c=mx-1;c<=200;c++){if(c+j+2<=200&&i+c<=200&&!dp[i+c][j+c+2][x][y+1])dp[i+c][j+c+2][x][y+1]=1,ans[i+c][j+c+2][x][y+1]=ans[i][j][x][y],ans[i+c][j+c+2][x][y+1].pb({c,c+2});if(c+i+2<=200&&c+j<=200&&!dp[i+c+2][j+c][x+1][y])dp[i+c+2][j+c][x+1][y]=1,ans[i+c+2][j+c][x+1][y]=ans[i][j][x][y],ans[i+c+2][j+c][x+1][y].pb({c+2,c});}}}}}int t;scanf("%d",&t);while(t--){int n,m,flag=0;scanf("%d%d",&n,&m);for(int i=0;i<6;i++){if(dp[n][m][awin[i]][bwin[i]]){printf("%d:%d\n",awin[i],bwin[i]);for(int j=0;j<ans[n][m][awin[i]][bwin[i]].size();j++)printf("%d:%d ",ans[n][m][awin[i]][bwin[i]][j].first,ans[n][m][awin[i]][bwin[i]][j].second);printf("\n");flag=1;break;}}if(!flag)printf("Impossible\n");}return 0;
}
这篇关于Codeforces Contest 1089 problem A Alice the Fan —— dp求已知两人最终得分推每次得分的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!