Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat movement from a cat video. To do this, he extracts cat features in each frame. A cat feature is a two-dimension vector <x, y>. If xi = xj and yi = yj, then <xi, yi><xj, yj> are same features.
So if cat features are moving, we can think the cat is moving. If feature <a, b> is appeared in continuous frames, it will form features movement. For example, feature <a , b > is appeared in frame 2,3,4,7,8 then it forms two features movement 2−3−4 and 7−8 .
Now given the features in each frames, the number of features may be different, Morgana wants to find the longest features movement.
Input
First line contains one integer T(1≤T≤10) , giving the test cases.
Then the first line of each cases contains one integer nnn (number of frames),
In The next nnn lines, each line contains one integer ki ( the number of features) and 2ki intergers describe ki features in ith frame.(The first two integers describe the first feature, the 3rd and 4th integer describe the second feature, and so on).
In each test case the sum number of features N will satisfy N≤100000 .
Output
For each cases, output one line with one integers represents the longest length of features movement.
样例输入
1 8 2 1 1 2 2 2 1 1 1 4 2 1 1 2 2 2 2 2 1 4 0 0 1 1 1 1 1 1
样例输出
3
题目来源
题解:
两个map滚动就行了。具体的看代码一看就懂。
代码:
/*F*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
using namespace std;
map<pair<int,int>,int> MMP[2];
map<pair<int,int>,int>::iterator it;
int main(){
int T,N;
scanf("%d",&T);
pair<int,int> P;
while(T--){
int ma = 0;
scanf("%d",&N);
int NUM;
for(int i=1; i<=N ; ++i){
int tt = i%2;
scanf("%d",&NUM);
for(int j=1 ; j<=NUM ; ++j){
scanf("%d %d",&P.first,&P.second);
it = MMP[tt].find(P);
if(it != MMP[tt].end()){
MMP[tt^1][P] = MMP[tt][P] + 1;
}
else MMP[tt^1][P] = 1;
if(ma < MMP[tt^1][P])ma = MMP[tt^1][P];
}
MMP[tt].clear();
}
printf("%d\n",ma);
}
return 0;
}