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

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

题目链接:https://nanti.jisuanke.com/t/31458

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_ixi​ = x_jxj​and y_iyi​ = y_jyj​, then <x_ixi​, y_iyi​> <x_jxj​, y_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-42−3−4 and 7-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 \le T \le 10)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 k_iki​ ( the number of features) and 2k_i2ki​ intergers 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 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

题解:这题主要是要看懂题意,相当于就是一个坐标连续在每一行中出现的次数,比如样例中的 (1 , 1) 在第 1、2、3行连续出现,出现次数为 3 。而其他的坐标比如 (2, 2) 它连续出现的次数为 2 ,在第 3、4行中连续出现。然后取出现次数的最大值即可。这就很简单了。。。哈哈

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
const int maxn=100010;
int t, n;
struct node{
    int x, y;
    int cnt;
}a[maxn];
int k[maxn];
int main()
{
    scanf("%d", &t);
    while(t--){
        memset(a, 0, sizeof a);
        scanf("%d", &n);
        int ans = 0;
        int id = 0;
        for(int i=1;i<=n;i++){
            scanf("%d", &k[i]);
            int x, y, cnt = 0, index = -1;
            int r = id;
            for(int j=0;j<k[i];j++){
                scanf("%d %d",&x, &y);
                cnt=1;
                for(int l = r-k[i-1]; l < r; l++){//扫描上一行中的坐标
                    if(x == a[l].x && y == a[l].y){//如果有相同的,就累加上一行中该坐标           已经出现的次数
                        cnt += a[l].cnt;
                        break;
                    }
                }
                a[id].x = x, a[id].y = y;
                a[id].cnt += cnt;
                ans = max(ans, cnt);
                id++;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37867156/article/details/82587598