2019黑龙江大学生程序设计竞赛A

2019年黑龙江省赛A题

Problem A
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 262144/262144K (Java/Other)
Total Submission(s) : 183 Accepted Submission(s) : 37
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
WNJXYK and VineAsh are friends. They often play puzzle games together.
One day, WNJXYK found a very interesting puzzle game. At the beginning of this game, he had infinite pattern puzzles, all of which are exactly the same and each pattern puzzle could be considered as a number sequence P1,P2,…Pn. Meanwhile, he had another number sequence T1,T2,…,Tm which is his target. During this game, he could pick up a pattern puzzle and delete some numbers in it (Or don’t delete any number at all) in order to build a processed puzzle. His goal is to build some processed puzzles and concatenate them together to construct his target.
This game is so easy. To show off in front of VineAsh, WNJXYK wanted to do something harder. He decided to use minimum number of pattern puzzles to construct the target. Soon after, he realized that even though he found a solution he could not prove that the solution uses minimum number of pattern puzzles.
Therefore, WNJXYK wants you to tell him the minimum number of pattern puzzles he needs to use in order to construct the target.
Input
There are multiple test causes.
The first line of input contains an integer T, representing the number of test cases.
For each test case, the first line contains two integers n, m, indicating the length of pattern puzzle and the length of target. The second line contains a sequence with n integers P1,P2,…,Pn which is the pattern puzzle. The third line contains a sequence with m integers T1,T2,…,Tn which is the target.
Output
For each test case, output the answer which is the minimum number of pattern puzzles WNJXKY needs to use in a line.
I11 addition, if WNJXKY could not construct the target with pattern puzzles, please output −1.
Sample Input

3
3 5
11 22 33
11 22 33 11 22
3 6
1 2 3
3 2 1 3 2 1
5 5
1 2 3 4 5
1 2 3 4 6

Sample Output

2
5
-1

Hint
1 ≤ T ≤ 10
1 ≤ n, m ≤ 1e5
1 ≤ Pi, Ti ≤ 1e9
For the second sample, “3”+“2”+“1 3”+“2”+“1”=“3 2 1 3 2 1”


题目大意:回头补上
思路:回头补上

AC代码:

#include<bits/stdc++.h>
#define INF 0x3F3F3F3F
#define endl '\n'
#define css(n) cout<<setiosflags(ios::fixed)<<setprecision(n); 
using namespace std;
typedef long long ll;
const int maxn=1e5+50;
int n,m;
int t;
double a,b;
map<int,int> mp;
vector<int> vec[maxn];
int ans[maxn];
int main()
{
//	std::ios::sync_with_stdio(false);
	scanf("%d",&t);
	while(t--)
	{
		int k=1;
		mp.clear();
	//	cin>>n>>m;
	scanf("%d%d",&n,&m);
	/*	for(int i=0;i<maxn;i++)
		vec[i].clear();*/
	//	memset(ans,0,sizeof(ans));
		for(int i=1;i<=n;i++)
		{
			int a;
			cin>>a;
			if(!mp[a])
			{
				mp[a]=k++;
				vec[mp[a]].clear();
			}
			vec[mp[a]].push_back(i);
		}
		int fin=0;
		int pos=0;
		int flag=1;
		for(int i=1;i<=m;i++)
		{
			int a;
		//	cin>>a;
		scanf("%d",&a);
			if(!mp[a]) flag=0;
			else ans[i]=mp[a];
		}
		if(flag==0)
		{
		//	cout<<"-1"<<endl;
		printf("-1\n");
			continue;
		}
		else
		{
			int i=1;
			fin=0;
			while(i<=m)
			{
				fin++;
				int pos=vec[ans[i]][0];
				i++;
				while(i<=m)
				{
					vector<int>::iterator it;
				/*	int it=upper_bound(vec[ans[i]].begin(),vec[ans[i]].end(),pos)-vec[ans[i]].begin();
					if(it>=vec[ans[i]].size())
					{
						break;
					}
					pos=vec[ans[i]][it];*/
					it=upper_bound(vec[ans[i]].begin(),vec[ans[i]].end(),pos);
					if(it==vec[ans[i]].end())
					{
						break;
					}
					pos=*it;
					i++;
				}
			}
		}
	//	cout<<fin<<endl;
	printf("%d\n",fin);
	 } 
	return 0;
} 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值