日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

*【 POJ - 1007 】DNA Sorting(枚举,类似三元组找第二元问题)

發布時間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 *【 POJ - 1007 】DNA Sorting(枚举,类似三元组找第二元问题) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are out of order with respect to each other. For instance, in the letter sequence ``DAABEC'', this measure is 5, since D is greater than four letters to its right and E is greater than one letter to its right. This measure is called the number of inversions in the sequence. The sequence ``AACEDGG'' has only one inversion (E and D)---it is nearly sorted---while the sequence ``ZWQM'' has 6 inversions (it is as unsorted as can be---exactly the reverse of sorted).?

You are responsible for cataloguing a sequence of DNA strings (sequences containing only the four letters A, C, G, and T). However, you want to catalog them, not in alphabetical order, but rather in order of ``sortedness'', from ``most sorted'' to ``least sorted''. All the strings are of the same length.?

Input

The first line contains two integers: a positive integer n (0 < n <= 50) giving the length of the strings; and a positive integer m (0 < m <= 100) giving the number of strings. These are followed by m lines, each containing a string of length n.

Output

Output the list of input strings, arranged from ``most sorted'' to ``least sorted''. Since two strings can be equally sorted, then output them according to the orginal order.

Sample Input

10 6 AACATGAAGG TTTTGGCCAA TTTGGCCAAA GATCAGATTT CCCGGGGGGA ATCGATGCAT

Sample Output

CCCGGGGGGA AACATGAAGG GATCAGATTT ATCGATGCAT TTTTGGCCAA TTTGGCCAAA

題目大意:

輸入n個長度為m的DNA序列,把他們按照逆序數從小到大穩定排序輸出。定義“穩定排序”就是當序列中出現A1==A2時,排序前后A1與A2的相對位置不發生改變。(n<=50 ,?m<=100)

解題報告:

? ? ?跟這題差不多。【HihoCoder - 1550】順序三元組。就是找到枚舉每一個關鍵元素然后求和就行。

(好像正解是分治?)

AC代碼:

#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; char maze[105][55]; int num[105]; int a[105],c[105],g[105],t[105]; struct Node {int val,pos;Node(){}Node(int val,int pos):val(val),pos(pos){} } node[105]; bool cmp(const Node & a, const Node & b) {return a.val < b.val; } int main() {int n,m;cin>>m>>n;//n行m列for(int i = 1; i<=n; i++) {scanf("%s",maze[i]+1);} for(int i = 1; i<=n; i++) {for(int j = 1; j<=m; j++) {if(maze[i][j] == 'A') {a[i]++;num[i] += c[i] + g[i] + t[i];}else if(maze[i][j] == 'C') {c[i]++;num[i] += g[i] + t[i];}else if(maze[i][j] == 'G') {g[i]++;num[i] += t[i];}else t[i]++;}} // for(int i = 1; i<=n; i++) printf("%d\n",num[i]);for(int i = 1; i<=n; i++) {node[i] = Node(num[i],i);}sort(node+1,node+n+1,cmp); // for(int i = 1; i<=n; i++) { // printf("%d %d\n",node[i].pos,node[i].val); // }for(int i = 1; i<=n; i++) {printf("%s\n",maze[node[i].pos] + 1);}return 0 ; }

這題用逆序數也可以搞一發?回頭試試。類似HDU - 5775和OpenJ_Bailian - 2299

總結

以上是生活随笔為你收集整理的*【 POJ - 1007 】DNA Sorting(枚举,类似三元组找第二元问题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。