计蒜客 31458.Features Track-滚动数组+STL(map)连续计数 (ACM-ICPC 2018 徐州赛区网络预赛 F)
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这道题目的意思就是猫有动作,一共有n个画面,每个画面有多个动作,第i行的第一个数表示该画面有几个动作,每个动作由两个数来确定。问你连续的画面中出现次数最多的动作出现了几次。
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\n",maxx); 63 } 64 }
溜了溜了。。。