AcWing 729. 特征提取
原题链接
中等
作者:
跟着灿哥学切菜
,
2021-02-09 09:42:30
,
所有人可见
,
阅读 454
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;
int main() {
int n;
cin >> n;
int res = 0;
map<PII, int> last_time, count;
for (int i = 1; i <= n; i ++) {
int m;
cin >> m;
//此时这种一对一对的读入方式需要来学习。
for (int j = 0; j < m; j ++) {
PII t;
cin >> t.first >> t.second;
//判断当前的这个点能否与上面的点连接起来
//如果可以接上, 就接上, 否则就是将长度设置为1
//此时需要来记录当前的这个特征的上一次的位置是在哪里? last_time[t] = i;
//同时需要记录的是从last_time往上, 最大的相同特征的长度是多少
if (last_time[t] == i -1) count[t] ++;
else if (last_time[t] < i - 1) count[t] = 1;
last_time[t] = i;
res = max(res, count[t]);
}
}
cout << res << endl;
return 0;
}