Blue Jeans

poj-3080 blue jeans Description The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contributors to map how the Earth 阅读详情

题目描述:

The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contributors to map how the Earth was populated.

As an IBM researcher, you have been tasked with writing a program that will find commonalities amongst given snippets of DNA that can be correlated with individual survey information to identify new genetic markers.

A DNA base sequence is noted by listing the nitrogen bases in the order in which they are found in the molecule. There are four bases: adenine (A), thymine (T), guanine (G), and cytosine ©. A 6-base DNA sequence could be represented as TAGACC.

Given a set of DNA base sequences, determine the longest series of bases that occurs in all of the sequences.

输入:

Input to this problem will begin with a line containing a single integer n indicating the number of datasets. Each dataset consists of the following components:

  • A single positive integer m (2 <= m <= 10) indicating the number of base sequences in this dataset.
  • m lines each containing a single base sequence consisting of 60 bases.

输出:

For each dataset in the input, output the longest base subsequence common to all of the given base sequences. If the longest common subsequence is less than three bases in length, display the string “no significant commonalities” instead. If multiple subsequences of the same longest length exist, output only the subsequence that comes first in alphabetical order.

样例输入:

3
2
GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
3
GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
3
CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

样例输出:

no significant commonalities
AGATAC
CATCATCAT

code:

要求你找到多个字符串里的相同的最长子串,如果有一样长的,输出字典序最小的哪一个
数据量比较小,放心暴力
当时看了很多博客,绕着绕着就晕了,所幸,也不是什么特别高深的算法题
暴力实现就好

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
char a[20][500];
char b[500];
int nextt[500];
vector<string> feng;
void init()
{
	int i=0,j=-1;
	nextt[0]=-1;
	int m=strlen(b);
	while(i<m)
	{
		if(j==-1||b[i]==b[j])
		{
			i++;
			j++;
			nextt[i]=j;
		}
		else
		{
			j=nextt[j];
		}
	}
}
bool kmp(int what)
{
	int i=0,j=0;
	int flag=0;
	init();
	int n=strlen(a[what]);
	int m=strlen(b);
	while(i<n)
	{
		if(j==-1||a[what][i]==b[j])
		{
			j++;
			i++;
		}
		else j=nextt[j];
		if(j==m)
		{
			return true;
		}
	}
	return false;
}
bool cmp(string a,string b)
{
	return a<b;
}
int main()
{
	int ttt,n;
	scanf("%d",&ttt);
	while(ttt--)
	{
		scanf("%d",&n);
		for(int i=0;i<n;i++)
		{
			scanf("%s",a[i]);
		}
		int m=strlen(a[0]);
		int flag=0;
		int much;
		int sum=0;
		for(int i=0;i<m-1;i++)
		{//i表示的是从a[0]数组中,砍掉几个字符
			for(int j=0;j<=i;j++)
			{//前面砍掉几个
				int start=j,over=m-i+j-1;//后面砍掉几个
				memset(b,'\0',sizeof(b));
				int qq=0;
				for(int k=start;k<=over;k++)
				{
					b[qq++]=a[0][k];
				}//将a[0]作为子串的来源
				int jie=1;
				for(int k=1;k<n;k++)
				{
					if(!kmp(k))
					{
						jie=0;
					}
				}//匹配
				if(jie==1)
				{
					flag=1;
					feng.push_back(b);
				}
			}
			if(flag)break;
		}
		if(strlen(b)<3)printf("no significant commonalities\n",b);
		else 
		{
			sort(feng.begin(),feng.end(),cmp);
			cout<<feng[0]<<endl;//求字典序最小的那个
		}
		feng.clear();
	}
	return 0;
}
华为OD机试真题 新系统 【社交网络相同爱好好友查询】 华为od机试真题 新系统【社交网络相同爱好好友查询】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为od机试真题【社交网络相同爱好好友查询】多语言题解实现。 阅读详情

相关推荐

TB6600驱动器共阴共阳接法傻傻分不清?一张图搞定STM32与42步进电机的接线避坑指南

本文详细解析了TB6600驱动器共阴共阳接法的本质区别,提供了STM32与42步进电机的高效连接方案。通过实际案例和接线图示,帮助读者避免常见错误,确保驱动器与MCU的安全连接,提升项目稳定性。

weixin_28710999的博客 246

POJ -3080 Blue Jeans(暴力枚举每个子串)

Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Description The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundr...

名字太长容易被发现并打死 333

麦当劳app之sign逆向分析

