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 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 test(s)
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<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;
}


The programme should have the following features: ● A menu including Open and Exit where Open starts a JFileChooser to select the file with the questions inside and Exit ends the programme. ● Once a file is loaded, the GUI should display one question and its answers at a time. ● The user should be able to select an answer and they should be informed if they were correct or not. ● The user should be made aware of the number of correctly answered and the total number of questions answered. ● The user should only be able to proceed to the next question once they answered the current one. ● Once all questions have been answered, the user should be informed of their overall score and that the game has finished. The Open menu item should now be enabled to start a new quiz. Optionally, you can add a restart menu item to redo the current quiz. Concrete sub-tasks: a) define a class called Question to hold a single question, i.e. the text, the possible answers, and the correct answer index; (0.25P) b) write a method to select a file via a JFileChooser and to read all the questions from that file into an array/list of Question objects (assume that file has the structure mentioned above); (0.25P) c) design and implement a GUI with the components mentioned above: A menu, ability to display the question and answers, ability to select an answer, show the outcome and score, and proceed to the next question. (Appropriate layout: 1P, Class extends JFrame: 0.25P, Class follows OOP principles: 0.25P, Global set-up in main method: 0.25P)1 d) write a method to display a question on the GUI you designed; (0.25P) e) implement an actionPerformed method to respond to user interactions with the GUI. Make sure to enable and disable interactive components as required, e.g. the user should not be able to skip to the next question without selecting an answer first and they should not be able to load a new quiz before finishing the current one;
05-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值