ACM-ICPC 2018 徐州赛区网络预赛 Feature 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_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

题目来源

扫描二维码关注公众号,回复: 3957305 查看本文章

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

 先说题意,首先是t组数据,每组数据第一行是一个n,接下来有n行,每行最开始有一个数x代表这一行有x对数,接下来有x

对数(两个数字为一对)。

题目问在这n

行之中,连续出现次数最大的那一对数出现的次数。

比如第一个样例(1,1)这一对连续出现了3次。

我们首先把这个问题从一个数对转化成一个数字,那么问题会转化成这么一个问题:给你一串数字,求这串数字中连续出现的数字次数的最大值。

那么我们很容易能想一种dp的解法,令dp[i][j]表示前i个数字中j这个数字出现的最大次数,然后dp[i][j]=dp[i-1][j]+1,然后取一个最大值即可。

那么对于这个问题,只不过是把数字转化成了数对,我们可以利用map来处理一下这个数对,map<pair<int,int>,int>mp,这样就可以把一个数对映射成为一个数字,接下来因为数据范围较大,有105

,我们用到的状态只有当前状态和前一个状态,所以可以利用滚动数组优化一下。

#include "bits/stdc++.h"
using namespace std;
#include <map>
#define rep(i,j,k) for(int i=j;i<=k;i++)
//特别疑惑一点,如果把using namespace std放到下面就会报,没有pair这个类型的错误,求教?
typedef pair<int,int> pir;//像这个类型里是包括了命名空间的,所有不能放到前面
map<pir,int> mp[2];



int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,max1=0;
		int cur=0;
		cin>>n;
		mp[0].clear();
		mp[1].clear();
		rep(i,1,n)
		{
			int m;
			cin>>m;
			cur^=1;//滚动数组,关键在于使用map这个数据结构
			mp[cur].clear();
			rep(j,1,m)
			{
				int a,b;
				scanf("%d%d",&a,&b);
				pir tmp=make_pair(a,b);
				mp[cur][tmp]=mp[cur^1][tmp]+1;
				if(max1<=mp[cur][tmp])
				{
					max1=	mp[cur][tmp];
			}
			}
		}
		cout<<max1<<endl;
	}
	return 0;
}

上面命名空间问题已解决

使用命名空间的目的是对标识符的名称进行本地化,以避免命名冲突。

在C++中,变量、函数和类都是大量存在的。如果没有命名空间,这些变量、函数、类的名称将都存在于全局命名空间中,会导致很多冲突。比如,如果我们在自己的程序中定义了一个函数toupper(),这将重写标准库中的toupper()函 数,这是因为这两个函数都是位于全局命名空间中的。命名冲突还会发生在一个程序中使用两个或者更多的第三方库的情况中。此时,很有可能,其中一个库中的名 称和另外一个库中的名称是相同的,这样就冲突了。这种情况会经常发生在类的名称上。比如,我们在自己的程序中定义了一个Stack类,而我们程序中使用的某个库中也可能定义了一个同名的类,此时名称就冲突了。

Namespace 关键字的出现就是针对这种问题的。由于这种机制对于声明于其中的名称都进行了本地化,就使得相同的名称可以在不同的上下文中使用,而不会引起名称的冲突。或许命名空间最大的受益者就是C++中的标准库了。在命名空间出现之前,整个C++库都是定义在全局命名空间中的(这当然也是唯一的命名空间)。引入命名空间后,C++库就被定义到自己的名称空间中了,称之为std。这样就减少了名称冲突的可能性。我们也可以在自己的程序中创建自己的命名空间,这样可以对我们认为可能导致冲突的名称进行本地化。这点在我们创建类或者是函数库的时候是特别重要的。

C++标准程序库中的所有标识符都被定义于一个名为std的namespace中。 
namespace是指标识符的各种可见范围。命名空间用关键字namespace 来定义。命名空间是C++的一种机制,用来把单个标识符下的大量有逻辑联系的程序实体组合到一起。此标识符作为此组群的名字。

C++标准程序库中的所有标识符都被定义于一个名为std的namespace中。 由于namespace的概念,使用C++标准程序库的任何标识符时, 

#include "bits/stdc++.h"
#include "vector"
#include "map"
#include "algorithm"
#include "string"
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
//从小到大排序 
void quickSort(int left,int right ,int *a)
{
	if(left>right)
	return;
	int i=left,j=right;
	int cur=a[left];
	while(i!=j)
	{
		while(a[j]>=cur&&i<j)
		j--;
		while(a[i]<=cur&&i<j)
		i++;
		if(i<j)
		swap(a[i],a[j]);
	}
	a[left]=a[i];//最后i和j相遇肯定有且仅有一种情况 
	a[i]=cur;
	quickSort(left,i-1,a);
	quickSort(i+1,right,a);
}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		int a[100];
		cin>>n;
		rep(i,0,n-1)
		{
			scanf("%d",a+i);
		}
		quickSort(0,n-1,a);
		rep(i,0,n-1)
		{
			cout<<a[i]<<" ";
		}
		
	}
	return 0;
}

https://github.com/zhblue/hustoj,网上oj 开源代码

#include "stdio.h"
const int maxn = 10000;
int a[maxn];
int  main()
{
	int n;
	scanf("%d",&n);
	a[0]=1;
	for(int i=2;i<=n;i++)
	{
		int cur=0;
		for(int j=0;j<=maxn-1;j++)
		{
			cur+=a[j]*i;
			a[j]=cur%10;
			cur/=10;
		}
	}
	int i;
	for(i=maxn-1;i>=0;i--)
	{
		if(a[i]!=0)
		{
			break;
		}
	}
	for(int j=i;j>=0;j--)
	{
		printf("%d",a[j]);
	}
	return 0;
}

 大数阶乘

猜你喜欢

转载自blog.csdn.net/weixin_41466575/article/details/82780037