POJ2302

简单题。

 1 #include<stdio.h>

 2 #include<string.h>

 3 #include<stdlib.h>

 4 #include<algorithm>

 5 using namespace std;

 6 const int maxn = 8;

 7 int mat[ maxn ][ maxn ];

 8 bool vis[ maxn ][ maxn ];

 9 bool appear[ 85 ];

10 struct node{

11     int x,y;

12 }num[ 105 ];

13 

14 void init(){

15     memset( appear,false,sizeof( appear ) );

16     memset( vis,false,sizeof( vis ) );

17     vis[3][3] = true;

18 }

19 

20 

21 bool judge(){

22     int cnt;

23     for( int i=1;i<=5;i++ ){

24         cnt = 0;

25         for( int j=1;j<=5;j++ ){

26             if( vis[i][j]==true )

27                 cnt++;

28             else

29                 break;

30         }

31         if( cnt==5 ) return true;//row

32         cnt = 0;

33         for( int j=1;j<=5;j++ ){

34             if( vis[j][i]==true )

35                 cnt++;

36             else

37                 break;

38         }

39         if( cnt==5 ) return true;//col

40     }

41     cnt = 0;

42     for( int i=1;i<=5;i++ )

43         if( vis[i][i]==true )

44             cnt++;

45         else

46             break;

47     if( cnt==5 ) return true;//dia

48     if( vis[1][5]==true&&vis[2][4]==true&&vis[4][2]==true&&vis[5][1]==true )

49         return true;

50     return false;

51 }

52 

53 int main(){

54     int n;

55     scanf("%d",&n);

56     while( n-- ){

57         init();

58         for( int i=1;i<=5;i++ ){

59             if( i!=3 ){

60                 for( int j=1;j<=5;j++ ){

61                     scanf("%d",&mat[i][j]);

62                     num[ mat[i][j] ].x = i;

63                     num[ mat[i][j] ].y = j;

64                     appear[ mat[i][j] ] = true;

65                 }

66             }

67             else{

68                 for( int j=1;j<=2;j++ ){

69                     scanf("%d",&mat[i][j]);

70                     num[ mat[i][j] ].x = i;

71                     num[ mat[i][j] ].y = j;

72                     appear[ mat[i][j] ] = true;

73                 }

74                 for( int j=4;j<=5;j++ ){

75                     scanf("%d",&mat[i][j]);

76                     num[ mat[i][j] ].x = i;

77                     num[ mat[i][j] ].y = j;

78                     appear[ mat[i][j] ] = true;

79                 }

80             }

81         }

82         int ans = 0;

83         int in_num;

84         bool flag = false;

85         //printf("input\n");

86         for( int i=1;i<=75;i++ ){

87             scanf("%d",&in_num);

88             if( flag==false ) ans++;

89             if( appear[ in_num ]==true ){

90                 vis[ num[ in_num ].x ][ num[ in_num ].y ] = true;

91                 if( judge()==true ){

92                     flag=true;

93                 }

94             }

95         }

96         printf("BINGO after %d numbers announced\n",ans);

97     }

98     return 0;

99 }
View Code

 

你可能感兴趣的:(poj)