题目链接:https://nanti.jisuanke.com/t/A2005
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 <xx, yy>. If x_ix
i
= x_jx
j
and y_iy
i
= y_jy
j
, then <x_ix
i
, y_iy
i
<x_jx
j
, y_jy
j
are same features.
So if cat features are moving, we can think the cat is moving. If feature <aa, bb> is appeared in continuous frames, it will form features movement. For example, feature <aa , bb > is appeared in frame 2,3,4,7,82,3,4,7,8, then it forms two features movement 2-3-42−3−4 and 7-87−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 \le T \le 10)T(1≤T≤10) , giving the test cases.
Then the first line of each cases contains one integer nn (number of frames),
In The next nn lines, each line contains one integer k_ik
i
( the number of features) and 2k_i2k
i
intergers describe k_ik
i
features in ith frame.(The first two integers describe the first feature, the 33rd and 44th integer describe the second feature, and so on).
In each test case the sum number of features NN will satisfy N \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
题目来源
ACM-ICPC 2018 徐州赛区网络预赛
分析:
假如是有间接的容器存次数的话,要注意下面这组数据
1
4
1 1 1
2 1 1 3 2
2 1 1 1 1
1 1 1
输出结果:4
代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <map>
#include<set>
using namespace std;
const int N=1e5+5;
#define p pair<int,int>
map<p,int> mp1;
map<int,int> mp2;
set<int> st[2];
int main()
{
int t;
int n;
int k;
int x,y;
scanf("%d",&t);
while(t--)
{
mp1.clear();
mp2.clear();
scanf("%d",&n);
int mx=0;
int cnt=1;
int cur=1;
st[0].clear();
st[1].clear();
for(int i=0;i<n;i++)
{
scanf("%d",&k);
cur^=1;
st[cur].clear();
for(int j=0;j<k;j++)
{
scanf("%d %d",&x,&y);
p w=make_pair(x,y);
if(mp1[w]<1)
{
mp1[w]=cnt++;
}
int ps=mp1[w];
if(st[cur^1].count(ps))
{
if(!st[cur].count(ps))
mp2[ps]+=1;
}
else
mp2[ps]=1;
st[cur].insert(ps);
mx=max(mx,mp2[ps]);
}
}
cout<<mx<<endl;
}
return 0;
}