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個視訊片段,每個片段有ki幀圖片<x,y>,問在n個片段中連續出現的圖片的最長長度是多少。【與該幀圖片出現的位置無關,只與出現在第幾個視訊中有關】

思路:將x,y,出現在第幾個視訊中pos進行排序。判斷相同的<x,y>是否連續和連續長度。

程式碼:

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
struct node
{
    int x,y;
    int pos;
} ff[maxn];
bool cmp(node&a,node&b)
{
    if(a.x==b.x&&a.y==b.y)return a.pos<b.pos;
    if(a.x==b.x)return a.y<b.y;
    return a.x<b.x;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int cnt=0;
        for(int v=0;v<n;v++)
        {
            int k;scanf("%d",&k);
            int a,b;

            for(int i=0;i<k;i++)
            {
                scanf("%d%d",&a,&b);
                ff[cnt].x=a;
                ff[cnt].y=b;
                ff[cnt].pos=v;
                cnt++;
            }
        }
        sort(ff,ff+cnt,cmp);
        int ans=1,num=1;
        for(int i=1;i<cnt;i++)
        {
            //printf("x=%d,y=%d,pos=%d\n",ff[i].x,ff[i].y,ff[i].pos);
            if(ff[i].x==ff[i-1].x&&ff[i].y==ff[i-1].y&&ff[i].pos==ff[i-1].pos+1)num++;
            else if(ff[i].x==ff[i-1].x&&ff[i].y==ff[i-1].y&&ff[i].pos==ff[i-1].pos);
            else num=1;

            ans=max(num,ans);
        }
        if(cnt==0)ans=0;
        printf("%d\n",ans);
    }
}