ACM-ICPC2018徐州网络赛 Features Track(二维map+01滚动)

Features Track

  •  31.32%
  •  1000ms
  •  262144K
 

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 <xx, yy>. If x_ixix_jxj and y_iyi = y_jyj, then <x_ixiy_iyi> <x_jxjy_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-4234 and 7-878.

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(1T10), 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_i2kiintergers 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 100000N100000 .

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 徐州赛区网络预赛

 

 

二维map记录当前行累积pair个数,因为只涉及到当前行与上一行的状态,因此采用01滚动map即可。

 

复制代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

map<int,map<pair<int,int>,int> > mp;
pair<int,int> p;

int main()
{
    int t,n,x,y,i,j,k;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        int ans=0,xxx=0;
        for(int i=0;i<n;i++){
            scanf("%d",&k);
            mp[xxx].clear();
            while(k--){
                scanf("%d%d",&x,&y);
                p = make_pair(x,y);
                if(mp[xxx^1].count(p)){
                    mp[xxx][p] = mp[xxx^1][p]+1;
                    ans=max(ans,mp[xxx][p]);
                }
                else{
                    mp[xxx][p]=1;
                    ans=max(ans,mp[xxx][p]);
                }
            }
            xxx^=1;
        }
        printf("%d\n",ans);
    }
    return 0;
}
复制代码

 

posted @   yzm10  阅读(483)  评论(0编辑  收藏  举报
编辑推荐:
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
阅读排行:
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(三):用.NET IoT库
· 【非技术】说说2024年我都干了些啥
点击右上角即可分享
微信分享提示