hdu 2689
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的更多相关文章
- HDU 2689 Sort it (树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2689 Sort it Problem Description You want to processe ...
- hdu 2689 Sort it
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2689 题目分析:求至少交换多少次可排好序,可转换为逆序对问题. 用冒泡排序较为简单,复杂度较大~~ 也 ...
- HDU 2689 Sort it【树状数组】
Sort it Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU 2689 sort it - from lanshui_Yang
Problem Description You want to processe a sequence of n distinct integers by swapping two adjacent ...
- HDU 2689.Sort it-冒泡排序
Sort it Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU - 2689 Sort it与2016蓝桥杯B 交换瓶子 排序(相邻交换与任意交换)
Sort it You want to processe a sequence of n distinct integers by swapping two adjacent sequence ele ...
- HDU 2689 Tree
Tree Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- BIT 树状数组 详解 及 例题
(一)树状数组的概念 如果给定一个数组,要你求里面所有数的和,一般都会想到累加.但是当那个数组很大的时候,累加就显得太耗时了,时间复杂度为O(n),并且采用累加的方法还有一个局限,那就是,当修改掉数组 ...
- 数学#素数筛法 HDU 4548&POJ 2689
找素数本来是很简单的问题,但当数据变大时,用朴素思想来找素数想必是会超时的,所以用素数筛法. 素数筛法 打表伪代码(用prime数组保存区间内的所有素数): void isPrime() vis[]数 ...
随机推荐
- jvectormap 中国地图 (包括香港、台湾、澳门)
一个完整的中国地图(各个省,市.还有国两制),谢谢大家. 忘了网上哪位的范例,我加了些修改. <html xmlns="http://www.w3.org/1999/xhtml&quo ...
- 无法解析属性“mode”的值。错误为: 枚举值必须是以下各值中的一个: RemoteOnly, On, Off。
Off首字母要大写,注意大小写 <customErrors mode="Off"> <error statusCode="404" ...
- 使用Code::Blocks配置Python编译环境
1.先在CodeBlock中新建C或C++工程. CodeBlock新建工程步骤:File——New——Project——Console applications——C或C++都可——Project所 ...
- .net FrameWork4.0安装未成功
安装了一上午的.net framework 4.0,各种失败,查了好多答案,各种不靠谱,最后终于找到答案了 和Windows Update有关系,给目录名重命名一下再次安装,即安装成功了! 下载地址: ...
- poj 2488A Knight's Journey
#include<cstdio> #include<cstring> #define MAXN 26 using namespace std; ,,-,,-,,-,}; ,-, ...
- Asteroids
http://poj.org/problem?id=3041 #include<cstdio> #include<cstring> #include<algorithm& ...
- Android ANR、Force Closed(转)
ANRs (“Application Not Responding”),意思是”应用没有响应“. 在如下情况下,Android会报出ANR错误: – 主线程 (“事件处理线程” / “UI线程”) 在 ...
- MySQL全连接(Full Join)实现,union和union all用法
MySQL本身不支持你所说的full join(全连接),但可以通过union来实现 ,下面是一个简单测试,可以看看: mysql> CREATE TABLE a(id int,name cha ...
- 那些SQL语句
根据book_id,class_id确定老师uid select user_id from lessons left join book on lessons.lesson_id = book.les ...
- 【转】Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果--不错
原文网址:http://blog.csdn.net/xiaanming/article/details/10163203 转载请注明出处:http://blog.csdn.net/xiaanming/ ...