Kattis - bingoties 带思维的暴力

Bingo is a game of chance played by a group of players. Each player has his or her own bingo card with a 55-by-55grid 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 55-by-55 grids with a number from 11 to 30003000 in each of the 2525 cells, and a winner is only declared when a player has 55 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:

31119429192523274543403142565049585468726163713294556681194350721125404961923315863427425471

148151062317262520393542314459555357526361716468142339596381735556115264253711025315764620445268

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 2540 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 2525 is called.

Input

The first line of the input is an integer nn (2n1002≤n≤100), the number of bingo cards. After the first line are the nn 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 11 to 30003000. 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 aa and bb (1a<bn1≤a<b≤n) identifying the two cards for which a tie could occur, where the cards are numbered from 11 to nn in the order that they appear in the input. If multiple pairs of cards can tie, output the pair with the smallest aa, breaking any remaining ties with the smallest bb.

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

题意就是几个人都有一张5*5的卡片

卡片上有25个不同的数字

然后随机说数字,你的卡片上如果出现一个就标记一个

如果你的卡片上有一行被划掉了,就胜利了,但是会出现同时胜利的情况

给你n张卡片,问你有没有可能有同时胜利的情况,如果有多张卡片有同时胜利的情况,输出字典序最小

我们很容易发现,两张卡片只要有一个数字相同就有可能同时胜利

但是在这相同的数字所在的两张卡片的两行还剩下8个数字,如果要想同时胜利,要先说这8个数,如果在这期间,有别的行或者卡片已经胜利了,那么这就不算同时胜利(这是这个题的思维所在)

实现的话...

其实这就是一道暴力题

9重循环吧,上代码

  1 /*
  2 加油,别忘记你写这段话时候的心情
  3 如临深渊,如履薄冰
  4 */
  5 //#include<bits/stdc++.h>
  6 #include<cstdio>
  7 #include<cstring>
  8 #include<vector>
  9 #include<algorithm>
 10 #include<cmath>
 11 #include<iostream>
 12 #include<queue>
 13 #include<set>
 14 #include<map>
 15 #include<string>
 16 using namespace std;
 17 typedef long long ll;
 18 typedef unsigned long long ull;
 19 const int maxn = 24;
 20 const ll INF = 2*1e18;
 21 
 22 int n;
 23 struct Begiocard
 24 {
 25     int num[6][6];
 26 };
 27 Begiocard mp[105];
 28 
 29 void Cincard(int x)
 30 {
 31     for(int i = 1; i <= 5; i++)
 32     {
 33         for(int j = 1; j <= 5; j++)
 34         scanf("%d",&mp[x].num[i][j]);
 35     }
 36 }
 37 
 38 bool judgec(int x,int y,int c1,int c2,int pos1,int pos2)//判断说其他数字时是否有其他行或者卡片已经胜利
 39 {
 40     set<int> s;
 41     for(int i = 1; i <= 5; i++)
 42     {
 43         if(i != pos1)
 44         {
 45             s.insert(mp[x].num[c1][i]);
 46         }
 47         if(i != pos2)
 48         {
 49             s.insert(mp[y].num[c2][i]);
 50         }
 51     }
 52     if(s.size() < 5) return false;
 53     for(int i = 1; i <= n; i++)
 54     {
 55         for(int j = 1; j <= 5; j++)
 56         {
 57             int cnt = 0;
 58             for(int k = 1; k <= 5; k++)
 59             {
 60                 if(s.count(mp[i].num[j][k])) cnt++;
 61             }
 62             if(cnt == 5) return true;
 63         }
 64     }
 65     return false;
 66 }
 67 
 68 bool judge(int x,int y,int c1,int c2)//判断两行是否有相同的数字
 69 {
 70     int pos1,pos2;
 71     for(int i = 1; i <= 5; i++)
 72     {
 73         pos1= i;
 74         for(int j = 1; j <= 5; j++)
 75         {
 76             if(mp[x].num[c1][i] == mp[y].num[c2][j])
 77             {
 78                 pos2 = j;
 79                 if(!judgec(x,y,c1,c2,pos1,pos2))
 80                 {
 81                     return true;
 82                 }
 83             }
 84         }
 85     }
 86     return false;
 87 }
 88 
 89 
 90 int main()
 91 {
 92     scanf("%d",&n);
 93     for(int i = 1; i <= n; i++)
 94     {
 95         Cincard(i);
 96     }
 97     int flag = 0;
 98     for(int i = 1; i < n; i++)
 99     {
100         for(int j = i+1; j <= n; j++)
101         {
102             for(int k = 1; k <= 5; k++)
103             {
104                 for(int c = 1; c <= 5; c++)
105                 {
106                     if(judge(i,j,k,c))
107                     {
108                         printf("%d %d\n",i,j);
109                         flag = 1;
110                         break;
111                     }
112                 }
113                 if(flag) break;
114             }
115             if(flag) break;
116         }
117         if(flag) break;
118     }
119     if(!flag) printf("no ties\n");
120     return 0;
121 }

Bingo is a game of chance played by a group of players. Each player has his or her own bingo card with a 55-by-55grid 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 55-by-55 grids with a number from 11 to 30003000 in each of the 2525 cells, and a winner is only declared when a player has 55 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:

31119429192523274543403142565049585468726163713294556681194350721125404961923315863427425471

148151062317262520393542314459555357526361716468142339596381735556115264253711025315764620445268

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 2540 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 2525 is called.

Input

The first line of the input is an integer nn (2n1002≤n≤100), the number of bingo cards. After the first line are the nn 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 11 to 30003000. 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 aa and bb (1a<bn1≤a<b≤n) identifying the two cards for which a tie could occur, where the cards are numbered from 11 to nn in the order that they appear in the input. If multiple pairs of cards can tie, output the pair with the smallest aa, breaking any remaining ties with the smallest bb.

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

Bingo is a game of chance played by a group of players. Each player has his or her own bingo card with a 55-by-55grid 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 55-by-55 grids with a number from 11 to 30003000 in each of the 2525 cells, and a winner is only declared when a player has 55 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:

31119429192523274543403142565049585468726163713294556681194350721125404961923315863427425471

148151062317262520393542314459555357526361716468142339596381735556115264253711025315764620445268

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 2540 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 2525 is called.

Input

The first line of the input is an integer nn (2n1002≤n≤100), the number of bingo cards. After the first line are the nn 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 11 to 30003000. 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 aa and bb (1a<bn1≤a<b≤n) identifying the two cards for which a tie could occur, where the cards are numbered from 11 to nn in the order that they appear in the input. If multiple pairs of cards can tie, output the pair with the smallest aa, breaking any remaining ties with the smallest bb.

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

猜你喜欢

转载自www.cnblogs.com/wxytxdy/p/10712102.html