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 ...
随机推荐
- php配置redis支持
在php.ini里面添加下面两行,注意这两行的顺序一定不要颠倒(扩展库下载网址https://github.com/phpredis/phpredis/downloads),同时注意这2个文件的版本一 ...
- Nginx+PostgreSQL+Django+UWSGI搭建
最近因为项目上的需要开始大量使用nginx,因此也想趁机将以前常用的django+apache的架构换成django+nginx.常见的 django webapp 部署方式采用FCGI 或 WSGI ...
- Sencha Touch 之 Ext.fly方法的使用
Ext.fly方法是Ext.js 4中的flyweight技术,该技术在浏览器中为使用Ext.fly方法的元素节点开辟一块内存,下一次使用Ext.fly方法的元素节点将占据同一块内存,即覆盖前一次的元 ...
- J2SE知识点摘记-数据库(二)
一. 查询数据 注意sql的内容. 通过ResultSet接口保存全部的查询结果,通过Statement接口中的executeQuery()方法查询.查询之后需要分别取出.通过nex ...
- 使用C#开发Metro 风格应用的路线图 -- 触屏操作
原文 http://www.cnblogs.com/icuit/archive/2012/05/01/2478312.html win8支持多点触摸技术,而我们在屏幕上所做的各种操作,也最终转换为输入 ...
- 强烈推荐visual c++ 2012入门经典适合初学者入门
强烈推荐visual c++ 2012入门经典适合初学者入门 此书循序渐进,用其独特.易于理解的教程风格来介绍各个主题,无论是编程新手,还是经验丰富的编程人员,都很容易理解. 此书的目录基本覆盖了Wi ...
- centos ldap
Standalone LDAP Daemon, slapd(standalone lightweight access protocol)Lightweight Directory Access Pr ...
- mongodb查询关于大于小于的用法;
mongoDB查询操作符: http://www.runoob.com/mongodb/mongodb-operators.html 项目中需要的场景是这样的,每个人每天只能领取一张明信片,换句话说, ...
- php各类hash算法长度及性能
Hash结果如下 <?php $data = "hello world"; foreach (hash_algos() as $v) { $r = hash($v, $dat ...
- JavaScript值延迟脚本和异步脚本
Html 4.0为<script>标签定义了defer属性,这个属性的用途是表名脚本在执行时,不会影响页面的构造.也就是说,脚本会延迟到整个页面解析完毕之后在运行,因此,在<scri ...