598. Range Addition II的C++解法

本文介绍了一种解决二维矩阵更新问题的方法。通过遍历操作数组,找出所有操作后的最小宽度和高度,以此确定更新区域的大小。最终返回该区域面积作为答案。

因为是从(0,0)开始更新,所以只要找到最小的横纵坐标就可以了。注意处理ops为空的情况。

class Solution {
public:
	int maxCount(int m, int n, vector<vector<int>>& ops) {
		int min1 = m;
		int min2 = n;
		for (int i = 0; i < ops.size(); i++)
		{
			if (ops[i][0] < min1) min1 = ops[i][0];
			if (ops[i][1] < min2) min2 = ops[i][1];
		}
		return min1*min2;
	}
};

题解里的另一种写法:
class Solution {
public:
    int maxCount(int m, int n, vector<vector<int>>& ops) {
        for (auto op : ops) {
            m = min(op[0], m);
            n = min(op[1], n);
        }
        return m * n;
    }
};

The team Test just finished an exciting JB/ICPC competition. They are eager to know their ranking, but the board has been closed. So they can only guess their ranking by observing the submissions of other teams. Now let’s briefly introduce the rules of ranking. Each team has two statistics: the number of solved problems and penalty time. All teams are ranked according to their numbers of solved problems. If the numbers of solved problems of two different teams are equal, then they are ranked according to the penalty time. Each time a team passes a problem, the number of solved problems +1, and the time (in minutes) elapsed from the beginning of the competition is added to their penalty time. If a team has multiple submissions, each of the failed submissions will result in a 20 added to their penalty time. At the time when the competition lasts for four hours, the board will stop updating. In other words, the board is "frozen". After that, you can only see the submission status of other teams (the number of attempts, the time of the last submission), but you cannot see whether those submissions are accepted or not. In addition, the competition lasts for five hours in total. In particular, all teams will not submit solutions to the problem after getting an "Accepted". If two teams have the same number of solved problems and penalty time, then they are ranked the same. Please help the team Test guess the highest and lowest rankings they can reach based on the current board. The input contains several test cases, and the first line contains a positive integer indicating the number of test cases, . For each test case, the first line is a positive integer indicating the number of other teams, where . Then for each team, the first line are two integers and , where indicating the number of solved problems and indicating the penalty time of this team. The second line contains an integer indicating the submissions of problems of this team after the board is frozen. Then following lines, each line contains two positive integers and indicating the time of the last submission and the submit times of a problem of this team. Finally there is one line contains two integers and indicating the number of solved problems and the penalty time of the team Test. For each test case, output a line containing two positive integers indicating the highest and lowest rankings of the team Test. 输入样例 1 1 1 30 1 250 2 1 20 输出样例 1 2
12-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值