29 STL的应用pair , set , map, make_pair

  • F. Features Track 题库链接

    • 通过率: 88.66 %
    • 通过人数: 1087

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 <xxx, yyy>. If xix_ixi​ = xjx_jxj​ and yiy_iyi​ = yjy_jyj​, then <xix_ixi​, yiy_iyi​> <xjx_jxj​, yjy_jyj​> are same features.

So if cat features are moving, we can think the cat is moving. If feature <aaa, bbb> is appeared in continuous frames, it will form features movement. For example, feature <aaa , bbb > is appeared in frame 2,3,4,7,82,3,4,7,82,3,4,7,8, then it forms two features movement 2−3−42-3-42−3−4 and 7−87-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≤T≤10)T(1 \le T \le 10)T(1≤T≤10) , giving the test cases.

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

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

In each test case the sum number of features NNN will satisfy N≤100000N \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

题目来源

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

这道题目并不难就是一道线性dp但是如果你不会关于STL的一些骚操作的话这道题目就是很难做了,在之前的时候我一直都很讨厌STL因为我这个人比较保守不喜欢投机取巧,但是事实证明,这种东西有时候真的很有效;

set <数据类型> a: 这类似一个数组,但是当你插入一个数字的时候,它就给你自动排好序了,时间是log(n)的并且这个数组很特别有很多自身带有的操作,例如二分,查找等;

pair<数据类型, 数据类型> a :这个东西类似一个有两个特征值的结构体,并不是很常用,但是用到就会很省时间,类似这道题目,

make_pair<数据类型,数据类型>:这一个操作是有返回值的它的返回值是一个相对应的pair类型的数据;

map<数据类型,数据类型>: 这个是非常强大的,可以用来进行数据间的简单映射(左边的数据用有面的数据来代替),也可以用来统计某种类型数据的个数,

用来统计的数据类型可以是pair,string, int ,char ,double ,float, 右面的数值类型的话你可以根据自身的需要来解决;

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

typedef long long ll ;
const int inf =  0x3f3f3f3f;
const int mod =  1e9+7;
const int Max =  1e5+10;
ll n,m,w[Max];

#define rep(i,s,n) for(ll i=s;i<=n;i++)
#define per(i,n,s) for(ll i=n;i>=s;i--)
pair<int,int> it;//make_pair()返回的是一个pair类型的数据;
map<pair<int,int>,int> ma[Max];//map的作用是可以用来统计任意一种类型数据的个数;
//左面的第一个放的是我们要统计的那一种数据类型,右面的那个我们统计这种数据类型的个数
//数据类型,个数,
//这里我们开了一个数组表示的是有多少层这样的映射;
int main(){
   int t;
   scanf("%d",&t);
   while(t--){
    rep(i,0,Max-5) ma[i].clear();
    int n;
    scanf("%d",&n);
    int ans=0;
    rep(i,1,n){
      int k;
      scanf("%d",&k);
      rep(j,1,k){
        int x,y;
        scanf("%d %d",&x,&y);
        it=make_pair(x,y);//这里返回的是一个pair类型的数据;
        int num=ma[i-1][it];
        if(num==0){
            ma[i][it]=1;
        }
        else {
            ma[i][it]=ma[i-1][it]+1;
            ans=max(ans,ma[i][it]);
        }
      }
    }
    printf("%d\n",ans);
   }
   return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_39792342/article/details/82620003