Features Track (STL瞎搞)

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 yi​ = yj, then <xi, yi​> <xj​, yj​> are same features.

So if cat features are moving, we can think the cat is moving. If feature <a, b> 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) , giving the test cases.

Then the first line of each cases contains one integer n (number of frames),

In The next nnn lines, each line contains one integer ki( the number of features) and 2ki​ intergers describe ki features in ith frame.(The first two integers describe the first feature, the 3rd and 4th integer describe the second feature, and so on).

In each test case the sum number of features N will satisfy N≤100000 .

Output

For each cases, output one line with one integers represents the longest length of features movement.

题意 

每个点是否不间断连续出现求连续出现的最大长度

题解 

用STL瞎搞一发,用map开两个状态,即当前状态和上一状态,如果上一状态某个点出现了,并且当前状态也出现了,那么次数加一,否则这个点继续从1开始计数,最后求一下最大的次数即可

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fLL
#define pi acos(-1.0)
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
//ll qpow(ll x, ll y, ll mod){ll s=1;while(y){if(y&1)s=s*x%mod;x=x*x%mod;y>>=1;}return s;}
ll qpow(ll a, ll b){ll s=1;while(b>0){if(b%2==1)s=s*a;a=a*a;b=b>>1;}return s;}

const int maxn = 1e6+5;

pair<int,int> p;
map<pair<int,int>,int>mp[2];

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

    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41021816/article/details/82562176