Codeforce 106A Card Game

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lj130lj/article/details/79968704

题意:

    四类牌,每类有9个等级。王牌这种类大于其他的类,同类型的比等级,不同类型的且没有王类,无法比较。

问先手是否能获胜。

#include<bits/stdc++.h>
using namespace std;
int Num(char c){
    if(c=='T')return 10;
    if(c=='J')return 11;
    if(c=='Q')return 12;
    if(c=='K')return 13;
    if(c=='A')return 14;
    return c-'0';
}
int main(){
    string w,a,b;
    cin>>w>>a>>b;
    if(a[1]==w[0]&&b[1]!=w[0]){
        cout<<"YES\n";
        return 0;
    }
    if(a[1]!=w[0]&&b[1]==w[0]){
        cout<<"NO\n";
        return 0;
    }
    if(a[1]!=b[1])cout<<"NO";
    else if(Num(a[0])>Num(b[0])){
        cout<<"YES\n";
    }else {
        cout<<"NO";
    }
}

阅读更多

Card Game - Kitty Fishing

02-22

There is a simple two-player card game called "Kitty Fishing". When the game begins, player A and B have the same number of cards. Then each gives out one card in turn. Each card given out on the table should be laid overlapped one by one. When the card newly given out finds a card which has the same value on the table, the player who gives out the card will take the cards between the two same cards following the order the cards on the table, and put them to the back of his cards. The same player continues to give out next cards. Player giving a card called a turn. Note: Do not change the order of your cards.nThe following is an example.nnAt the beginning:nnA has cards 1,4,2,3 and B has cards 2,1,3,4nnFirst: A gives out 1.nnA: 4,2,3nB: 2,1,3,4nCards on the table: 1.nnSecond: B gives out 2.nnA:4,2,3nB:1,3,4nCards on the table: 1,2nnThird: A gives out 4.nnA:2,3nB:1,3,4nCards on the table 1,2,4nnForth: B gives out 1.nnA:2,3nB:3,4nCards on the table: 1,2,4,1nnThe card '1'given out by B is the same as the first one of the cards on the table. So B takes the cards following the turn of '1,4,2,1'. Then it will be:nnA: 2,3nB: 3,4,1,4,2,1nCards on the table: NULLnnIn this example, A and B have four turns.nnIf one of the players has given out all of his cards, he will lose the game, and the other one is the winner. The game is over.nnWrite a program that will play the game of "Kitty Fishing".nnnInputnnThe input contains one or more data sets. Each data set consists of three lines: The first line contains an integer which gives out the turns you should play, and the next two lines are cards which A and B have. Each one's cards will be ended with the number 0.nnA line which contains a single 0 will end the input. No input lines follow that line.nnnOutputnnIf the game has been over before the turns, just write out the winner's name. If the game has not been over, write out the cards two players have in the order in their hands and the cards on the table.nnnSample Inputnn4n1 4 2 3 0n2 1 3 4 0n30n5 8 5 6 5 7 3 4 6 2 1 7 7 1 2 1 0n3 8 7 8 8 5 6 3 6 2 3 2 4 4 1 4 0n246n5 6 7 2 7 1 2 4 3 5 3 1 7 1 6 4 0n8 6 2 6 4 8 7 8 2 3 5 8 3 5 1 4 0n0nnnSample OutputnnCase 1:n2 3n3 4 1 4 2 1nNULLnCase 2:n1 5 3 5 7 6 7 7 2 7 1 4 3 1n4 8 8 8 5 8 3 4 6 3 6 6 2 2n5 4 2 1nCase 3:nA

Funny Card Game

02-27

