(157A)
来源:互联网 发布:巨森网络 编辑:程序博客网 时间:2024/04/30 14:18
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 consideredwinning 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.
Sample Input
11
0
21 23 4
2
45 7 8 49 5 3 21 6 6 49 5 7 3
6
Hint
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 4953 2166 49 5 7 3
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <ctype.h> int main() { int n,i,j;int count,sum;int s[50][50];int hang[50];int lie[50];while(scanf("%d",&n)!=EOF){memset(s,0,sizeof(s));memset(hang,0,sizeof(hang));memset(lie,0,sizeof(lie));count=0;for(i=0;i<n;i++){for(j=0;j<n;j++)scanf("%d",&s[i][j]);}for(i=0;i<n;i++){sum=0;for(j=0;j<n;j++){sum+=s[i][j];}hang[i]=sum;}for(i=0;i<n;i++){sum=0;for(j=0;j<n;j++){sum+=s[j][i];}lie[i]=sum;}for(i=0;i<n;i++){for(j=0;j<n;j++){if(hang[i]<lie[j])count++;}}printf("%d\n",count);} return 0; }
- (157A)
- (a++) += (a++)和(++a)=(++a)+(a++)
- A*(A Star)算法
- (int &)a 和(int)a
- 寻路(AStar/A星/A*)算法
- a summary a week(1315)
- (int &)a 和(int)a
- 生成排列(next_permutation(a, a + n))
- 寻路(AStar/A星/A*)算法
- A星(A*)寻路算法
- A. Guess a number!(cf)
- const void *a和*(int*)a
- Unity3D A 星寻路(A*) C# 版本
- A*(A星)算法python实现
- (int&)a与*(int*)&a
- Unity3D A 星寻路(A*) C# 版本
- A-GPS(AssistedGPS)
- JS陷阱(A)
- 论MySQL何时使用索引,何时不使用索引
- 网络编程:Json解析
- CSS解决图片下面有空隙的简单方法
- linux 技巧:使用 screen 管理你的远程会话
- 面向对象的三大支柱:继承,封装,多态
- (157A)
- PHP 下载功能源码
- 第13周 《C++语言基础》程序阅读——多态性与抽象类 (4)
- 第十三周阅读项目(1):虚函数
- 葛教你如何成为顶尖互联网产品经理
- 指环王经典,励志篇
- InnoDB的三个关键特性
- Codeforces Round #305 (Div. 2)-Mike and Fun(暴力求解连续1)
- 《C Primer Plus(第5版)中文版》第6章编程练习第14题