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. js创建对象的几种常用方式小结

    第一种模式:工厂方式  var lev=function(){ return "666"; }; function Parent(){ var Child = new Object ...

  2. php测试时不出现错误信息

    来源:http://blog.sina.com.cn/s/blog_6c9d65a101013vdj.html 在练习程序时,有时候写错了,在浏览器会打印出出错信息. 可我的程序始终没有出现. 我的环 ...

  3. Activity篇章参考

    附上学习这部分知识的时候收集的一些比较好的链接: Task and backStack|Android Developer adb shell dumpsys activity 单个apk多进程 Ac ...

  4. Win7下qt5.3.1+opencv2.4.9编译环境的搭建(好多 Opencv2.4.9源码分析的博客)

      到官网下载qt-opensource-windows-x86-mingw482_opengl-5.3.1.exe文件,执行该文件,选择默认安装即可实现QT的安装(安装在C盘的根目录下),该文件封装 ...

  5. CC++初学者编程教程(2) Microsoft Visual C++ 6.0开发环境搭建

    上一篇演示的是如何安装VS2010,本文演示的是如何安装Microsoft Visual C++ 6.0 简称VC6. 有同学经常VC6都是很古董的版本了,为啥他还存在,不得不说VC6是微软一个很经典 ...

  6. asp.net 使用my97 datepicker实现前后两个日期的范围界定

    说明:日期选择后,前面的日期小于等后面的日期,后面的日期大于等于前面的日期.点点看就知道了:) - 这里将周末日期不可选.代码如下: <html xmlns="http://www.w ...

  7. WebPart设置杂项

    CS写法:                    } 后台写法:  public D_ZoneLimitView WebPart { get; set; }

  8. 解决Metadata file does not match checksum错误

    1.清空缓存执行: # yum clean all 先把就的缓存数据都去掉. 2.下载metadata和校验数据先进入yum对应的目录,再下载: # cd /var/cache/yum/rpmforg ...

  9. oracle默认的hr用户使用脚本安装

    1 解压到%ORACLE_HOME%/demo/schema/human_resources/目录下 2 在sys或system用户下运行hr_main.sql脚本(运行命令:@%ORACLE_HOM ...

  10. yii2.0 从控制器到视图的输出

    在controllers/SiteController.php文件中,添加 public function actionSay($message = 'Hello') { return $this-& ...