A. Game Outcome
来源:互联网 发布:软件开发培训班 编辑:程序博客网 时间:2024/05/20 18:53
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.
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.
Print the single number — the number of the winning squares.
11
0
21 23 4
2
45 7 8 49 5 3 21 6 6 49 5 7 3
6
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 49 5 3 21 6 6 49 5 7 3
解题说明:此题就是判断每一个位置的列之和和行之和数字大小
#include<cstdio>#include<iostream>#include<cstring>#include<cmath>using namespace std;int main(){int n,i,j;int row[31];int col[31];int a[31][31];int count;count=0;scanf("%d",&n);for(i=0;i<31;i++){row[i]=0;col[i]=0;}for(i=0;i<n;i++){for(j=0;j<n;j++){scanf("%d",&a[i][j]);row[i]+=a[i][j];col[j]+=a[i][j];}}for(i=0;i<n;i++){for(j=0;j<n;j++){if(row[i]<col[j]){count++;}}}printf("%d\n",count);return 0;}
- A. Game Outcome
- A. Game Outcome
- CodeForces 157A Game Outcome
- Game Outcome
- Game Outcome CodeForces
- CF——Game Outcome
- codeforces--C. Predict Outcome of the Game
- 451 C. Predict Outcome of the Game
- 451C - Predict Outcome of the Game
- Codeforces #258 (Div. 2) C. Predict Outcome of the Game
- Codeforces 451C Predict Outcome of the Game
- Codeforces 451C Predict Outcome of the Game(暴力)
- codeforces 258(Div.2) C. Predict Outcome of the Game
- Codeforces Div. 2 #258-C. Predict Outcome of the Game
- CodeForces 451 C. Predict Outcome of the Game
- Codeforces 451C. Predict Outcome of the Game
- CF 451 C Predict Outcome of the Game(数学题)
- Codeforces 451C Predict Outcome of the Game (枚举+YY)
- WPF 判断是否为设计(Design)状态
- 创建多媒体APP 之 音频播放:处理音频输出硬件
- linux C/C++编程基本操作
- js 知识总结
- Oracle创建用户、表空间、导入导出、...命令
- A. Game Outcome
- 清理你的目录,一条命令删除已从 tar rar 包解压出来的所有文件
- 【Android-Emulator】Android模拟器介绍和基本使用
- libtool : X--tag=CC: command not found 编译报错
- zoj3690(递推)
- C++笔记----explicit构造函数
- Kerberos (protocol)
- Top 10 Tools for a Free Online Education
- MyEclipse自动从种中抽取接口