F. Features Track
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 yiy_iyi = yjy_jyj, then <xi, yi> <xj, yj> are same features.
So if cat features are moving, we can think the cat is moving. If feature <aaa, bbb> 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−4and 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)T(1 \le T \le 10)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 kik_iki ( the number of features) and 2ki2k_i2ki intergers describe kik_iki features in ith frame.(The first two integers describe the first feature, the 333rd and 444th integer describe the second feature, and so on).
In each test case the sum number of features NNN will satisfy N≤100000N \le 100000N≤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
题目来源
解题思路:这题就是看点连续,本次出现的点在上一次也出现就加1,如果上次没出现就将本次的置为1,然后每次都选最大的。在比赛的时候看题没有看清楚,现在看看就在想当时怎么就没想到。。。
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
typedef pair<int,int> p;
map<p,int>m[maxn];
int main(void)
{
int t;
scanf("%d",&t);
while(t--)
{
int n,ans=0;
scanf("%d",&n);
for(int i=0;i<=maxn;i++)
m[i].clear();
for(int i=1;i<=n;i++)
{
int k;
scanf("%d",&k);
for(int j=0;j<k;j++)
{
int x,y;
scanf("%d%d",&x,&y);
if(!m[i-1].count({x,y}))
m[i][{x,y}]=1;
else m[i][{x,y}]=m[i-1][{x,y}]+1;
ans=max(ans,m[i][{x,y}]);
}
}
printf("%d\n",ans);
}
return 0;
}