poj 107 DNA sorting
关于Java的题解,也许效率低下,但是能解决不只是ACGT的序列字符串
代码如下:
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
TreeMap<Integer,String> map = new TreeMap<Integer,String>();
//读入题目所给的信息
int n = sc.nextInt(),m = sc.nextInt(),count;
String[] strs = new String[m];
for(int i=0;i<strs.length;i++){
strs[i] = sc.next();
if(strs[i].length()!=n)
throw new RuntimeException();
}
//计算每一个序列的measure数,用count表示
for(int i=0;i<strs.length;i++){
count=0;
for(int j=0;j<strs[i].length()-1;j++){
for(int k=j+1;k<strs[i].length();k++){
char ch1 = strs[i].charAt(j);
char ch2 = strs[i].charAt(k);
if(ch1>ch2)
count++;
}
}
//如果发现序列中有相同的count,那么把该序列加到原序列的末尾,用来最后的输出
if(map.containsKey(count)){
String value = map.get(count);
map.put(count,value+strs[i]);
}
else
map.put(count, strs[i]);
}
//输出答案序列
for(Map.Entry<Integer, String> entry : map.entrySet()){
String value = entry.getValue();
int size = value.length()/n;
if(size>1){
int offset = 0;
for(int i=1;i<=size;i++){
System.out.println(value.substring(offset,offset+n));
offset+=n;
}
}
else
System.out.println(value);
}
}
}
poj 107 DNA sorting的更多相关文章
- [POJ 1007] DNA Sorting C++解题
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 77786 Accepted: 31201 ...
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 Des ...
- [POJ] #1007# DNA Sorting : 桶排序
一. 题目 DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95052 Accepted: 382 ...
- poj 1007 DNA Sorting
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95437 Accepted: 38399 Des ...
- poj 1007 DNA sorting (qsort)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95209 Accepted: 38311 Des ...
- poj 1007 DNA Sorting 解题报告
题目链接:http://poj.org/problem?id=1007 本题属于字符串排序问题.思路很简单,把每行的字符串和该行字符串统计出的字母逆序的总和看成一个结构体.最后把全部行按照这个总和从小 ...
- POJ 1007 DNA Sorting(sort函数的使用)
Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are ...
- POJ 1007 DNA sorting (关于字符串和排序的水题)
#include<iostream>//写字符串的题目可以用这种方式:str[i][j] &str[i] using namespace std; int main() {int ...
- DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...
随机推荐
- 怎样完整地离线更新并升级基于 Debian 的操作系统
不久之前我已经向你展示了如何在任意离线的 Ubuntu 和 Arch Linux 操作系统上安装软件. 今天,我们将会看看如何完整地离线更新并升级基于 Debian 的操作系统. 和之前所述方法的不同 ...
- form 表单添加 enctype ="multipart/form-data" 属性后后台接收中文乱码
解决办法: new String( request.getParameter("title").getBytes("ISO-8859-1"),"utf ...
- 2018.10.13 bzo1934: [Shoi2007]Vote 善意的投票(最小割)
传送门 最小割定义题. 按照题意建边就行了. 考虑把冲突变成把aaa选入不与自己匹配的集合所需要付出的代价. 然后跑最小割就行了. 代码: #include<bits/stdc++.h> ...
- 2018.09.09 poj2949Word Rings(01分数规划+spfa判环)
传送门 这题要先巧妙的转化一下. 对于每个字符串,我们把头尾的两个小字符串对应的点连边,边权是这个字符串的长度. 这样最多会出现26*26个点. 这个时候就只用求出边权和跟边数的最大比值了. 这个显然 ...
- hdu-1698(线段树,区间修改)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 注意:用位运算会更快,不然超时. #include<iostream> #inclu ...
- yum基本操作(转)
原文地址:http://www.cnblogs.com/chuncn/archive/2010/10/17/1853915.html yum(全称为 Yellow dog Updater, Modif ...
- 文件权限命令 linux
chmod 777 文件名/文件夹名 拥有所有权限 http://www_xpc8_com/ chmod 755 文件名/文件夹名 属主有所有权限,群组和其他有读.执行 ...
- I2C总线驱动框架详解
一.I2C子系统总体架构 1.三大组成部分 (1)I2C核心(i2c-core):I2C核心提供了I2C总线驱动(适配器)和设备驱动的注册.注销方法,I2C通信方法(”algorithm”)上层的,与 ...
- BSD Socket (java)
服务器 import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java ...
- windows编程经典书籍
本人是刚刚开始学习windows编程的,感觉看雪学院的大牛很NB.想找一些书籍来看学习学习,可是不知道看哪些书好.驱动,对菜鸟们来说真是一个很深奥的话题,所以 ,我找来了这篇文章供大家分享,以后大家发 ...