Of course all of you want to know how to become ACM world champions. There is no exact answer to this question but it is well known that the champions of the last two ACM World Finals enjoyed playing the following funny card game. Two or more players can play this game simultaneously. It is played using a standard 54-card deck. At the beginning the players sit forming a circle. One of the players shuffles the deck and then he deals the cards in clockwise order starting from the neighbour on his left. He deals the top card of the deck to the current player each time. He does it until each player gets five cards. Then he takes the top card of the deck and lays it onto the table face up and he also lays the remainder of the deck nearby (these cards are laid face down preserving their original order). The card laid by the shuffler is considered as the first turn of the game (as if it was made by the shuffler to the player on his left).nnThe normal game flow as following: the player should cover the last laid card with the card of the same suit or value. If he has none, he takes one card from the top of the deck and again checks this condition. If still there are no matching cards, the move will go to the next player (his left neighbour). But for some cards special rules are applied:nn1. If the laid card is 6, the player takes one card from the top of the deck and skips his turnnn2. If the laid card is 7, the player takes two cards from the top of the deck (if there is only one card in the deck, he takes just it) and skips his turnnn3. If the laid card is Ace the player skips his turn without taking any cardsnn4. If the player lays Queen, he himself announces the suit of the card it should be covered withnn5. Eight is one of the most powerful weapons in this game. When it is laid, the next player has to cover it in any case. If he cannot cover it with his cards he has to take cards from the deck, until he is able to cover it.nn6. And the most important card in the game is the King of Spades. If it's laid, the next player takes 4 cards from the top of the deck (if there is not enough cards in the deck, he takes all of them) and skips his turn.nnYou may assume that the deck is looped and the laid cards are immediately moving to the bottom of the deck. So it can happen that the player has to cover the card by itself.nnWe should say some words about Jokers. Jokers can have any card value by the wish of the player who has it. If the player lays the joker, he assigns a definite card value and suit for it, so this Joker has this assigned value until another player takes it from the deck (if it ever happens). The player is free to use or not to use the Joker whenever he wants (if it is his turn to play, of course).nnIf the player is left without any cards in his hand, he is considered a winner and the game continues without him (his left neighbour becomes the left neighbour of his right neighbour).nnIf there is only one player left, he is the looser, so he is called a Japanese Fool (it is a Russian name of this game).nnWe are interested in the following situation. Consider the moment when only two players are left in the game. If one of them has a special combination of cards, it may happen that he can lay out all his cards in a some sequence so that the other player won't get a move (he'll just have to take cards from the deck and skip turns) and will be the loser - provided the first one finds the winning sequence.nnYou will be given the position of the game in which only two players are left. Your task will be to determine whether such a winning sequence for the first player exists or not.nnWe will consider that the first player have already taken all cards from the deck that he had to (if any), so he cannot take any cards from the deck. We will also consider that if the last laid card is a skip-turn card, it was the second player who skipped the turn.nnnInputnnThe first line of the input file contains cards of the first player separated by spaces. The second line contains the last laid face up card.nnThe card description consists of two characters. The first of them corresponds to the card value (2-9 for digits, T for 10, J for Jack, Q for Queen, K for King and A for Ace). The next describes the suit of the card and may be one of the following: S for Spades, C for Clubs, D for Diamonds or H for Hearts. Joker is represented by a character '*'. If the last laid card is Queen, it is followed by a suit letter. If the last laid card is a joker, then the '*' is followed by an actual card description (the card specified by the player who laid the Joker).nnProcess to the end of file.nnnOutputnnThe first line of the output file should contain a single word Yes or No signalling whether the winning sequence exists. If the answer is positive the second line must contain the winning sequence of cards separated by one space. As in the input, the Joker is to be followed by a card specification and the Queen should follow a suit letter. If there is more than one solution you may output an arbitrary one.nnnSample Inputnn6C QD 6S KS 7S *n*QHSn*nKSn6C 8D 7D 8H 8Cn2DnnnSample OutputnnYesn7S KS 6S 6C *6D QDSnYesn*QSDnNo

poker card game

10-15

DescriptionnnSuppose you are given many poker cards. As you have already known, each card has points ranging from 1 to 13. Using these poker cards, you need to play a game on the cardboard in Figure 1. The game begins with a place called START. From START, you can walk to left or right to a rectangular box. Each box is labeled with an integer, which is the distance to START. nn ![](http://poj.org/images/1339_1.jpg)nFigure 1: The poker card game cardboard. nnTo place poker cards on these boxes, you must follow the rules below: (1) If you put a card with n points on a box labeled i , you got (n ∗ i) points. (2) Once you place a card on a box b, you block the paths to the boxes behind b. For example, in Figure 2, a player places a queen on the right box of distance 1, he gets 1 ∗ 12 points but the queen also blocks the paths to boxes behind it; i.e., it is not allowed to put cards on boxes behind it anymore. nn![](http://poj.org/images/1339_2.jpg)n nFigure 2: Placing a queen. nnYour goal: Given a number of poker cards, find a way to place them so that you will get the minimum points. For example, suppose you have 3 cards 5, 10, and K. To get the minimum points, you can place cards like Figure 3, where the total points are 1 * 13 + 2 * 5 + 2 * 10 = 43. nn![](http://poj.org/images/1339_3.jpg)n nFigure 3: An example to place cards. nnInputnnThe first line of the input file contains an integer n, n <= 10, which represents the number of test cases. In each test case, it begins with an integer m, m <= 100000, nnwhich represents the number of poker cards. Next, each card represented by its number are listed consecutively. Note that, the numbers of ace, 2, 3, ..., K are given by integers 1, 2, 3, ..., 13, respectively. The final minimum point in each test case is less than 5000000. nOutputnnList the minimum points of each test case line by line.nSample Inputnn3n3n5 10 13n4n3 4 5 5n5n7 7 10 11 13nSample Outputnn43n34n110

求解Card Game -Kitty Fishing

07-15

Card Game -Kitty Fishing rnrnrnThere is a simple two-player card game called "Kitty Fishing". When the game begins, player A and B have the same number of cards. Then each gives out one card in turn. Each card given out on the table should be laid overlapped one by one. When the card newly given out finds a card which has the same value on the table, the player who gives out the card will take the cards between the two same cards following the order the cards on the table, and put them to the back of his cards. The same player continues to give out next cards. Player giving a card called a turn. Note: Do not change the order of your cards. rnrnThe following is an example. rnrnAt the beginning: rnA has cards 1,4,2,3 and B has cards 2,1,3,4 rnrnFirst: A gives out 1. rnA:4,2,3 rnB:2,1,3,4 rnCards on the table:1. rnrnSecond:B gives out 2. rnA:4,2,3 rnB:1,3,4 rnCards on the table:1,2 rnrnThird:A gives out 4. rnA:2,3 rnB:1,3,4 rnCards on the table:1,2,4 rnrnForth:B gives out 1. rnA:2,3 rnB:3,4 rnCards on the table:1,2,4,1 rnrnThe card '1' given out by B is the same as the first one of the cards on the table. So B takes the cards following the turn of '1,4,2,1'. Then it will be: rnA:2,3 rnB:3,4,1,4,2,1 rnCards on the table:NULL rnrnIn this example, A and B have four turns. rnrnIf one of the players has given out all of his cards, he will lose the game, and the other one is the winner. The game is over. rnrnWrite a program that will play the game of "Kitty Fishing".. rnrnInput rnrnThe input contains one or more data sets. Each data set consists of three lines: The first line contains an integer which gives out the turns you should play, and the next two lines are cards which A and B have. Each one's cards will be ended with the number 0. rnA line which contains a single 0 will end the input. No input lines follow that line. rnrnOutput rnrnIf the game has been over before the turns, just write out the winner's name. If the game has not been over, write out the cards two players have in the order in their hands and the cards on the table. rnrnSample Input rnrnrn30rnrn5 8 5 6 5 7 3 4 6 2 1 7 7 1 2 1 0rnrn3 8 7 8 8 5 6 3 6 2 3 2 4 4 1 4 0rnrn0rnrnrnSample Output rnrnrnCase 1:rnrn1 5 7 3 5 3 3 6 6 1 1rnrn4 8 8 8 5 8 6 7 5 6 2 2 4 7 2 1 3 4rnrn2 7 4rnrn

没有更多推荐了,返回首页