hdu 1683 Colour sequence 有多种解法的题目

来源:互联网 发布:绝地求生支持mac系统吗 编辑:程序博客网 时间:2024/06/07 02:38

Colour sequence

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 233    Accepted Submission(s): 136


Problem 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" denotes the sequence blue, green, blue, green.

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 '*' denotes a joker, which can play the role of any of the possible colours.


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 '*' in the other line at the corresponding position.

 

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" if this is not the case.

 

Sample Input
3RBYB*RRBG*BRYBGBGRZ*Y*PGGAB*Y*BCBBAPCBUBCDAPVDAVVDLPFVLDCUSPGLSGPPVDD
 

Sample Output
winwinlose
 

Source
华东区大学生程序设计邀请赛_热身赛
 

Recommend
lcy   |   We have carefully selected several similar problems for you:  1680 1681 1684 1679 1687 



这个题目是说有几副扑克牌,然后先给出一排要求求出的字母,然后给出几张扑克,给出正负两面,然后随便开始匹配,如果匹配成功就是win,否则lose,这个题目说的简单吧,也很简单,一个for循环就可以了,还可以使用暴搜,其实还可以用
DP。
水办法:

#include<iostream>#include<cstdio>#include<cstring>using namespace std;int main(){    int i,j,k;    int n;    scanf("%d",&n);    char a[200];    char b[110];    char c[110];    while(n--)    {        j=0;        i=0;        scanf("%s%s%s",a,b,c);        int la=strlen(a);        int lb=strlen(b);        int flag=0;        for(i=0;i<lb;i++)        {            if((b[i]==a[j])||(c[i]==a[j])||(b[i]=='*')||(c[i]=='*'))            {                j++;            }            if(j==la)            {                flag=1;                break;            }        }        if(flag)        {            printf("win\n");        }        else        printf("lose\n");    }    return 0;}
比较有水平的办法:
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int f[200][200],la,ls;string a,s1,s2; bool dfs(int na,int ns)  {      if(na==la)      return true;      if(ns==ls)      return false;      if(f[na][ns]!=-1)       {           return f[na][ns];       }      if(a[na]==s1[ns]||a[na]==s2[ns]||s1[ns]=='*')        {            return f[na][ns]=dfs(na+1,ns+1);        }        else return f[na][ns]=dfs(na,ns+1);  }int main() {     int n;     cin>>n;     while(n--)      {          memset(f,-1,sizeof(f));          cin>>a;cin>>s1;cin>>s2;          la=a.length(); ls=s1.length();          int flag=0;          for(int i=0;i<=ls-la;i++)           {               flag=dfs(0,i);               if(flag)break;           }          if(flag)          cout<<"win"<<endl;           else           cout<<"lose"<<endl;      } }












 
0 0
原创粉丝点击