题目:
商汤科技的行人检测(简单) - 计蒜客 A1218 - Virtual Judge (vjudge.net)
题面:
分析:
边输入边处理
用 cnt 来统计一个数的出现次数,当下一个数跟自己相同是 cnt++, 当不相同时 cnt-- 抵消
当 cnt 为 0 时更新当前的众数
最后的众数一定会让 cnt 为正数
代码:
#include <iostream>
using namespace std;
typedef long long LL;
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
LL T;
cin >> T;
LL cnt = 0, res_x = 0, res_y = 0;
LL x1, y1, x2, y2;
for (int i = 0; i < T; i++)
{
cin >> x1 >> y1 >> x2 >> y2;
if (cnt == 0)
{
res_x = x2 - x1, res_y = y2 - y1;
cnt++;
}
else if (res_x == x2 - x1 && res_y == y2 - y1) cnt++;
else cnt--;
}
cout << res_x << " " << res_y << endl;
return 0;
}
收获:
学到了求众数的方法