本文主要是介绍CF——Game Outcome,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Game Outcome
Description
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.
Sample Input
1 1
0
2 1 2 3 4
2
4 5 7 8 4 9 5 3 2 1 6 6 4 9 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>
int main()
{
int n,i,j,m,k,sum;
int hh[50];
int lh[50];
int mapp[50][50];
scanf("%d",&n);
for(i = 0;i < n;i++)
{
sum = 0;
for(j = 0;j < n;j++)
{
scanf("%d",&mapp[i][j]);
sum += mapp[i][j];
}
hh[i] = sum;
}
for(i = 0;i < n;i++)
{
sum = 0;
for(j = 0;j < n;j++)
{
sum += mapp[j][i];
}
lh[i] = sum;
}
for(i = 0;i < n;i++)
{
for(j = 0;j < n-1-i;j++)
{
if(hh[j] < hh[j+1])
{
k = hh[j];
hh[j] = hh[j+1];
hh[j+1] = k;
}
}
}
int num = 0;
for(i = 0;i < n;i++)
{
m = lh[i];
for(j = 0;j < n;j++)
{
if(m > hh[j])
{
num = num + (n - j);
break;
}
}
}
printf("%d\n",num);
return 0;
}
这篇关于CF——Game Outcome的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!