D - Game Outcome

Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board’s squares by some tricky rules we don’t know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number of winning squares. To determine if the particular square is winning you should do the following. Calculate the sum of all numbers on the squares that share this column (including the given square) and separately calculate the sum of all numbers on the squares that share this row (including the given square). A square is considered winning if the sum of the column numbers is strictly greater than the sum of the row numbers.

For instance, lets game was ended like is shown in the picture. Then the purple cell is winning, because the sum of its column numbers equals 8 + 3 + 6 + 7 = 24, sum of its row numbers equals 9 + 5 + 3 + 2 = 19, and 24 > 19.

Input

The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.

Output

Print the single number — the number of the winning squares.

Examples
Input

1
1

Output

0

Input

2
1 2
3 4

Output

2

Input

4
5 7 8 4
9 5 3 2
1 6 6 4
9 5 7 3

Output

6

Note

In the first example two upper squares are winning.

In the third example three left squares in the both middle rows are winning:
5 7 8 4
9 5 3 2
1 6 6 4
9 5 7 3

本题主要是每一列的和与每一列行的和作比较,大于就加一。刚开始看这道题的时候会有一些乱,但后来把思路理清后,做起来容易了很多,所以总结到了一个经验就是在开始打代码之前,一定要把思路弄明白,这样做题才能不浪费时间。
代码如下:

#include"stdio.h"
#include"cstring"
#include"algorithm"
using namespace std;
int main()
{
	int n;
	int b[101];
	int c[102];
	int a[150][150];
	while(~scanf("%d",&n))
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(c,0,sizeof(c));
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				scanf("%d",&a[i][j]);
				b[i] += a[i][j];
			}
		 } 
		 
		 for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				c[i] += a[j][i];
				
			}	 
		 }
		 int sum=0;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(c[j]>b[i])
				{
					sum ++;
				}
			}	 
		 }
		printf("%d\n",sum);
	}
	return 0;
 } 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值