CodeForces 157A Game Outcome
2016-05-07 07:47
387 查看
A. Game Outcome
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Examples
input
output
input
output
input
output
6
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Examples
input
1 1
output
0
input
2 1 2 3 4
output
2
input
4
5 7 8 4
9 5 3 21 6 6 4
9 5 7 3
output
6
#include <iostream> #include <string.h> #include <stdlib.h> #include <algorithm> #include <math.h> #include <stdio.h> using namespace std; int r[35]; int l[35]; int a[35][35]; int n; int main() { scanf("%d",&n); memset(r,0,sizeof(r)); memset(l,0,sizeof(l)); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { scanf("%d",&a[i][j]); } } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { r[i]+=a[i][j]; l[i]+=a[j][i]; } } int num=0; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(l[j]>r[i]) num++; } } printf("%d\n",num); return 0; }
相关文章推荐
- win7任务栏图标显示异常的解决方法
- 动态链接库DLL的加载:隐式加载(载入时加载)和显式加载(运行时加载)
- HDU 3578 Greedy Tino(双塔DP)
- 第一个DLL程序:动态链接库DLL教程,30分钟快速上手
- HDU 3578 Greedy Tino(双塔DP)
- POJ 2609 Ferry Loading(双塔DP)
- POJ 2609 Ferry Loading(双塔DP)
- 最小-最大计划报表-无法生成申请
- setContentView( )方法
- 数据科学家应该掌握的12种机器学习算法
- 吃了程序员这碗青春饭 40岁你该怎么办?
- setContentView( )方法
- 月入十万真的难吗?
- POJ 1015 Jury Compromise(双塔DP)
- POJ 1015 Jury Compromise(双塔DP)
- 用浏览器(支持WebSocket)和node-inspector 调试后端(CoffeeScript,Typescript)代码
- 持续交付之一——软件交付的问题
- Adb connection Error:远程主机强迫关闭了一个现有的连接
- 【BZOJ-4524】伪光滑数 堆 + 贪心 (暴力) [可持久化可并堆 + DP]
- sass/scss 和 less的区别