首页 > 其他分享 >POJ 3458 Colour Sequence

POJ 3458 Colour Sequence

时间:2022-11-09 18:38:47浏览次数:37  
标签:Colour sequence colour colours POJ cards line 3458 row


Description



We have a pile of cards consisting of 100 cards that are coloured on both sides. There is a finite number of colours (at most 26). In addition there are special cards called jokers. Jokers have a joker sign on both sides, which can assume any of the possible colours. We consider here a one-player card game, in which the player is challenged to derive a given colour sequence from a given row of cards, following certain rules.

Before the actual beginning of the game a colour sequence S of length at most 100 (not containing a joker) is given. Furthermore a number of cards are chosen from the pile and are put in a row. The sides turned upwards form a row of colours. Now the aim for the player is to create the colour sequence S with the cards from the row in the following way. For each card in the row the player decides whether or not to turn it over. When the card is turned over, only the colour on the other side is visible. Jokers may be part of the row of cards.

These steps lead to the final sequence of colours formed by the visible side of the cards in the row. If the player has been able to turn the cards in such a way that the pre-given colour sequence S is contained (from left to right) in the final row of colours, the player wins. If not, he loses. In matching the pre-given colour sequence to the row, cards in the row may be skipped, as long as the relative order of the colours is preserved. A joker can assume any colour. For example, the colour sequence (red, blue, yellow) is contained in (green, joker, blue, red, yellow), and (blue, green, blue, green) is contained in (red, blue, joker, yellow, joker, blue, green, green).

Your job is to find out if the player can win, given the colour sequence S and the row of cards chosen from the pile. This means that the sequence of colours that are face up is known, and so are the colours on the other side of these cards.


Input



The first line of the input file contains a single number: the number of test cases to follow. Each test case has the following format:

  • One line describing the colour sequence S. This line contains a string of m (with 1 ≤ m ≤ 100) characters from the set {'A', 'B', …, 'Z'}, denoting the colours. Different colours correspond to different characters. For example: "BGBG"
  • Two lines, corresponding to the row of cards chosen from the pile. Each of these lines contains a string of k (1 ≤ k ≤ 100) characters from the set {'A', 'B', …, 'Z', '*'}. The character '*'
    The string in the first line corresponds to the row of colours on the visible side of the cards. The string in the second line corresponds to the row of colours on the hidden side of the cards.
    So for the ith card in the row, the first line gives the colour of the side turned upwards and the second line shows the colour of the side face down. Obviously the strings on both lines have the same length. Furthermore, a '*' in one line (denoting a joker) always corresponds to a'*'


Output



For every test case in the input file, the output should contain one line. This line contains "win" if the colour sequence S can be achieved by the player by turning the right cards upside down, and "lose"


Sample Input



3 RBY B*RRB G*BRY BGBG RZ*Y*PGG AB*Y*BCB BAPC BUBCDAPVDAVVDLPF VLDCUSPGLSGPPVDD


Sample Output



win win

lose

其实就是判断第一个串能不能成为下面两个串合并的子串,像找子串一样直接做就好了

#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=3e5+10;
int T;
char s[maxn],c[2][maxn];

int main()
{
scanf("%d",&T);
while (T--)
{
scanf("%s%s%s",s,c[0],c[1]);
int k=0;
for (int i=0;c[0][i]&&s[k];i++)
{
if (c[0][i]==s[k]||c[1][i]==s[k]||c[0][i]=='*') k++;
}
if (s[k]) printf("lose\n"); else printf("win\n");
}
return 0;
}



标签:Colour,sequence,colour,colours,POJ,cards,line,3458,row
From: https://blog.51cto.com/u_15870896/5837714

相关文章

  • SPOJ 705 New Distinct Substrings
    DescriptionGivenastring,weneedtofindthetotalnumberofitsdistinctsubstrings.InputT-numberoftestcases.T<=20;Eachtestcaseconsistsofonestr......
  • POJ 1743 Musical Theme
    DescriptionAmusicalmelodyisrepresentedasasequenceofN(1<=N<=20000)notesthatareintegersintherange1..88,eachrepresentingakeyonthepi......
  • 究竟什么是POJO?
    POJO(PlainOldJavaObject)这种叫法是MartinFowler、RebeccaParsons和JoshMacKenzie在2000年的一次演讲的时候提出来的。     我在做J2EE培训中发现我的......
  • POJ3061 Subsequence
    思路:尺取法注意本题目中所有的内容全部是证书,这就为我们维护了一个很好的单调性.考虑最暴力的\(\mathcalO(n^3)\)的做法,就是枚举起点,终点,然后分别求和.但是......
  • POJ-1018
    POJ-1018(现在好像过不了)题意目前有一个公司需要购进宽带设备,每种设备有多款机器供选择,每种设备都需购进一台,现给出每台设备的带宽p与价格q,要求选择设备的最小带宽\(min(......
  • POJ-3737
    POJ-3737题意给出一个圆锥的表面积,求最大体积。思路显然,得到底面积的半径后,一切都能得到。在我们慢慢延长半径时,发现不满足线性,而是单峰函数。故三分。圆锥复习Code......
  • poj 2392 Space Elevator
    给出了一些砖块,砖块有高度,最高可以达到的高度(高度限制)和数量,问可以用这些砖块堆的最大高度   f[i][j]考虑前i块,能否堆出高度为j   f[i][j]|=f[i-1][j-k*h[i]......
  • 【XSY3458】原样输出(SAM)
    考虑判断一个串是否能成为输出,贪心的方法肯定是优先在第一个串的SAM上匹配至匹配不了,再在第二个串的SAM上匹配至匹配不了,……于是可以考虑通过如下方式把\(n\)个串......
  • 【POJ1430】Binary Stirling Numbers(第二类斯特林数,组合数)
    求\(\begin{Bmatrix}n\\m\end{Bmatrix}\bmod2\)的值。由第二类斯特林数的递推公式:\[\begin{Bmatrix}n\\m\end{Bmatrix}=\begin{Bmatrix}n-1\\m-1\end{Bmatrix}+m\begi......
  • 【poj1061】青蛙的约会(扩展欧几里得)
    不妨设青蛙A的出发点坐标是\(m1\),青蛙B的出发点坐标是\(n1\)。青蛙A一次能跳\(m\)米,青蛙B一次能跳\(n\)米,跳一圈长\(l\)米,设青蛙A、B跳了\(x\)次。那么题目要求的是满足下......