摘要:本文分析了麦当劳APP请求参数sign的逆向过程。通过抓包发现32位sign参数疑似MD5加密,使用frida-trace工具跟踪CC_MD5函数验证其为标准MD5算法。加密参数包含时间戳、token、版本号等固定和动态字段,拼接后经MD5加密生成sign。文章提供了JS和Python两种实现方案,包含完整的请求头参数和加密逻辑,最终成功获取API响应数据。该研究仅用于逆向技术学习,展示了移动应用常见加密参数的逆向分析方法。

佛系更新... 2442

poj3080

Blue Jeans Time Limit:1000MS Memory Limit:65536K Total Submissions:7671 Accepted:3184 Description The Genographic Project is a research partnership between IBM and ...

weixin_34008933的博客 343

Hyper-V虚拟机 安装 银河麒麟V10桌面版

如何在windows 11 Hyper-V 虚拟机中 安装 银河麒麟V10桌面版。

m0_46756112的博客 3422

银河麒麟V11 + KVM/QEMU + GT 710 GPU直通 Win10 完整操作流程文档

宿主机:RTX 5080专门运行ollama大模型服务,通过SSH/VNC远程管理Win10虚拟机:GT 710直通,物理键盘专属,通过物理显示器处理视频应用硬件隔离:两个系统完全隔离,互不干扰,性能最大化两种不同的直通方式直通方式 配置方法 设备在宿主机的状态 典型应用场景PCIe设备直通 vfio-pci.ids=10de:128b,10de:0e0f 设备完全从宿主机消失,被vfio-pci驱动接管 GPU、网卡、NVMe硬盘。

weixin_45285654的博客 1154

(kmp) Blue Jeans (3080)

这个题,感觉有一点复杂,中途有一点想放弃,,还是坚持下来了。还一次成功了。不错。,,今天写kmp比较顺利,也算是更理解一些了吧 #include #include #include #include #include #include #include #include using namespace std; int n; char s[11][66]; int next[

jiangjiashi的博客 655

分布式锁特点、以及用python3实现redis分布式锁

以下是 Python3 实现 Redis 分布式锁的详细教程,包含代码示例、原理说明及最佳实践。

数据知道的博客 2万+

Blue Jeans 【KMP+暴力】

Description The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contributors to map how the Earth was...

几许情愁的博客 634

系统安装(kuntaiR522 kvm安装)

鲲泰R522服务器kvm安装rocky

weixin_46396917的博客 1822

Python画柱状图(双柱状图,三柱状图)且显示对应数值

使用python实现双柱状图和三柱状图,并且在柱状图形的顶部显示对应数值;

yue200403的博客 1万+

Blue Jeans(最大匹配问题)

Description The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contributors to map how the Earth was...

PleasantlY1的博客 1366

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

POJ_3080 Blue Jeans 【KMP】

题目链接 题目描述 题目叭叭说了一大堆,其实意思就是让你在n个字符串中找到一个最长的公共子串,如果长度小于3输出:no significant commonalities 否则输出最长的子串即可。 解题思路 首先将第一个串分解,把其所有的子串作为kmp的模式串,在剩余的字符串中查找,如果剩余的字符串中都存在该模式串,就更新答案(公共子串的长度 和 公共子串)。 最后根据题目...

Learning Deep Learning 478

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

【KMP+二分枚举】 I - Blue Jeans POJ - 3080

Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21193   Accepted: 9399 Description The Genographic Project is a research partnersh...

博客 267

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

POJ 3080.Blue Jeans

题目:http://poj.org/problem?id=3080 AC代码(C++): #include #include #include #include #include #include #include #include #include #define INF 0xfffffff #define MAXN 2005 using namespace

njyexiong的博客 260

POJ 3080 Blue Jeans

Blue Jeans Time Limit:1000MS Memory Limit:65536K Total Submissions:22483 Accepted:9983 Description The Genographic Project is a research partnership between IBM and The Natio...

~ 450

BLUE Jeans

G - Blue Jeans   input 3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3 GATACCAGATACCAGATACCAGATACCAGATACCAGATA

dally2的博客 585

【POJ3080】Blue Jeans

这道题我们发现每个串的长度只有60 所以对于第一个串(或者选一个你喜欢的)枚举子串分别与其他串KMP匹配 注意长度相等时字典序最小&&长度<3时no significant commonalities 1 #include<cstdio> 2 #include<cstring> 3 using namespace s...

diefou0453的博客 116

poj 3080 Blue Jeans(kmp)

poj 3080 PKU 3080 Blue Jeans(kmp)?#include<stdio.h>#include<string.h>const int N=100;int n,m,next[N];char dna[N][N];void get_next(char *str,int len){ next[0]=-1; int j=0,k=-1;//k记...

weixin_30498921的博客 75
上一篇: Seek the Name, Seek the Fame
下一篇: Simpsons’ Hidden Talents
大橘为重eleven
博客等级 码龄8年 35粉丝 103原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值