Sicily 2386. Jollo

来源:互联网 发布:七上生物行知天下答案 编辑:程序博客网 时间:2024/06/07 15:02

2386. Jollo

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

Jollo is a simple card game which the children from Logonia love to play. It is played between two players with a normal deck of 52 cards. In the game, cards are ordered according to their rank and suit, forming a sequence of 52 distinct values.
The game is composed of three rounds, played in a best-of-three series (a player must win two rounds to win the game). At the beginning of the game the deck is shuffled and each player is given a hand of three cards. In each round the players show one card to each other and the player with the highest card wins the round. The cards shown in a round are discarded (i.e., they cannot be shown again).
The King's son loves to play the game. But he is not very smart, losing frequently to his little sister. And when he loses, he cries so loud no one can stand it. The servant who deals the cards to the Prince and his sister is afraid he will be sent to prison if the Prince continues to lose. The servant is allowed to see every card he deals, and after dealing five cards (three to the Princess and two to the Prince) he wants to know which is the lowest card he should deal to the Prince so that there is no chance he will lose the game, no matter how badly he plays.

Input

Each test case is given in a single line that contains five distinct integers ABCX and Y, describing the cards dealt to the players. The first three cards are given to the Princess (1$ \le$ABC$ \le$52) and the last two cards are given to the Prince (1$ \le$XY$ \le$52). The last test case is followed by a line containing five zeros.

Output

For each test case output a single line. If there exists a card that will make the Prince win the game no matter how badly he plays, you must print the lowest such a card. Otherwise, print -1.

Sample Input

28 51 29 50 5250 26 19 10 2710 20 30 24 2646 48 49 47 500 0 0 0 0

Sample Output

30 -1 21 51

Problem Source

每周一赛第二场

挺好玩的题,分析如下,其中王子是b,公主是g;

如果g有两张牌可以对应大于b,b输(笨王子);

如果g无论如何都没有两张牌对应大于b,g输(这运气。。);

那么我们可以枚举王子的第三张牌,然后判断。

// Problem#: 2386// Submission#: 2811520// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <stdio.h>#include <algorithm>using namespace std;int g[3], b[3];bool boy_win(int key) {    if (key == b[0] || key == b[1] || key == g[0] || key == g[1] || key == g[2])        return false;    int bb[3], gg[3];    int per[3] = {0, 1, 2};    bb[0] = b[0];    bb[1] = b[1];    bb[2] = key;    gg[0] = g[0];    gg[1] = g[1];    gg[2] = g[2];    int counter = 0;    for (int i = 0; i < 3; i++) {        if (gg[per[i]] > bb[i]) {            counter++;        }    }    if (counter >= 2) {        return false;    }    while (next_permutation(per, per + 3)) {        counter = 0;        for (int i = 0; i < 3; i++) {            if (gg[per[i]] > bb[i]) {                counter++;            }        }        if (counter >= 2) {            return false;        }    }    return true;}int main() {    while (scanf("%d%d%d%d%d", &g[0], &g[1], &g[2], &b[0], &b[1]) && g[0]) {        int key;        bool is_win = false;        for (key = 1; key <= 52; key++) {            if (boy_win(key)) {                is_win = true;                printf("%d\n", key);                break;            }        }        if (!is_win) {            printf("-1\n");        }    }    return 0;}            


0 0
原创粉丝点击