POJ-1007
2013-04-26 19:55
190 查看
哎,这是手贱了,用java写一点都不爽,可能是我不会用java吧T_T。
这题由于数据范围小,水水就过了。
这题由于数据范围小,水水就过了。
import java.util.*; public class Main { public static void main(String[] args) { Astruct[] s = new Astruct[105]; Scanner in = new Scanner(System.in); int m = in.nextInt(); int n = in.nextInt(); for (int i=0; i<n; i++) { s[i] = new Astruct(in.next()); for (int j=0; j<m-1; j++) for (int l=j+1; l<m; l++) if (s[i].str.charAt(j) > s[i].str.charAt(l)) s[i].count++; } sort(0, n-1, s); for (int i=0; i<n; i++) System.out.println(s[i].str); } public static void sort(int l, int r, Astruct[] s) { int mid = s[(l+r) / 2].count; int i = l, j = r; while (i <= j) { while (s[i].count < mid) i++; while (s[j].count > mid) j--; if (i <= j) { if (s[i].count != s[j].count) s[i].swap(s[j]); i++; j--; } } if (i<r) sort(i,r,s); if (l<j) sort(l,j,s); } } class Astruct { public Astruct(String ss) { str = ss; count = 0; } public Astruct() {} public void swap(Astruct a) { int temp = count; count = a.count; a.count = temp; String ss = str; str = a.str; a.str = ss; } public String str; public int count; }
相关文章推荐
- poj1007——DNA Sorting
- POJ 1007 没想到暴力就能过
- poj 1007
- POJ - 1007 DNA Sorting
- poj 1007 求逆序数
- POJ 1007 DNA Sorting
- POJ-1007
- POJ 1007 DNA Sorting [解题报告] Java
- poj-1007-DNA Sorting
- poj1007 DNA排序
- 字符串 POJ-1007
- poj 1007 DNA Sorting(简单题)
- POJ-1007 DNA Sorting
- poj 1007
- poj 1007 DNA Sorting(STL运用)
- poj_acm 1007
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
- POJ 1007
- poj 1007 分治求逆序对
- POJ 1007