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(暴力)的更多相关文章

  1. POJ 4044 Score Sequence

    题目链接 题意 :给你两个序列,进行降序排序,找出连续的公共子序列,将这个子序列输出,然后对个位数升序排序,如果个位数相同就按数的大小排,再输出这个新排好的. 思路 :先排序,再找公共子序列,最后个位 ...

  2. poj 1699 Best Sequence(AC自己主动机+如压力DP)

    id=1699" target="_blank" style="">题目链接:poj 1699 Best Sequence 题目大意:给定N个D ...

  3. [poj P1141] Brackets Sequence

    [poj P1141] Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K   Special Judge Description ...

  4. Poj 1019 Number Sequence( 数据分析和操作)

    一.题目大意 有这样一个序列包含S1,S2,S3...SK,每一个Si包括整数1到 i.求在这个序列中给定的整数n为下标的数. 例如,前80位为1121231234123451234561234567 ...

  5. POJ 2478 Farey Sequence

     名字是法雷数列其实是欧拉phi函数              Farey Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  6. POJ 2478 Farey Sequence(欧拉函数前n项和)

    A - Farey Sequence Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  7. POJ 2778 DNA Sequence(AC自动机+矩阵加速)

    DNA Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9899   Accepted: 3717 Desc ...

  8. poj 2021 Relative Relatives(暴力)

    题目链接:http://poj.org/problem?id=2021 思路分析:由于数据较小,采用O(N^2)的暴力算法,算出所有后代的年龄,再排序输出. 代码分析: #include <io ...

  9. POJ 2593 Max Sequence

    Max Sequence Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17678   Accepted: 7401 Des ...

随机推荐

  1. OSG显示文字——自定义显示文字函数

    #include <Windows.h> #include <osg/Geode> #include <osg/Geometry> #include <osg ...

  2. PKCS#12

    http://blog.csdn.net/cuiran/article/details/7816696 数字证书介绍 一.什么是数字证书 数字证书就是互联网通讯中标志通讯各方身份信息的一系列数据,提供 ...

  3. 剑指offer 25 二叉树中和为某一值的路径

    非递归方法: class Solution { public: vector<vector<int>> FindPath(TreeNode* root,int expectNu ...

  4. Android开发实例之闹钟提醒

    本实例通过TimePickerDialog时间选择对话框让用户设置闹钟.并通过AlarmManager全局定时器在指定的时间启动闹钟Activity . 程序执行效果图: 实例代码: package ...

  5. FPGA中浮点运算实现方法——定标

    有些FPGA中是不能直接对浮点数进行操作的,仅仅能採用定点数进行数值运算.对于FPGA而言,參与数学运算的书就是16位的整型数,但假设数学运算中出现小数怎么办呢?要知道,FPGA对小数是无能为力的,一 ...

  6. Effective JavaScript Item 36 实例状态仅仅保存在实例对象上

    本系列作为EffectiveJavaScript的读书笔记. 一个类型的prototype和该类型的实例之间是"一对多"的关系.那么,须要确保实例相关的数据不会被错误地保存在pro ...

  7. 提高你的Java代码质量吧:使用构造函数协助描述枚举项

    一.分析 一般来说,我们经常使用的枚举项只有一个属性,即排序号,其默认值是从0.1.2... ....但是除了排序号外,枚举还有一个(或多个)属性. 二.场景 比如,可以通过枚举构造函数声明业务值,定 ...

  8. SQL数据库插入文本信息

    文本内容

  9. asp.net MVC Razor 语法(2)

    变量是用于存储数据的命名实体. 变量 变量用于存储数据. 变量名必须以字母字符开头,不能包含空格和保留字符. 变量可以是某个具体的类型,指示其所存储的数据类型.字符串变量存储字符串值 ("W ...

  10. IIS7.0/7.5 MVC3 实现伪静态

    routes.MapRoute(            "Default",            "{controller}/{action}.html/{id}&qu ...