1. 程式人生 > >ACM-ICPC 2018 徐州賽區網路賽 F. Features Track(雜湊+暴力)

ACM-ICPC 2018 徐州賽區網路賽 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 <xx, yy>. If x_ixi​= x_jxj​ and y_iyi​ = y_jyj​, then <x_ixi​, y_iyi​> <x_jxj​, y_jyj​> 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_iki​ ( the number of features) and 2k_i2ki​ intergers describe k_iki​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

題目來源

題意:

給了N個集合,每個集合都有許多的二維向量,如果存在一個向量在兩個不同的集合中則可以看出是連續的。問最多有多少個連續的相等的集合。

思路:

將二維的向量雜湊轉化成數字存入集合中,判斷每個元素連續出現的次數,判斷完了之後就將這些元素刪除,避免查詢的時候會超時。

程式碼:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
set<ll> se[maxn];
set<ll> ::iterator it,itt;
int main()
{
    int t,n,k,x,y,ans;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&k);
            for(int j=1;j<=k;j++)
            {
                scanf("%d%d",&x,&y);
                se[i].insert((ll)x*(100007)+y*(11));
            }
        }
        ans=0;
        for(int i=1;i<=n;i++)
        {
            if(se[i].size()==0)
                continue;
            while((it=se[i].begin())!=se[i].end())
            {
                it=se[i].begin();
                int cnt=1;
                for(int j=i+1;j<=n;j++)
                {
                    if((itt=se[j].find(*it))!=se[j].end())
                    {
                        cnt++;
                        se[j].erase(itt);
                    }
                    else
                    {
                        ans=max(ans,cnt);
                        break;
                    }
                }
                se[i].erase(it);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}