本文主要是介绍ACM-ICPC 2018 徐州赛区网络赛 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_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_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 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 徐州赛区网络预赛
题意:
给了N个集合,每个集合都有许多的二维向量,如果存在一个向量在两个不同的集合中则可以看出是连续的。问最多有多少个连续的相等的集合。
思路:
将二维的向量哈希转化成数字存入集合中,判断每个元素连续出现的次数,判断完了之后就将这些元素删除,避免查找的时候会超时。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
set<ll> se[maxn];
set<ll> ::iterator it,itt;
int main()
{int t,n,k,x,y,ans;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&k);for(int j=1;j<=k;j++){scanf("%d%d",&x,&y);se[i].insert((ll)x*(100007)+y*(11));}}ans=0;for(int i=1;i<=n;i++){if(se[i].size()==0)continue;while((it=se[i].begin())!=se[i].end()){it=se[i].begin();int cnt=1;for(int j=i+1;j<=n;j++){if((itt=se[j].find(*it))!=se[j].end()){cnt++;se[j].erase(itt);}else{ans=max(ans,cnt);break;}}se[i].erase(it);}}printf("%d\n",ans);}return 0;
}
这篇关于ACM-ICPC 2018 徐州赛区网络赛 F. Features Track(哈希+暴力)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!