2012寒假POJ(1)
来源:互联网 发布:游戏源码吧 编辑:程序博客网 时间:2024/05/29 15:59
寒假开始了,今天上论坛看到算法版的大牛放出了一些对2011级新生的练习题;想来自己也算是2011级新生啊,当年看见人家搞ACM的牛逼的不行,自己到现在还是小菜一只,没办法厚着脸皮做一下吧;编程能力真是弱爆了,还好这个博客知道和关注的人也没几个,就在这记录一下吧。
排序POJ1007:
DNA Sorting
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 61106 Accepted: 24145
Description
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.
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 6AACATGAAGGTTTTGGCCAATTTGGCCAAAGATCAGATTTCCCGGGGGGAATCGATGCAT
Sample Output
CCCGGGGGGAAACATGAAGGGATCAGATTTATCGATGCATTTTTGGCCAATTTGGCCAAA
Source
East Central North America 1998
我的思路:题目是根据逆序数的大小来确定对应字符串的顺序,所以问题就转变为两部分:1.求逆序数 2.对应字符串的排序
实现方法:使用了C++里面的vector来存储数据,每一个元素都是一个结构体,包含字符串和它所对应的逆序数两部分,排序使用sort函数,在默认升序排序的基础上增加比较规则参数,最后直接根据排好的顺序输出字符串。
运行结果:AC。
总结:虽然在OJ上通过了,但是发现性能上不是很好,内存占用200多K,时间也花费了200ms.点开Status发现大牛的程序都是OK,1ms,相比之下我的结果真是惨不忍睹;于是在网上搜到了结题报告,果然厉害,很巧妙的解决了找到对应下标的问题:
差距很大啊,网上还有其他的方法,有兴趣的话还可以看看,不过这里用到的下标保存的方法值得学习,避免了不必要的空间开销;还有就是关于C++的STL了解的还是太少,很多好用的东西都不知道,革命尚未成功,同志仍需努力啊~
- 2012寒假POJ(1)
- 2012寒假POJ(2)
- 寒假前刷题(1)
- 寒假前刷题(5)搜索系列 bfs poj 1426
- 寒假前刷题(6)广度优先搜索 poj 3126
- POJ 1321 棋盘问题(寒假刷题之路)
- C#寒假学习笔记(1)
- 寒假学习之STM32(1)----GPIO
- 2012寒假学习计划
- 2012寒假总结
- 2011-2012寒假总结
- 2011-2012寒假总结
- 2012寒假总结
- 2012年寒假总结
- 寒假篇 -1
- 寒假作业1
- 寒假练习1_A
- 2017寒假作业1
- 基于流的I/O操作
- Fedora 16 安装 ATI显卡驱动
- PL/SQL基础编程之(十)[SQL、EM创建用户、角色][授权、配置文件、限制登录次数锁定用户]
- Hello, ISSG
- Intset实现:真正理解并掌握链表
- 2012寒假POJ(1)
- xrandr 笔记
- 信息安全常见误区
- 调试PCB板中,结果短路了,这是一个非常纠结的问题,写下解决经验
- 传智播客——学前第3天总结-2
- Struts1 和Struts 2 国际化全局资源
- 华为NAT配置
- 20120116工作记录
- 原来并不是把包放在lib文件夹下,系统就会自动添加的啊。。。