zoukankan      html  css  js  c++  java
  • poj1804逆序数

    冒泡求逆序数

    View Code
    #include <iostream>
    #include <stdio.h>
    using namespace std;
    const int N=1001;
    int m[N],s[N];
    int main()
    {
    int t,n,i,j,sstep,mstep,tmp,cnt=1;
    bool flag=false;
    scanf("%d",&t);
    while(0 <= --t)
    {
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    scanf("%d",&m[i]);
    s[i]=m[i];
    }
    mstep=0;
    for(i=0;i<n-1;i++)
    {
    flag=false;
    for(j=n-1;j>i;j--)
    {
    if(s[j]<s[j-1])
    {
    flag=true;
    mstep++;
    tmp=s[j];
    s[j]=s[j-1];
    s[j-1]=tmp;
    }
    }
    if(!flag)
    break;
    }
    printf("Scenario #%d:\n%d\n\n",cnt++,mstep);
    }
    return 0;
    }

  • 相关阅读:
    相机
    播放音乐
    录音
    NSURLConnection下载
    UITableView
    UIPageControl
    UIScrollView
    ajax禁止浏览器缓存
    java替换word2003
    退出登录
  • 原文地址:https://www.cnblogs.com/buptLizer/p/2185919.html
Copyright © 2011-2022 走看看