zoukankan      html  css  js  c++  java
  • 计蒜客 31458.Features Track-滚动数组+STL(map)连续计数 (ACM-ICPC 2018 徐州赛区网络预赛 F)

    F. Features Track

    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_i2ki intergers describe k_ikifeatures 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



    这道题目的意思就是猫有动作,一共有n个画面,每个画面有多个动作,第i行的第一个数表示该画面有几个动作,每个动作由两个数来确定。问你连续的画面中出现次数最多的动作出现了几次。
    其实就是给每个动作一个映射的值,用map保存一下就可以,写个pair,然后对于连续的操作,就用滚动数组就可以,因为只有两种状态,所以直接开个2的数组就可以。我是用二维map写的,里面内嵌的pair,其实用结构体代替pair就可以,因为我懒,所以用的pair。
    一开始写这道题的时候,因为数据感觉有点大,还想用hash来处理一下,结果发现,直接map硬怼就过了。。。
    具体代码写了注释(再也不敢不写注释了。。。)
     
    代码:
     1 //F-滚动数组+map连续计数
     2 #include<iostream>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<bitset>
     7 #include<cassert>
     8 #include<cctype>
     9 #include<cmath>
    10 #include<cstdlib>
    11 #include<ctime>
    12 #include<deque>
    13 #include<iomanip>
    14 #include<list>
    15 #include<map>
    16 #include<queue>
    17 #include<set>
    18 #include<stack>
    19 #include<vector>
    20 using namespace std;
    21 typedef long long ll;
    22 
    23 const double PI=acos(-1.0);
    24 const double eps=1e-6;
    25 const ll mod=1e9+7;
    26 const int inf=0x3f3f3f3f;
    27 const int maxn=1e5+10;
    28 const int maxm=1e3+10;
    29 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    30 
    31 map<pair<int,int>,int> mp[2];
    32 map<pair<int,int>,int>p;
    33 
    34 int main()
    35 {
    36     int t;
    37     scanf("%d",&t);
    38     while(t--){
    39         int n;
    40         scanf("%d",&n);
    41         int maxx=-1;
    42         for(int i=0;i<n;i++){
    43             int k;
    44             scanf("%d",&k);
    45             int t1=i%2;//因为只有两种状态,当前和上一个,所以直接%2就可以
    46             int t2=(i+1)%2;
    47             mp[t1].clear();//清空
    48             p.clear();
    49             for(int j=0;j<k;j++){
    50                 int u,v;
    51                 scanf("%d%d",&u,&v);
    52                 if(p[make_pair(u,v)]==0){//如果在当前画面中该动作还没出现,就标记一下
    53                     p[make_pair(u,v)]=1;
    54                     if(mp[t2][make_pair(u,v)]!=0)//如果当前动作在上一个画面中出现过
    55                         mp[t1][make_pair(u,v)]=mp[t2][make_pair(u,v)]+1;//直接上一个状态+1
    56                     else
    57                         mp[t1][make_pair(u,v)]++;//如果出现过了,直接++
    58                     maxx=max(maxx,mp[t1][make_pair(u,v)]);//找一下最大值
    59                 }
    60             }
    61         }
    62         printf("%d
    ",maxx);
    63     }
    64 }

    溜了溜了。。。

  • 相关阅读:
    微信公众平台开发学习系列(四):微信分享内容修改与分享之后才能访问某页面
    微信公众平台开发学习系列(三):网页授权获取用户基本信息
    微信公众平台开发学习系列(二):微信公众平台接收消息与发送消息
    微信公众平台开发学习系列(一):公众平台测试号申请与自定义菜单创建
    EF结合SqlBulkCopy在项目中的使用
    用python实现【五猴分桃】问题
    基于pandas进行数据预处理
    【转载】各类排序算法的对比及实现
    牛客网2017校招真题在线编程之合唱团问题——动态规划问题首秀
    动态规划(DP)算法
  • 原文地址:https://www.cnblogs.com/ZERO-/p/9622790.html
Copyright © 2011-2022 走看看