题名:DNA排序

题意:给定字符串长度、个数,计算每个字符串的逆序数,然后从大到小排列,有兴趣的可以去看下原题。

计算字符串逆序数,然后排序,这里使用了快速排序算法,string释放的时候竟然有问题,直接字符数组吧。

// 1007.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <iostream>
#include <algorithm>
using namespace std;
class data
{
public:
char s[];
int c;
};
int partion(data a[],int p,int r){
int x = a[r].c; //通常,拿最后一个值,作为预期的中间值
int middle = p; //记录“较小的一段数据”的最大下标。通常这个值在p和r的中间,故起名middle
data *temp=new data;
for (int j = p ; j < r ; j++){
if (a[j].c < x){ memcpy(temp,&a[middle],sizeof(data));
//int temp = a[middle].c;
memcpy(&a[middle],&a[j],sizeof(data));
//a[middle] = a[j];
memcpy(&a[j],temp,sizeof(data));
//a[j] = temp;
middle++;
}
}
//int temp = a[r];
memcpy(temp,&a[r],sizeof(data));
//a[r] = a[middle];
memcpy(&a[r],&a[middle],sizeof(data));
//a[middle] = temp;
memcpy(&a[middle],temp,sizeof(data));
delete temp;
return middle;
} void QuickSort(data a[],int p,int r){
if (p<r){
int q=partion(a,p,r);
QuickSort(a,p,q-);
QuickSort(a,q+,r);
}
} int main(int argc, char* argv[])
{
int slen=,snum=;
cin>>slen>>snum;
int count=;
char temp[]={}; data *d1=new data[snum];
while (count<snum)
{
cin>>temp;
strcpy(d1[count].s,temp);
int bigTimes=;
for (int i=;i<strlen(temp)-;i++)//计算大的次数
{
for (int j=i+;j<strlen(temp);j++)
{
if(temp[i]>temp[j])
bigTimes++; }
}
d1[count].c=bigTimes;
count++;
}
QuickSort(d1,,count-);
for (int i=;i<count;i++)
{
//strcpy(temp,d1[i].s.c_str());
cout<<d1[i].s<<endl;
}
delete []d1;
return ;
}

PKU 1007的更多相关文章

  1. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  2. SCNU 2015ACM新生赛初赛【1007. ZLM的扑克牌】解题报告

            题目链接详见SCNU 2015新生网络赛 1007. ZLM的扑克牌 .         其实我在想这题的时候,还想过要不要设置求最小的排列,并且对于回文数字的话,可以把扑克牌折起来( ...

  3. PKu 2195

    //PKu 2195 回家 By Loli_con Enail : Loli_con@outlook.com /* 题目叙述 ========= 在一个网格图中,有n个人和n个房子.每一个单位时间,每 ...

  4. sicily 1007. To and Fro 2016 11 02

    // Problem#: 1007// Submission#: 4893204// The source code is licensed under Creative Commons Attrib ...

  5. 【HDU 1007】Quoit Design

    http://acm.hdu.edu.cn/showproblem.php?pid=1007 最近欧式距离模板题. 用分治大法(分治的函数名用cdq纯属个人习惯_(:з」∠)_) 一开始狂M. 后来判 ...

  6. 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design

    题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...

  7. poj 1007 DNA Sorting 解题报告

    题目链接:http://poj.org/problem?id=1007 本题属于字符串排序问题.思路很简单,把每行的字符串和该行字符串统计出的字母逆序的总和看成一个结构体.最后把全部行按照这个总和从小 ...

  8. 【BZOJ】 1007: [HNOI2008]水平可见直线(凸壳)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1007 一开始我贪心的写了下,当然全wa了.. 这题看了题解感觉很简单. 首先什么情况才能看到呢? w ...

  9. HDU 1007 Quoit Design(二分+浮点数精度控制)

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

随机推荐

  1. js判断数据类型

    1.判断一个数字是否是无穷的 isFinite()例:var aa=Number.POSITIVE_INFINITY; if(isFinite(aa)){ alert("aa不是无穷的&qu ...

  2. 《JAVA与模式》之单例模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述单例模式的: 作为对象的创建模式,单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例.这个类称为单例类. 单例模式的 ...

  3. About “this” of Javascript

    the 4 point about This: 1.the use of Object methods 2.the use of constructors 3.the use of ordinary ...

  4. 简化通过classname查找 方法

    function getClass(oParent,sclass){ var aEle=oParent.getElementsByTagName('*'); var result=[]; for(va ...

  5. C——没有bool的C语言?

    bool static my_var_initialized = false; 偶然写出了这样一句C代码,环境是visual studio 2012,工程是Compile as C的,竟然报了好几个错 ...

  6. Debian/Ubuntu/CentOS VPS安装Net-Speeder并优化

    安装过程: CentOS安装 wget --no-check-certificate https://gist.github.com/LazyZhu/dc3f2f84c336a08fd6a5/raw/ ...

  7. cp命令

    [root@www ~]# cp [-adfilprsu] 来源文件(source) 目标文件(destination) [root@www ~]# cp [options] source1 sour ...

  8. C++中的字面值指定类型

    C++中只有内置类型存在字面值,没有类(class)类型字面值.例如:0是int类型的字面值,3.14159是double类型的字面值. 字面值类型很多 整型浮点字面值 20             ...

  9. WebPack 简明学习教程

    WebPack 简明学习教程 字数1291 阅读22812 评论11 喜欢35 WebPack是什么 一个打包工具 一个模块加载工具 各种资源都可以当成模块来处理 网站 http://webpack. ...

  10. django:field字段类型

    字段类型(Field types) AutoField 它是一个根据 ID 自增长的 IntegerField 字段.通常,你不必直接使用该字段.如果你没在别的字段上指定主 键,Django 就会自动 ...