Codeforces Contest 1089 problem A Alice the Fan —— dp求已知两人最终得分推每次得分

本文主要是介绍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求已知两人最终得分推每次得分的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/881230

相关文章

csu 1446 Problem J Modified LCS (扩展欧几里得算法的简单应用)

这是一道扩展欧几里得算法的简单应用题,这题是在湖南多校训练赛中队友ac的一道题,在比赛之后请教了队友,然后自己把它a掉 这也是自己独自做扩展欧几里得算法的题目 题意:把题意转变下就变成了:求d1*x - d2*y = f2 - f1的解,很明显用exgcd来解 下面介绍一下exgcd的一些知识点:求ax + by = c的解 一、首先求ax + by = gcd(a,b)的解 这个

hdu4826(三维DP)

这是一个百度之星的资格赛第四题 题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1004&cid=500 题意:从左上角的点到右上角的点,每个点只能走一遍,走的方向有三个:向上,向下,向右,求最大值。 咋一看像搜索题,先暴搜,TLE,然后剪枝,还是TLE.然后我就改方法,用DP来做,这题和普通dp相比,多个个向上

hdu1011(背包树形DP)

没有完全理解这题, m个人,攻打一个map,map的入口是1,在攻打某个结点之前要先攻打其他一个结点 dp[i][j]表示m个人攻打以第i个结点为根节点的子树得到的最优解 状态转移dp[i][ j ] = max(dp[i][j], dp[i][k]+dp[t][j-k]),其中t是i结点的子节点 代码如下: #include<iostream>#include<algorithm

hdu4865(概率DP)

题意:已知前一天和今天的天气概率,某天的天气概率和叶子的潮湿程度的概率,n天叶子的湿度,求n天最有可能的天气情况。 思路:概率DP,dp[i][j]表示第i天天气为j的概率,状态转移如下:dp[i][j] = max(dp[i][j, dp[i-1][k]*table2[k][j]*table1[j][col] )  代码如下: #include <stdio.h>#include

usaco 1.1 Broken Necklace(DP)

直接上代码 接触的第一道dp ps.大概的思路就是 先从左往右用一个数组在每个点记下蓝或黑的个数 再从右到左算一遍 最后取出最大的即可 核心语句在于: 如果 str[i] = 'r'  ,   rl[i]=rl[i-1]+1, bl[i]=0 如果 str[i] = 'b' ,  bl[i]=bl[i-1]+1, rl[i]=0 如果 str[i] = 'w',  bl[i]=b

uva 10025 The ? 1 ? 2 ? ... ? n = k problem(数学)

题意是    ?  1  ?  2  ?  ...  ?  n = k 式子中给k,? 处可以填 + 也可以填 - ,问最小满足条件的n。 e.g k = 12  - 1 + 2 + 3 + 4 + 5 + 6 - 7 = 12 with n = 7。 先给证明,令 S(n) = 1 + 2 + 3 + 4 + 5 + .... + n 暴搜n,搜出当 S(n) >=

uva 10154 DP 叠乌龟

题意: 给你几只乌龟,每只乌龟有自身的重量和力量。 每只乌龟的力量可以承受自身体重和在其上的几只乌龟的体重和内。 问最多能叠放几只乌龟。 解析: 先将乌龟按力量从小到大排列。 然后dp的时候从前往后叠,状态转移方程: dp[i][j] = dp[i - 1][j];if (dp[i - 1][j - 1] != inf && dp[i - 1][j - 1] <= t[i]

uva 10118 dP

题意: 给4列篮子,每次从某一列开始无放回拿蜡烛放入篮子里,并且篮子最多只能放5支蜡烛,数字代表蜡烛的颜色。 当拿出当前颜色的蜡烛在篮子里存在时,猪脚可以把蜡烛带回家。 问最多拿多少只蜡烛。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cs

uva 10069 DP + 大数加法

代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#include <stack>#include <vector>#include <queue>#include <map>#include <cl

uva 10029 HASH + DP

题意: 给一个字典,里面有好多单词。单词可以由增加、删除、变换,变成另一个单词,问能变换的最长单词长度。 解析: HASH+dp 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#inc