ACM-ICPC 2018 徐州赛区网络预赛F

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 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

1组测试实例,8行,每一行第一个是说当前行有几个点

如果当前行中和上一行有相同点,说明这个点连续,

那么求最大的连续次数(例如示例中1,1点连续3次,所以输出3)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Node{
    int x,y;
    bool operator < (const Node &a) const{
        if(x!=a.x)
            return x<a.x;
        return y<a.y;
    }
};
map<Node,int> M[2];
int main()
{
    int t,n,m,x,y;
    scanf("%d",&t);

    while(t--)
    {
        scanf("%d",&n);
        int ans = 0,flag = 0;
        for(int i=0;i<n;i++)
        {
            M[flag].clear();
            scanf("%d",&m);
            if(!m)
                continue;
            while(m--)
            {
                scanf("%d%d",&x,&y);
                Node P;
                P.x = x;
                P.y = y;
                if(M[!flag].count(P))
                {
                    M[flag][P] = M[!flag][P]+1;
                    ans = max(ans,M[flag][P]);
                }
                else
                    M[flag][P]=1,ans = max(ans,M[flag][P]);
            }
            flag = !flag;
        }
        printf("%d\n",ans);
    }

    return 0;
}

好吧,被发现了小bug,已改正,是上面continue的问题

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Node{
    int x,y;
    bool operator < (const Node &a) const{
        if(x!=a.x)
            return x<a.x;
        return y<a.y;
    }
};
map<Node,int> M[2];
int main()
{
    int t,n,m,x,y;
    scanf("%d",&t);

    while(t--)
    {
        scanf("%d",&n);
        int ans = 0,flag = 0;
        for(int i=0;i<n;i++)
        {
            M[flag].clear();
            scanf("%d",&m);
            while(m--)
            {
                scanf("%d%d",&x,&y);
                Node P;
                P.x = x;
                P.y = y;
                if(M[!flag].count(P))
                {
                    M[flag][P] = M[!flag][P]+1;
                    ans = max(ans,M[flag][P]);
                }
                else
                    M[flag][P]=1,ans = max(ans,M[flag][P]);
            }
            flag = !flag;
        }
        printf("%d\n",ans);
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/Du_Mingm/article/details/82562015