poj 4044 Score Sequence(暴力)

http://poj.org/problem?id=4044

大致题意:给出两个班级的成绩,先按降序排序,并且没有成绩相同的。然后求连续的最长公共子序列。输出时,先输出最长公共子序列,然后按个位数字递增的顺序输出,若各位数字一样就按成绩递增。

人数小于30,注意去重,直接暴力即可。

#include <stdio.h>
#include <iostream>
#include <map>
#include <stack>
#include <vector>
#include <math.h>
#include <string.h>
#include <queue>
#include <string>
#include <stdlib.h>
#include <algorithm>
#define LL long long
#define _LL __int64
#define eps 1e-8
#define PI acos(-1.0)
using namespace std;

const int maxn = 32;
int n1,n2;
int a[maxn],b[maxn],aa[maxn],bb[maxn];

int cmp(int a, int b)
{
	return a > b;
}

struct node
{
	int num;
	int dig;

	bool operator < (const struct node &tmp)const
	{
		if(dig == tmp.dig)
			return num < tmp.num;
		return dig < tmp.dig;
	}
}ans[maxn];

bool judge(int s1, int s2, int len)
{
	int k;
	for(k = 0; k < len; k++)
	{
		if(a[s1+k] != b[s2+k])
			break;
	}
	if(k < len)
		return false;
	return true;
}

int main()
{
	int test;
	scanf("%d",&test);
	while(test--)
	{
		int i,j,t;
		scanf("%d %d",&n1,&n2);
		for(i = 0; i < n1; i++)
			scanf("%d",&aa[i]);
		for(i = 0; i < n2; i++)
			scanf("%d",&bb[i]);

		sort(aa,aa+n1,cmp);
		sort(bb,bb+n2,cmp);

		a[0] = aa[0];
		t = 1;
		for(i = 1; i < n1;)
		{
			while(aa[i] == aa[i-1] && (i+1) < n1)
				i++;
			if(aa[i] != aa[i-1])
				a[t++] = aa[i++];
			else break;
		}
		n1 = t;

		b[0] = bb[0];
		t = 1;
		for(i = 1; i < n2; )
		{
			while(bb[i] == bb[i-1] && (i+1) < n2)
				i++;
			if(bb[i] != bb[i-1])
				b[t++] = bb[i++];
			else break;
		}
		n2 = t;

		int len = 0;
		int cnt;

		for(i = 0; i < n1; i++)
		{
			for(j = 0; j < n2; j++)
			{
				for(int k = 1; k <= min(n1-i,n2-j); k++)
				{
					if(judge(i,j,k) && len < k)
					{
						len = k;
						cnt = 0;
						for(int g = 0; g < k; g++)
							ans[cnt++] = (struct node){a[i+g],a[i+g]%10};
					}
				}
			}
		}

		if(len == 0)
		{
			printf("NONE\n");
			continue;
		}

		for(int i = 0; i < cnt-1; i++)
			printf("%d ",ans[i].num);
		printf("%d\n",ans[cnt-1].num);

		sort(ans,ans+cnt);
		for(i = 0; i < cnt-1; i++)
			printf("%d ",ans[i].num);
		printf("%d\n",ans[cnt-1].num);

	}
	return 0;
}

poj 4044 Score Sequence(暴力)

时间: 2024-07-31 20:10:50

poj 4044 Score Sequence(暴力)的相关文章

练手题,没事就来AC吧 poj 4044 Score Sequence

此题为12年金华邀请赛A题 克隆了下比赛,A题最简单,也是最挑战人数据处理能力的一题,可惜自己数据处理能力太弱 久久不能写出代码---- 总结下就是题做少了,平时应多做题,少灌水,应放下看电影的时间,玩各种软件的时间 先做好一项再说才是正道,看到一句话说得好 "   人有两条路要走,一条是必须走的,一条是想走的,你必须把必须走的路走漂亮,才可以走想走的路..." 不扯了,贴代码: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

poj Problem A. Score Sequence(暴力)

这道题,对于我这种英文不好的人来说,有点费劲啊. 题目的意思:给你两组成绩,你要找出他们之间最大的公共子序列,不能有重复,然后输出两组数据. 第一组就是:按照从大到小输出最大子序列. 第二组就是:按照个位数由小到大输出,若个位数一样大,则小的在前输出最大子序列. 解题思路基本上已经出来了,就是千万要注意就是在最长子序列匹配之前就就把重复的数字给删除. 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h

poj 1699 Best Sequence(AC自动机+状压DP)

题目链接:poj 1699 Best Sequence 题目大意:给定N个DNA序列,问说最少多长的字符串包含所有序列. 解题思路:AC自动机+状压DP,先对字符串构造AC自动机,然后在dp[s][i]表示匹配了s,移动到节点i时候的最短步数. #include <cstdio> #include <cstring> #include <queue> #include <vector> #include <iostream> #include &

POJ 1699 Best Sequence (DFS+预处理)

题意:看那张图就一清二楚了吧, N个序列首位相连(相同的序列部分),得到最短的总序列. 题目链接:http://poj.org/problem?id=1699 ~~~~ 思路就是:将N个序列首尾相连能重合的长度求粗来.然后DFS枚举每种首尾相连的情况. #include<cstdio> #include<cstring> #include<algorithm> #define N 22 #define INF 0x7fffffff using namespace std

POJ 1019 Number Sequence 题解

这又是一道看似简单,实际挺困难的题目. 本来想做道基础题消遣一下的,没想到反被消遣了-_-|||. 看个人的基础吧,对于数学好的会简单点,但是由于情况太多,需要都考虑全,故此难度应该在4星以上了. 我这里使用的方法就是直接打表,然后直接模拟,利用打表去掉一大段数据,剩下数据量十分小了,故此可以直接模拟. 打表是为了计算前面的周期数,把周期数直接去掉. 主要难点是后面10位数以上的数有2位, 3位,4位等情况要考虑.- 下面使用getNewNums一个函数解决了,想通了,就几行代码,还不用难理解的

POJ 1699 Best Sequence(DFS)

題目鏈接 題意 : 將幾個片段如圖所示方法縮成一個序列,求出最短這個序列. 思路 : 其實我也不知道怎麼做.....看網上都用了DP.....但是我不會.....這個DP不錯,還有用KMP+状压DP做的 1 //1699 2 #include <iostream> 3 #include <stdio.h> 4 #include <string.h> 5 #include <string> 6 7 using namespace std; 8 9 string

uva1626 poj 1141 Brackets Sequence 区间dp 打印路径

// poj 1141 Brackets Sequence // 也是在紫书上看的一题,uva就是多了一个t组数据. // 经典区间dp // dp(i,j)表示区间[i,j]内所需要增加的括号数目 // 则分为两种情况 // 一种是s[i]和s[j]是匹配的则 // dp[i][j] = min(dp[i][j],dp[i+1][j-1]) // 另外一种情况是不匹配 // dp[i][j] = min(dp[i][j],dp[i][k]+dp[k+1][j]){i<k<j}; // 但是无

POJ 1840 Eqs(暴力)

Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The coefficients are given integers from the interval [-50,50]. It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,

poj 1699 Best Sequence (搜索技巧 剪枝 dfs)

题目链接 题意:给出几个基因片段,要求你将它们排列成一个最短的序列,序列中使用了所有的基因片段,而且不能翻转基因. 分析:先计算出add数组,再dfs枚举. 1 #include <iostream> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 #include <cstdio> 6 #include <vector> 7 #include <al