本文主要是介绍ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- 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 <x, y>. If xi=xj and yi = yj, then <xi, yi> <xj,yj> are same features.
So if cat features are moving, we can think the cat is moving. If feature <a, b> is appeared in continuous frames, it will form features movement. For example, feature <a,b> is appeared in frame 2,3,4,7,8 then it forms two features movement 2-3-4 and 7-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≤T≤10) , giving the test cases.
Then the first line of each cases contains one integer n (number of frames),
In The next n lines, each line contains one integer ki ( the number of features) and 2ki intergers describe ki features in ith frame.(The first two integers describe the first feature, the 3rd and 4th integer describe the second feature, and so on).
In each test case the sum number of features N will satisfy N≤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个区域,每个区域有k个点(x,y)。各点(x,y)出现的区域中最长的连续区域的长度的最大值
比如,
1 //1组测试
8 //8个区域
2 1 1 2 2 //区域1两个点 (1,1) (2,2)
2 1 1 1 4 //区域2两个点 (1,1) (1,4)
2 1 1 2 2 //区域3两个点 (1,1) (2,2)
2 2 2 1 4 //区域4两个点 (2,2) (1,4)
0 //区域5零个点
0 //区域6零个点
1 1 1 //区域7一个点 (1,1)
1 1 1 //区域8一个点 (1,1)
点(1,1)出现在区域1,2,3,7,8 最长的连续区域为1-2-3长度为3
点(2,2)出现在区域1,3,4 最长的连续区域为3-4长度为2
点(1,4)出现在区域2,4最长的连续区域为2或4长度为1
因此最后答案为3
题解:将二维坐标用一个数表示,由于x+y的值小于等于100000,因此可以将(x,y)用数 z=x*100001+y 表示,其中x=z/100000 ,y=z%100000 。使用映射map<int,int>s[2],键表示位置坐标化成的整数,值表示以此区域的这个点结尾的最长连续区间的长度,s[0]记录上一个区间的点信息,s[1]记录本区间的点信息,由于要连续,因此如果本区域出现了上一个区域没有出现的点,那么本区域以这个点结尾的最长连续区间的长度为1,否则为上一个区域相同结点的对应的值加一,每次记录最大值即可。
AC的C++代码:
#include<iostream>
#include<map>using namespace std;
typedef long long ll;ll mod=100001;
map<ll,ll>s[2];//记录上一个区域和此区域的结点信息 int main()
{int t,r,n,x,y,num;scanf("%d",&t);while(t--){s[0].clear();s[1].clear();ll ans=0;scanf("%d",&r);for(int i=1;i<=r;i++){s[i%2].clear();scanf("%d",&num);for(int j=1;j<=num;j++){scanf("%d%d",&x,&y);ll pos=x*mod+y;//将本区域的点位置化成1维的数 s[i%2][pos]=+s[(i-1)%2][pos]+1;if(ans<s[i%2][pos])//更新答案 ans=s[i%2][pos];}s[(i-1)%2].clear();//清空上一个区域的结点信息 }printf("%lld\n",ans);}return 0;
}
这篇关于ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!