Bingo VJ补题

Bingo is a game of chance played by a group of players. Each player has his or her own bingo card with a 5-by-5

grid of numbers. Each number appears at most once per card. The bingo caller calls out a sequence of randomly drawn numbers, and the players mark the numbers that appear on their card as they are called out. The winner is the player that completes a line of five marked numbers (horizontally, vertically or diagonally) on his or her card. The winning player then yells “bingo” and the game ends.

You have been volunteering with a local youth group and have been running bingo games for the children. They love bingo, but every time two or more kids yell “bingo” at the same time, a spirited “disagreement” breaks out. You’ve created a slightly modified version of bingo (in the hopes of introducing fewer ties): the cards are 5
-by-5 grids with a number from 1 to 3000 in each of the 25 cells, and a winner is only declared when a player has 5

numbers in a row. Note that in this new game, players cannot win via columns or diagonals.

Alas, these changes did not eliminate ties or the subsequent disagreements. To prevent further disagreements, you’ve decided to analyze the sets of cards to determine if there is any possibility that a tie (where two kids can yell bingo at the same time) can occur. Write a program that takes a collection of bingo cards and determines if there is any possible sequence of numbers that could be called so that the game ends, and a tie between two or more players occurs, when the last number in the sequence is called.

For example, consider the following two bingo cards:

3111942919252327454340314256504958546872616371

148151062317262520393542314459555357526361716468

Then this set of two cards could result in a tie if the sequence of numbers called was
40 61 64 10 57 49 11 31 25

This sequence would result in the card on the left completing the third row and the card on the right completing the fourth row when the number 25

is called.
Input

The first line of the input is an integer n
(2≤n≤100), the number of bingo cards. After the first line are the n

bingo cards, each separated from the next by a blank line of input.

Each bingo card consists of five lines of input. Each line consists of five integers in the range from 1
to 3000

. The numbers on each bingo card are unique.
Output

If no ties are possible between any two cards, output “no ties”. Otherwise, output the two numbers a
and b (1≤a<b≤n) identifying the two cards for which a tie could occur, where the cards are numbered from 1 to n in the order that they appear in the input. If multiple pairs of cards can tie, output the pair with the smallest a, breaking any remaining ties with the smallest b

.
Sample Input 1 Sample Output 1

2
3 29 45 56 68
1 19 43 50 72
11 25 40 49 61
9 23 31 58 63
4 27 42 54 71

14 23 39 59 63
8 17 35 55 61
15 26 42 53 71
10 25 31 57 64
6 20 44 52 68

1 2

Sample Input 2 Sample Output 2

2
2189 2127 1451 982 835
150 1130 779 1326 1149
2697 2960 315 534 2537
2750 1771 875 1702 430
300 2657 2827 983 947

886 738 2569 1107 2758
2795 173 1718 2294 1732
1188 2273 2489 1251 2224
431 1050 1764 1193 1566
1194 1561 162 1673 2411

no ties

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 24;
const ll INF = 2*1e18;

int n;
struct Begiocard
{
    int num[6][6];
};
Begiocard mp[105];

void Cincard(int x)
{
    for(int i = 1; i <= 5; i++)
    {
        for(int j = 1; j <= 5; j++)
        scanf("%d",&mp[x].num[i][j]);
    }
}

bool judgec(int x,int y,int c1,int c2,int pos1,int pos2)//判断说其他数字时是否有其他行或者卡片已经胜利
{
    set<int> s;
    for(int i = 1; i <= 5; i++)
    {
        if(i != pos1)
        {
            s.insert(mp[x].num[c1][i]);
        }
        if(i != pos2)
        {
            s.insert(mp[y].num[c2][i]);
        }
    }
    if(s.size() < 5) return false;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= 5; j++)
        {
            int cnt = 0;
            for(int k = 1; k <= 5; k++)
            {
                if(s.count(mp[i].num[j][k])) cnt++;
            }
            if(cnt == 5) return true;
        }
    }
    return false;
}

bool judge(int x,int y,int c1,int c2)//判断两行是否有相同的数字
{
    int pos1,pos2;
    for(int i = 1; i <= 5; i++)
    {
        pos1= i;
        for(int j = 1; j <= 5; j++)
        {
            if(mp[x].num[c1][i] == mp[y].num[c2][j])
            {
                pos2 = j;
                if(!judgec(x,y,c1,c2,pos1,pos2))
                {
                    return true;
                }
            }
        }
    }
    return false;
}


int main()
{
    scanf("%d",&n);
    for(int i = 1; i <= n; i++)
    {
        Cincard(i);
    }
    int flag = 0;
    for(int i = 1; i < n; i++)
    {
        for(int j = i+1; j <= n; j++)
        {
            for(int k = 1; k <= 5; k++)
            {
                for(int c = 1; c <= 5; c++)
                {
                    if(judge(i,j,k,c))
                    {
                        printf("%d %d\n",i,j);
                        flag = 1;
                        break;
                    }
                }
                if(flag) break;
            }
            if(flag) break;
        }
        if(flag) break;
    }
    if(!flag) printf("no ties\n");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/king9666/article/details/89816561
vj