ACM-ICPC 2018 徐州赛区网络预赛 Features Track(STL二维map)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yu121380/article/details/82591465

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 <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,8then it forms two features movement 2-3-4 and 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 nn (number of frames),

In The next nn 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 33rd and 44th integer describe the second feature, and so on).

In each test case the sum number of features N will satisfyN≤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 徐州赛区网络预赛

【题目大意】有N个帧,每帧有K个动作特征,每个特征用一个向量表示(x,y)。两个特征相同当且仅当他们在不同的帧中出现且向量的两个分量分别相等。求最多连续相同特征的个数?

【题解】用一个map来维护帧中特征的信息,map中的键即读入的向量,因此用一个pair<int , int>表示,键的值也是一个pair,需要记录它当前已经连续了多少次,还需要记录它上一次出现的帧的位置。如果它上一帧没有出现过,那么它的连续次数就要被置成1;如果上次出现了,则继续累加。用ans维护某个键最大连续出现次数。

map<pair<int ,int> , pair<int ,int>>

map[ pair(x,y)].first为该特征(x.y)连续次数  

map[ pair(x,y)].second为该特征上一次出现的帧序号,用于下一次判断连续性

#include<bits/stdc++.h>
using namespace std;

#define e exp(1)
#define pi acos(-1)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b){return b?gcd(b,a%b):a;}

typedef pair<int,int> pii;
map<pii,pii> mp;
int main()
{
	int T;scanf("%d",&T);
	while(T--)
	{
		int n;scanf("%d",&n);
		int ans=-1;
		for(int i=1; i<=n; i++)
		{
			int k;scanf("%d",&k);
			for(int j=1; j<=k; j++)
			{
				int x,y;scanf("%d%d",&x,&y);
				if(mp[pii(x,y)].second==i-1)
					mp[ pii(x,y) ].first++;
                else if(mp[pii(x,y)].second==i)
					continue;
                else mp[ pii(x,y) ].first = 1;
                
                ans=max(ans,mp[pii(x,y)].first);
                mp[pii(x,y)].second=i;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/yu121380/article/details/82591465