赞
踩
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; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。