poj Problem A. Score Sequence(暴力)

这道题,对于我这种英文不好的人来说,有点费劲啊。

题目的意思:给你两组成绩,你要找出他们之间最大的公共子序列,不能有重复,然后输出两组数据。

第一组就是:按照从大到小输出最大子序列。

第二组就是:按照个位数由小到大输出,若个位数一样大,则小的在前输出最大子序列。

解题思路基本上已经出来了,就是千万要注意就是在最长子序列匹配之前就就把重复的数字给删除。


  1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 struct node
6 {
7 int data;
8 int ge;
9 };
10
11 int cmp1(const void *a , const void *b)
12 {
13 return *(int *)a - *(int *)b;
14 }
15 int cmp2(const void *a , const void *b)
16 {
17 return *(int *)b - *(int *)a;
18 }
19 int cmp3( const void *a , const void *b )
20 {
21 struct node *c = (struct node *)a;
22 struct node *d = (struct node *)b;
23 if(c->ge != d->ge) return c->ge - d->ge;
24 else return c->data - d->data;
25 }
26
27 int main()
28 {
29 int t, n, m;
30
31
32 scanf("%d", &t);
33
34 while(t--)
35 {
36
37 int a[35], b[35],c[35];
38 int x[35],y[35];
39 struct node d[35];
40 scanf("%d%d", &n, &m);
41 //printf("xmx\n");
42 for(int i = 0; i < n; i++)
43 scanf("%d", &a[i]);
44 //printf("xmx\n");
45 for(int i = 0; i < m; i++)
46 scanf("%d", &b[i]);
47
48 qsort(a, n, sizeof(a[0]), cmp1);
49 qsort(b, m, sizeof(b[0]), cmp1);
50
51 int v = a[0];
52 x[0]=a[0];
53 int k1 = 0;
54
55 for(int i = 1; i < n; i++)
56 {
57 if(v!=a[i])
58 {
59 v = a[i];
60 k1++;
61 x[k1] = a[i];
62 }
63 }
64
65 v = b[0];
66 y[0]=b[0];
67 int k2 = 0;
68
69 for(int i = 1; i < m; i++)
70 {
71 if(v!=b[i])
72 {
73 v = b[i];
74 k2++;
75 y[k2] = b[i];
76 }
77 }
78
79
80 int maxn = 0, flag = 0;
81 int i1, j1, start;
82
83 for(int i = 0; i <= k1; i++)
84 {
85 for(int j = 0; j <= k2; j++)
86 {
87 i1 = i;
88 j1 = j;
89 flag = 0;
90 //printf("xmx\n");
91 for(int k = 0; k <= k1&&i1<=k1&&j1<=k2; k++)
92 {
93 if(x[i1] == y[j1])
94 {
95 flag++;
96 i1++;
97 j1++;
98 }
99 else
100 {
101 break;
102 }
103 }
104 if(maxn <= flag)
105 {
106 maxn = flag;
107 start = i;
108 }
109 }
110 }
111 if(maxn > 0)
112 {
113 v = x[start];
114 c[0]=x[start];
115 int k = 0;
116
117 for(int i = 1; i < maxn; i++)
118 {
119 if(v!=x[start+i])
120 {
121 v = x[start + i];
122 k++;
123 c[k] = x[start + i];
124 }
125 }
126 qsort(c,k+1,sizeof(c[0]),cmp2);
127 for(int i=0; i<=k; i++)
128 {
129 printf("%d ",c[i]);
130 d[i].data=c[i];
131 d[i].ge=c[i]%10;
132 }
133 printf("\n");
134 qsort(d,k+1,sizeof(d[0]),cmp3);
135 for(int i=0; i<=k; i++)
136 printf("%d ",d[i].data);
137 printf("\n");
138
139 }
140 else
141 {
142 printf("NONE\n");
143 }
144 }
145
146 return 0;
147 }

poj Problem A. Score Sequence(暴力),布布扣,bubuko.com

时间: 2024-08-07 04:34:13

poj Problem A. Score Sequence(暴力)的相关文章

poj 4044 Score Sequence(暴力)

http://poj.org/problem?id=4044 大致题意:给出两个班级的成绩,先按降序排序,并且没有成绩相同的.然后求连续的最长公共子序列.输出时,先输出最长公共子序列,然后按个位数字递增的顺序输出,若各位数字一样就按成绩递增. 人数小于30,注意去重,直接暴力即可. #include <stdio.h> #include <iostream> #include <map> #include <stack> #include <vecto

练手题,没事就来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 2081 Recaman&#39;s Sequence

比较简单,加一个B数组判重即可 Recaman's Sequence Time Limit: 3000MS   Memory Limit: 60000K Total Submissions: 21743   Accepted: 9287 Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, am = am−1 − m if the rsulting am is positive and not already i

【POJ】2278 DNA Sequence

各种wa后,各种TLE.注意若AC非法,则ACT等一定非法.而且尽量少MOD. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <queue> 5 using namespace std; 6 7 #define MAXN 105 8 #define NXTN 4 9 10 char str[15]; 11 12 typedef struct Matrix {

poj 1054 The Troublesome Frog (暴力搜索 + 剪枝优化)

题目链接 看到分类里是dp,结果想了半天,也没想出来,搜了一下题解,全是暴力! 不过剪枝很重要,下面我的代码 266ms. 题意: 在一个矩阵方格里面,青蛙在里面跳,但是青蛙每一步都是等长的跳, 从一个边界外,跳到了另一边的边界外,每跳一次对那个点进行标记. 现在给你很多青蛙跳过后的所标记的所有点,那请你从这些点里面找出 一条可能的路径里面出现过的标记点最多. 分析:先排序(目的是方便剪枝,break),然后枚举两个点,这两个 点代表这条路径的起始的两个点.然后是三个剪枝,下面有. 开始遍历时,

uva 10837 - A Research Problem(欧拉函数+暴力)

题目链接:uva 10837 - A Research Problem 题目大意:给定一个phin,要求一个最小的n,欧拉函数n等于phin 解题思路:欧拉函数性质有,p为素数的话有phip=p?1;如果p和q互质的话有phip?q=phip?phiq 然后根据这样的性质,n=pk11(p1?1)?pk22(p2?1)???pkii(pi?1),将所有的pi处理出来,暴力搜索维护最小值,虽然看上去复杂度非常高,但是因为对于垒乘来说,增长非常快,所以搜索范围大大被缩小了. #include <cs

poj 3017 Cut the Sequence

poj 3017 Cut the Sequence 单调队列 题意是:把一个 长度 为 n 的 数列 分成任意份,使每一份的和不超过m,求每一份的最大值的和,使和最小 动态规划方程 是 f [i] = f[j] + max{ f[j+1] , f[j+2] , f[i] }; 朴素的算法是 O(n^2); 用 单调队列 表示一个递减 的 队列 ,则 不需要 求 每块区域的最大值 哎哎哎……不知道怎么说 #include <iostream> #include <cstdio> #i

poj 2081 Recaman&#39;s Sequence (dp)

Recaman's Sequence Time Limit: 3000MS   Memory Limit: 60000K Total Submissions: 22566   Accepted: 9697 Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, am = am−1 − m if the rsulting am is positive and not already in the sequence,

HDOJ 5400 Arithmetic Sequence 暴力枚举

Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 382    Accepted Submission(s): 196 Problem Description A sequence b1,b2,?,bn are called (d1,d2)-arithmetic sequence if and on