当前位置:   article > 正文

Lucky Chances Gym 100801L_problem a. lucky numbertimelimit : 2second, memory

problem a. lucky numbertimelimit : 2second, memorylimit : 1024megabytest

Problem L. Lucky Chances
Input file: lucky.in
Output file: lucky.out
Time limit: 2 seconds
Memory limit: 256 megabytes
Lucky Chances is a lottery game. Each lottery ticket has a play field and a scratch area. The play field
is a rectangular r × c field filled with numbers. The scratch area hides row and column numbers that
specify the bet cell.
There are four possible winning directions: up, down, left and right. You win a direction if all numbers
in this direction from the bet cell are strictly less than a number in the bet cell. And if the bet cell is on
the edge of the grid, you win the corresponding direction automatically!
5 3 9 10
1 8 8 2
4 3 4 3
Row
Column
Unscratched ticket
2
3
5 3 9 10
1 8 8 2
4 3 4 3
Row
Column
win
win
lose
lose
Scratched ticket 1
1
1
5 3 9 10
1 8 8 2
4 3 4 3
Row
Column
win
win
win
lose
Scratched ticket 2
Larry wants to choose the ticket that has maximum total number of winning directions for all possible
bet cells. Write a program that determines this number for the given grid.
Input
The first line of the input file contains two integers r and c — the number of rows and columns in the
grid (1 ≤ r, c ≤ 100).
The following r lines contain c integers each — the numbers printed on the grid. Each number is positive
and does not exceed 1000.
Output
Output a single integer w — the total number of winning directions for the given grid.
Example
lucky.in lucky.out
3 4
5 3 9 10
1 8 8 2
4 3 4 3
25

#include <iostream>
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
    freopen("lucky.in","r",stdin);
    freopen("lucky.out","w",stdout);

     int j,n,m,i,a[110][110];
     scanf("%d%d",&n,&m);
     for(i=1;i<=n;i++)
     {
         for(j=1;j<=m;j++)
         {
            scanf("%d",&a[i][j]);
         }
     }
     long long sum=0;
     for(i=1;i<=n;i++)
     {
        for(j=1;j<=m;j++)
        {

            int max1=a[i][j],f;
            f=1;
            for(int k=1;k<i;k++)
            {
                if(a[k][j]>=max1)
                    {
                    f=0;
                        break;
                    }
            }
            if(f==1)
            {
                sum++;}
            f=1;
            for(int k=i+1;k<=n;k++)
            {
                if(a[k][j]>=max1)
                {
                    f=0;
                    break;
                }
            }
            if(f==1)
                {
                sum++;}
                f=1;
            for(int k=1;k<j;k++)
            {
                if(a[i][k]>=max1)
                {
                    f=0;
                    break;
                }
            }
            if(f==1)
                {

                sum++;}
            f=1;
            for(int k=j+1;k<=m;k++)
            {
                if(a[i][k]>=max1)
                {
                    f=0;
                    break;
                }
            }
            if(f==1)
               {
                sum++;}

        }
     }
     printf("%lld\n",sum);
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/72376
推荐阅读
相关标签
  

闽ICP备14008679号