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 ...
随机推荐
- JAVA并发2
Java 5中引入了新的锁机制--java.util.concurrent.locks中的显式的互斥锁:Lock接口,它提供了比synchronized更加广泛的锁定操作.Lock接口有3个实现它的类 ...
- redis 异常排查
异常排查 redis-server redis.windows.conf D:\redis-2.8.17>redis-server.exe redis.windows.conf[4692] 27 ...
- POJ_3083——贴左右墙DFS,最短路径BFS
Description The cornfield maze is a popular Halloween treat. Visitors are shown the entrance and mus ...
- 批量将文件转换为UTF-8无BOM格式
最近有一个项目需要迁移,要把文件全部转换成utf8格式的,本来想用python,后来听说PowerShell很是强大,就试着用了一下,果然好用啊! $list = Get-ChildItem .\ - ...
- jQuery效果---隐藏与显示
隐藏与显示 index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"& ...
- 创建第一个freemarker
1.创建java项目TestFreeMarker 2.导入包freemarker.jar,添加依赖 3.在根目录下创建一个文件夹templates 4.在文件夹templates下创建文件a.ftl ...
- MYSQL触发器学习笔记
课程学至金色晨曦科技公司技术总监沙利穆 触发器 1. 什么是触发器 触发器是一种特殊类型的存储过程,不由用户直接调用.创建触发器时会对其进行定义,以便在对特定表或列作特定类型的数据修改时执 ...
- JavaScript学习笔记(高级部分—02)
47.switch语句的语法: switch (i) { case 20: alert("20"); break; case 30: alert("30"); ...
- 类型转换操作符static_cast、const_cast、dynamic_cast、reinterpret_cast
一.static_cast 对于类型转换,我们常常这么做: (type) expression 引进了static_cast类型转换操作符后,我们只需这样做: static_cast<type& ...
- C语言函数指针(转载)
二.通常的函数调用 一个通常的函数调用的例子:/* 自行包含头文件 */void MyFun(int x); /* 此处的声明也可写成:void MyFun(int) */int main(int a ...