hdu 2689

超级大水题。。。。两种代码都过了,开始以为n^2会tle,后来竟然过了。。。汗

注意下cin写在while里面,就可以了

#include <iostream>
using namespace std;
int main()
{
int n,i,j,a[1010];
while(cin>>n)
{
for(i=1; i<=n; i++)
cin>>a[i];
int cnt = 0;
for(i=1; i<=n; i++)
for(j=i+1; j<=n; j++)
if(a[i]>a[j])
cnt++;
cout<<cnt<<endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int a[1010],i,j,temp,cnt,n;
while(cin>>n){ cnt = 0;
for(i=1;i<=n;i++)
cin>>a[i];
for(i=1;i<n;i++)
for(j=1;j<=n-i;j++)
{
if(a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
cnt++;
}
}
cout<<cnt<<endl;
}
return 0;
}

hdu 2689的更多相关文章

  1. HDU 2689 Sort it (树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2689 Sort it Problem Description You want to processe ...

  2. hdu 2689 Sort it

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2689 题目分析:求至少交换多少次可排好序,可转换为逆序对问题. 用冒泡排序较为简单,复杂度较大~~ 也 ...

  3. HDU 2689 Sort it【树状数组】

    Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  4. HDU 2689 sort it - from lanshui_Yang

    Problem Description You want to processe a sequence of n distinct integers by swapping two adjacent ...

  5. HDU 2689.Sort it-冒泡排序

    Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  6. HDU - 2689 Sort it与2016蓝桥杯B 交换瓶子 排序(相邻交换与任意交换)

    Sort it You want to processe a sequence of n distinct integers by swapping two adjacent sequence ele ...

  7. HDU 2689 Tree

    Tree Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  8. BIT 树状数组 详解 及 例题

    (一)树状数组的概念 如果给定一个数组,要你求里面所有数的和,一般都会想到累加.但是当那个数组很大的时候,累加就显得太耗时了,时间复杂度为O(n),并且采用累加的方法还有一个局限,那就是,当修改掉数组 ...

  9. 数学#素数筛法 HDU 4548&POJ 2689

    找素数本来是很简单的问题,但当数据变大时,用朴素思想来找素数想必是会超时的,所以用素数筛法. 素数筛法 打表伪代码(用prime数组保存区间内的所有素数): void isPrime() vis[]数 ...

随机推荐

  1. Bootstrap中的 Typeahead 组件

    Bootstrap 中的 Typeahead 组件其实就是嵌入到其中的typeahead.js插件,可以完成输入框的自动匹配功能,在通过一些人工的调整基本可以胜任所有的匹配功能和场景,下面介绍下简单的 ...

  2. 让 IE6/7/8 也支持HTML5标签的方式

    方式一:引入Google的HTML5.js线上文件 <!–[if lt IE9]> <script src="http://html5shiv.googlecode.com ...

  3. PhotoShop 移动工具详解

    自动选择工具 勾选后  可以随意移动任意图层     不勾选  只适用于移动当前所选图层 Ctrl+Z 还原移动Ctrl+Alt+Z 后退一步 复制图像 Alt键+拖动 Shift+Alt+拖动   ...

  4. sql 语句左连接右连接小例子

    A表(a1,b1,c1) B表(a2,b2) a1 b1 c1 a2 b2 01 数学 95 01 张三 02 语文 90 02 李四 03 英语 80 04 王五 select A.*,B.* fr ...

  5. c#中方法out参数的使用

    一个很普通的例题,求出一个整型数组的最小值.最大值.总和.平均值,利用调用函数的方法来ut参数实现 using System; using System.Collections.Generic; us ...

  6. Sequence

    http://poj.org/problem?id=2442 用STL写的时间为:5657MS #include<cstdio> #include<algorithm> #in ...

  7. RUBY类特性

    学习教材 class Person def initialize(name,age=18) @name=name @age=age @motherland="China" end ...

  8. 【HDOJ】1310 Team Rankings

    STL的应用,基本就是模拟题. /* 1410 */ #include <iostream> #include <string> #include <algorithm& ...

  9. -_-#【Backbone】Collection

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. (2015年郑州轻工业学院ACM校赛题) C 数列

    在我们做完B题之后就去看C题了, 发现很多人都已经做出来了, 并且一血还是我们学弟拿的, 感觉这题不难, 我们举了几个例子之后发现全是Alice 然后我们就决定意淫一下,试试看! 没想到就A了 - . ...