【计蒜客】2018ICPC徐州赛区网络赛F Features Track(map、pair)

map,set对于关键字来说是唯一的

还有map的count用法

用来查找键是否存在

题目链接:

#include<vector>
#include<set>
#include<cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 100010
map<pair <int,int> ,int>mp[maxn];
//map<pair<int,int>,int>mp[maxn];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        int ans=0;
        scanf("%d",&n);
        for(int i=0;i<maxn;i++)//一定要记得清空
            mp[i].clear();
        for(int i=1;i<=n;i++)
        {
            int k;
            scanf("%d",&k);
            while(k--)
            {
                int x,y;
                scanf("%d%d",&x,&y);
                if(!mp[i-1].count({x,y}))
                    mp[i][{x,y}]=1;
                    else
                    mp[i][{x,y}]=mp[i-1][{x,y}]+1;
                    ans=max(ans,mp[i][{x,y}]);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42232118/article/details/82595204