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[]数 ...
随机推荐
- angularJS中XHR与promise
angularJS应用是完全运行在客户端的应用,我们可以通过angularJS构建一个不需依赖于后端,同时能够实现动态内容和响应的web应用,angularJS提供了将应用与远程服务器的信息集成在一起 ...
- 移动端html5重力感应
下面是测试案例,只测试过itouch,iphone http://06wjin.sinaapp.com/billd/ http://06wjin.sinaapp.com/billd/test. ...
- Symmetry(对称轴存在问题)
Symmetry Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description Th ...
- C# windows窗体程序打包安装及卸载
一.新建安装部署项目
- APP如何设计才能适配iphone6/plus和iphone5
随着苹果发布两种新尺寸的大屏iPhone 6,iOS平台尺寸适配问题终于还是来了,移动设计全面进入"杂屏"时代.看看下面三款iPhone尺寸和分辨率数据就知道屏幕有多杂了. 移动a ...
- 上海招聘FPGA讲师(专兼职均可)
上海招聘FPGA讲师(专兼职均可) 招聘FPGA培训讲师(专兼职均可) 诚聘FPGA培训讲师_软件无线电方向 ◆精通FPGA设计方法及技巧 ◆精通无线电知识及System View设计方法,有基于Sy ...
- JS基于时间戳写的浏览访问人数
Title:JS基于时间戳写的浏览访问人数 --2013-12-23 14:07 <script language="JavaScript"> var timesta ...
- java 上传图片 打水印
其实就是在现有的图片上,画东西,也可以直接 贴图片 //添加水印 @Override public File pressFile(File file,String press_path) throws ...
- 【HDOJ】3587 NUDOTA
字符串模拟水题. /* 3587 */ #include <iostream> #include <cstdio> #include <cstring> #incl ...
- 两台windows服务器----SVN的迁移
两台服务器,进行SVN的迁移:系统平台:windows server 2003 版本库:test源服务器:192.168.1.14目标服务器:192.168.1.12源SVN版本库的path: D:\ ...