poj 3080 Blue Jeans 暴力
来源:互联网 发布:八爪鱼采集数据重复 编辑:程序博客网 时间:2024/06/06 03:55
Blue Jeans
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 14283 Accepted: 6356
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 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 (C). 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.
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 (C). 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
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.
Output
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.
Sample Input
32GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAGATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAAGATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA3CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
Sample Output
no significant commonalitiesAGATACCATCATCAT
题意: 求出多组字符串的最大相邻公共子串,若长度小于三则输出“no significant commonalities”,否则,对于输出公共子串,对于同样长度的公共子串,输出按字母排序较小的串
思路:暴搜暴搜暴搜~~~
#include<cstdio>#include<iostream>#include<cstring>using namespace std;char a[15][65];char anss[65];int main(){ int n; scanf("%d",&n); while(n--){ int m; scanf("%d",&m); int i,j,k; for(i=0;i<m;i++){ scanf("%s",a[i]); } int ans=0; int len=strlen(a[0]); char sub[65]; for(i=0;i<len;i++){ for(j=i+2;j<len;j++){ strncpy(sub,a[0]+i,j-i+1); sub[j-i+1]='\0'; int flag=1; for(k=1;flag&&k<m;k++){ if(strstr(a[k],sub)==0){ flag=0; } } if(flag&&(ans<strlen(sub)||(ans==strlen(sub)&&strcmp(anss,sub)>=0))){//记得比较一下 ans=strlen(sub); strcpy(anss,sub); } } } if(ans<3) printf("no significant commonalities"); else printf("%s",anss); printf("\n"); }}
0 0
- poj 3080 Blue Jeans 暴力
- [KMP或者暴力]POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans 暴力枚举+KMP
- POJ 3080 Blue Jeans KMP+暴力
- poj 3080 Blue Jeans (kmp暴力)
- POJ 3080 Blue Jeans (KMP || 暴力)
- POJ 3080 Blue Jeans(暴力)
- poj-3080-Blue Jeans-串-暴力
- POJ 3080 Blue Jeans kmp+暴力枚举
- poj 3080 Blue Jeans 【KMP 暴力枚举】
- POJ 3080--Blue Jeans【KMP && 暴力枚举】
- poj 3080 Blue Jeans 字符串,暴力
- POJ 3080 Blue Jeans (暴力)
- poj 3080 Blue Jeans 【kmp+暴力】
- POJ 3080 Blue Jeans (很暴力)
- POJ-3080 Blue Jeans(纯暴力)
- POJ 3080 Blue Jeans 串的暴力
- POJ 3080 Blue Jeans(暴力 + 串)
- NYOJ_94 cigarettes 递归VS迭代
- MongoDB索引
- linux数据流重定向
- MongoDB 聚合
- MongoDB 备份
- poj 3080 Blue Jeans 暴力
- 如何在 MIT Scheme 中运行 Scheme 语言程序
- 程序内存管理
- Linux____用户和群组进阶学习笔记
- 关于等差等比数列乘积求和的分析
- Uncaught TypeError: Cannot read property 'prototype' of null using Openerp 7.0
- 从注册表中查看Oracle的hotname及SID等
- mac 下修改mysql的密码
- synchronized与Lock有什么异同