Lucky Chances Gym 100801L

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值