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(暴力)的更多相关文章
- POJ 4044 Score Sequence
题目链接 题意 :给你两个序列,进行降序排序,找出连续的公共子序列,将这个子序列输出,然后对个位数升序排序,如果个位数相同就按数的大小排,再输出这个新排好的. 思路 :先排序,再找公共子序列,最后个位 ...
- poj 1699 Best Sequence(AC自己主动机+如压力DP)
id=1699" target="_blank" style="">题目链接:poj 1699 Best Sequence 题目大意:给定N个D ...
- [poj P1141] Brackets Sequence
[poj P1141] Brackets Sequence Time Limit: 1000MS Memory Limit: 65536K Special Judge Description ...
- Poj 1019 Number Sequence( 数据分析和操作)
一.题目大意 有这样一个序列包含S1,S2,S3...SK,每一个Si包括整数1到 i.求在这个序列中给定的整数n为下标的数. 例如,前80位为1121231234123451234561234567 ...
- POJ 2478 Farey Sequence
名字是法雷数列其实是欧拉phi函数 Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- POJ 2478 Farey Sequence(欧拉函数前n项和)
A - Farey Sequence Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- POJ 2778 DNA Sequence(AC自动机+矩阵加速)
DNA Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9899 Accepted: 3717 Desc ...
- poj 2021 Relative Relatives(暴力)
题目链接:http://poj.org/problem?id=2021 思路分析:由于数据较小,采用O(N^2)的暴力算法,算出所有后代的年龄,再排序输出. 代码分析: #include <io ...
- POJ 2593 Max Sequence
Max Sequence Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17678 Accepted: 7401 Des ...
随机推荐
- 中标麒麟6.0_ICE3.4.2编译+demo测试(CPP)
(菜鸟版)确保 gcc版本4.4.6(其他版本未测试),4.8不行 一.降级GCC到4.4.6 注意:gcc g++ c++命令都为4.4.6(可用gcc -v; g++ -v; c++ -v 命令查 ...
- 使用Unity开发HoloLens应用
https://developer.microsoft.com/en-us/windows/holographic/install_the_tools 导读:开发者们在陆续收到HoloLens开发者版 ...
- JS中String添加trim()方法
这么牛的JS竟然还要自己封装trim方法. 下面利用prototype和正则表达式的添加方式添加trim(): <script language="javascript"&g ...
- FIDO联盟:我们将杀死密码
前不久发布的三星S5与iPhone 5S一样,配备了指纹识别技术.但更为重要的是,这一识别器可以与PayPal关连,进而与多种支付系统相连.通过这一过程,你很可能会摆脱密码,用指纹就可以畅游网络.当然 ...
- Golang网络库中socket阻塞调度源码剖析
本文分析了Golang的socket文件描述符和goroutine阻塞调度的原理.代码中大部分是Go代码,小部分是汇编代码.完整理解本文需要Go语言知识,并且用Golang写过网络程序.更重要的是,需 ...
- 一个简单的RTTI实现
RTTI是"Runtime Type Information"的缩写,意思是:运行时类型信息.它提供了运行时确定对象类型的方法. 最近在写的一些东西,不想使用MFC之类的框架,但是 ...
- 百度云是用SOUI开发的产品
http://www.cnblogs.com/setoutsoft/p/4155997.html
- centos6 qt ENV
打算做嵌入式图像处理,计划方案嵌入式Linux+OpenCV+QT,昨天简单入门OpenCV今天看看QT,QT就先弄Linux下面的,回家之前争取把基本的摸通,然后能在板子上跑起来 关于QT安装 QT ...
- xcode UIImageView创建、图片加载、 音频文件播放、 延迟调用
代码创建 /** 创建UIImageView */ UIImageView * imageView=[[UIImageView alloc]init]; /** 设置尺寸位置 */ imageView ...
- 在 Visio 中录制宏
在“开发工具”选项卡上,单击“录制宏”.(如果您看不到“开发工具”选项卡,请参阅下面的“显示‘开发工具’选项卡”.) 在“宏名”框中,键入宏名称. 在“快捷键”框中,键入与 Ctrl 键一起使用可运行 ...