cf C. Insertion Sort
http://codeforces.com/contest/362/problem/C
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int a[];
int c[];
int n; int lowbit(int x)
{
return x&(-x);
} void add(int x)
{
while(x>)
{
c[x]++;
x-=lowbit(x);
}
} int sum(int x)
{
int sum1=;
while(x<=n)
{
sum1+=c[x];
x+=lowbit(x);
}
return sum1;
} int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
a[i]++;
}
int t1=,temp,t2=;
int max1=-;
for(int i=; i<n; i++)
{
memset(c,,sizeof(c));
for(int j=i+; j<=n; j++)
{
if(a[i]>a[j])
{
t1++;
temp=+*sum(a[j]);
if(temp>max1) {max1=temp; t2=;}
if(temp==max1) t2++;
add(a[j]);
}
}
}
printf("%d %d\n",t1-max1,t2);
}
return ;
}
cf C. Insertion Sort的更多相关文章
- [LeetCode] Insertion Sort List 链表插入排序
Sort a linked list using insertion sort. 链表的插入排序实现原理很简单,就是一个元素一个元素的从原链表中取出来,然后按顺序插入到新链表中,时间复杂度为O(n2) ...
- 经典排序算法 – 插入排序Insertion sort
经典排序算法 – 插入排序Insertion sort 插入排序就是每一步都将一个待排数据按其大小插入到已经排序的数据中的适当位置,直到全部插入完毕. 插入排序方法分直接插入排序和折半插入排序两种, ...
- leetcode Insertion Sort List
题目:Sort a linked list using insertion sort. 代码: /** * Definition for singly-linked list. * struct Li ...
- 【leetcode】Insertion Sort List (middle)
Sort a linked list using insertion sort. 思路: 用插入排序对链表排序.插入排序是指每次在一个排好序的链表中插入一个新的值. 注意:把排好序的部分和未排序的部分 ...
- 9. Sort List && Insertion Sort List (链表排序总结)
Sort List Sort a linked list in O(n log n) time using constant space complexity. H ...
- LeetCode OJ 147. Insertion Sort List
Sort a linked list using insertion sort. Subscribe to see which companies asked this question 解答 对于链 ...
- Java for LeetCode 147 Insertion Sort List
Sort a linked list using insertion sort. 解题思路: 插入排序,JAVA实现如下: public ListNode insertionSortList(List ...
- 【LeetCode OJ】Insertion Sort List
Problem: Sort a linked list using insertion sort. The node of the linked list is defined as: /** * D ...
- 147. Insertion Sort List
Sort a linked list using insertion sort. 代码如下: /** * Definition for singly-linked list. * public cla ...
随机推荐
- 【转】如何在 Android 程序中禁止屏幕旋转和重启Activity
原文网址:http://www.cnblogs.com/bluestorm/p/3665890.html 禁止屏幕随手机旋转变化 有时候我们希望让一个程序的界面始终保持在一个方向,不随手机方向旋转而变 ...
- 小记UNIX编程库调用.
更好的文章:http://www.cppblog.com/deane/articles/165216.html 静态库生成:(举例加法库) 1.编程源程序 add.h add.c 2.编译源程序,生成 ...
- POJ_1321——棋盘问题,回溯+剪枝
Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子 ...
- HDU_2029——回文串的判断
Problem Description “回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串.请写一个程序判断读入的字符串是否是“回文”. Input 输入包 ...
- 公告:本博客搬迁到:http://www.courtiercai.com/
公告: 您好,本人意见本博客搬迁到:http://www.courtiercai.com/.
- zookeeper[4] 安装windows zookeeper,及问题处理
安装步骤: 1.在如下路径下载zookeeper-3.4.7.tar.gz http://mirrors.cnnic.cn/apache/zookeeper/stable/ 2.解压zookeeper ...
- javascript 缓冲运动demo
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Jmeter命令行运行实例讲解
1. 简介 使用非 GUI 模式,即命令行模式运行 JMeter 测试脚本能够大大缩减所需要的系统资 本文介绍windows下以命令行模式运行的方法. 1.1. 命令介绍 jmeter -n -t & ...
- Android Clipboard(复制/剪贴板)
Android提供的剪贴板框架,复制和粘贴不同类型的数据.数据可以是文本,图像,二进制流数据或其它复杂的数据类型. Android提供ClipboardManager.ClipData.Item和Cl ...
- 我的创业劲儿,无可阻挡-JAVA学院张孝伟
导语:张孝伟,这个怀揣着创业梦想的农村小伙,为了报答父母的恩情,他开启了自己的逐梦之旅.友好的伙伴,火旺的生意.以前让他如鱼得水.就在他满足于现状的时候,一场突如其来的事故,让他一夜间倾家荡产.他是否 ...