说是排序结果就是各种奇技淫巧

中位数被坑多了久病成医,例题一题搞笑一题糖果传递(昨晚精神那么好效率还那么差)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL; int n,m,T;
LL X[],Y[],s[];
LL reX()
{
LL ave=T/n;
for(int i=;i<=n;i++)s[i]=s[i-]+ave-X[i];
sort(s+,s+n+);
LL ret=;
for(int i=;i<=n;i++)
ret+=abs(s[i]-s[(n+)/]);
return ret;
}
LL reY()
{
LL ave=T/m;
for(int i=;i<=m;i++)s[i]=s[i-]+ave-Y[i];
sort(s+,s+m+);
LL ret=;
for(int i=;i<=m;i++)
ret+=abs(s[i]-s[(m+)/]);
return ret;
} int main()
{
int x,y;
scanf("%d%d%d",&n,&m,&T);
for(int i=;i<=T;i++)
scanf("%d%d",&x,&y), X[x]++, Y[y]++;
if(T%n==&&T%m==)printf("both %lld\n",reX()+reY());
else if(T%n==)printf("row %lld\n",reX());
else if(T%m==)printf("column %lld\n",reY());
else printf("impossible\n");
return ;
}

bzoj3032

有一个叫对顶堆“算法”的东西,超级搞笑,就是在线求中位数,用两个堆一个存一半,应该是因为我见过类似的套路bzoj3192: [JLOI2013]删除物品,就没意思了。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
typedef long long LL; priority_queue<int> h;
priority_queue< int,vector<int>,greater<int> > t; int aslen,as[];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int zz,n;
scanf("%d%d",&zz,&n);
while(!h.empty())h.pop();
while(!t.empty())t.pop(); aslen=;int x,mid;
h.push(-);
t.push();
for(int i=;i<=n;i++)
{
scanf("%d",&x);
if(i%==)
{
if(x<h.top()) mid=h.top(), h.pop(), h.push(x);
else if(t.top()<x) mid=t.top(), t.pop(), t.push(x);
else mid=x;
as[++aslen]=mid;
h.push(mid);
}
else
{
if(x<h.top()) t.push(h.top()) ,h.pop() , h.push(x);
else h.push(t.top()) ,t.pop() , t.push(x); if(h.size()>t.size()) t.push(h.top()) ,h.pop();
else if(h.size()<t.size()) h.push(t.top()) ,t.pop();
}
} printf("%d %d\n",zz,aslen);
for(int i=;i<=aslen;i++)
{
printf("%d ",as[i]);
if(i%==)printf("\n");
}
if(aslen%!=)printf("\n");
}
return ;
}

poj3784

好像有个O(n)求第k大,但是没有例题口胡一下,就相当于splay的做法,分成左右两个区域,然后判断tot和k应该往哪边。

我觉得这东西应该没什么用,只问第k大的没多少吧,而且假如是在线问题的话肯定问很多次,每次O(n)太慢了2333

逆序对就没什么东西了(毕竟也是会cdq分治的)

但是n*m数码问题的有解性判定没见过,虽然简单就不口胡了。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std; int n,m;
int len,ans,a[],tt[];
void fenzi(int l,int r)
{
if(l==r)return ;
int mid=(l+r)/;
fenzi(l,mid);fenzi(mid+,r); int i=l,j=mid+,p=l;
while(i<=mid&&j<=r)
{
if(a[i]<=a[j])
{
ans+=j-(mid+);
tt[p++]=a[i++];
}
else
{
tt[p++]=a[j++];
}
}
while(i<=mid)
{
ans+=j-(mid+);
tt[p++]=a[i++];
}
while(j<=r)
{
tt[p++]=a[j++];
} for(int i=l;i<=r;i++)a[i]=tt[i];
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==&&m==)break;
int dis;len=;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
{
len++;
scanf("%d",&a[len]);
if(a[len]==)dis=n-i,len--;
}
ans=;fenzi(,len);
if(m%==&&ans%==)printf("YES\n");
else if(m%==&&(ans+dis)%==)printf("YES\n");
else printf("NO\n");
}
return ;
}

poj2893

0x05 排序的更多相关文章

  1. 2019CSP-S初赛知识点汇总

    0x00 基本算法 0x01 位运算 0x02 前缀和与差分 0x03 二分 0x04 倍增 0x05 排序 0x06 离散化 0x07 高精度 0x10 数据结构 0x11 栈和队列 0x12 链表 ...

  2. 算法竞赛进阶指南 0x00 基本算法

    放在原来这个地方不太方便,影响阅读体验.为了读者能更好的刷题,另起一篇随笔. 0x00 基本算法 0x01 位运算 [题目][64位整数乘法] 知识点:快速幂思想的灵活运用 [题目][最短Hamilt ...

  3. javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈

    Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...

  4. iOS可视化动态绘制八种排序过程

    前面几篇博客都是关于排序的,在之前陆陆续续发布的博客中,我们先后介绍了冒泡排序.选择排序.插入排序.希尔排序.堆排序.归并排序以及快速排序.俗话说的好,做事儿要善始善终,本篇博客就算是对之前那几篇博客 ...

  5. JavaScript实现常用的排序算法

    ▓▓▓▓▓▓ 大致介绍 由于最近要考试复习,所以学习js的时间少了 -_-||,考试完还会继续的努力学习,这次用原生的JavaScript实现以前学习的常用的排序算法,有冒泡排序.快速排序.直接插入排 ...

  6. [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序

    用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html  目录 马桶排序(令人 ...

  7. 算法与数据结构(十三) 冒泡排序、插入排序、希尔排序、选择排序(Swift3.0版)

    本篇博客中的代码实现依然采用Swift3.0来实现.在前几篇博客连续的介绍了关于查找的相关内容, 大约包括线性数据结构的顺序查找.折半查找.插值查找.Fibonacci查找,还包括数结构的二叉排序树以 ...

  8. 算法与数据结构(七) AOV网的拓扑排序

    今天博客的内容依然与图有关,今天博客的主题是关于拓扑排序的.拓扑排序是基于AOV网的,关于AOV网的概念,我想引用下方这句话来介绍: AOV网:在现代化管理中,人们常用有向图来描述和分析一项工程的计划 ...

  9. 使用po模式读取豆瓣读书最受关注的书籍,取出标题、评分、评论、题材 按评分从小到大排序并输出到txt文件中

    #coding=utf-8from time import sleepimport unittestfrom selenium import webdriverfrom selenium.webdri ...

随机推荐

  1. Spring《八》AOP/代理类定义

    Spring通知 Interception Around通知 MethodInterceptor类(方法执行前后通知) Before通知 MethodBeforeAdvice类(方法执行前通知) Af ...

  2. 导入Excel时去除多余的空白行

    https://blog.csdn.net/shuishousuiyue/article/details/44773987 按着上面链接用的第一种方式,如下图所示:第二种方式要遍历每一个Excel单元 ...

  3. 关于FastIo

    由于你的驱动将要绑定到文件系统驱动的上边,文件系统除了处理正常的IRP 之外,还要处理所谓的FastIo.FastIo是Cache Manager 调用所引发的一种没有irp 的请求.换句话说,除了正 ...

  4. Git Learning Part III - working remotely (Github)

    help document of Github : https://help.github.com/ 1 upload 1.1 new update  Initialize a repository  ...

  5. mybatis 高级映射和spring整合之逆向工程(7)

    mybatis 高级映射和spring整合之逆向工程(7) 4.0 逆向工程 4.1 mybatis需要程序员自己编写sql语句,mybatis官方提供逆向工程,可以针对单表自动生成mybatis执行 ...

  6. Windows平台上使用ANT编译Hadoop Eclipse Plugin

    一.准备工作:   1.安装JDK 下载页面:http://www.oracle.com/technetwork/java/javase/downloads/index.html JDK6,JDK7都 ...

  7. 命令模式 Command design pattern in C++

    参考https://sourcemaking.com/design_patterns/command/cpp/2 Create a class that encapsulates some numbe ...

  8. 关于《Python核心编程》第2版和第3版

    关于<Python核心编程>第2版和第3版 以前开始学Python的时候,根据某大神的建议买了本<Python核心编程>第2版,慢慢学习.而最近回家没带书回来,刚好JD有活动, ...

  9. Java中的强制转换

    特点: 1.需要程序员手动修改代码 2.语法:范围小的类型 变量名 = (范围小的类型)范围大的类型的数据 3.从范围小 到 范围大  注意: 强制类型转换可能会造成数据的丢失哦,小伙伴们在应用时一定 ...

  10. day06-08面向对象的三大特性

    一.继承 1.1什么是继承?继承是一种创建新类的方式,在python中,新建的类可以继承一个或多个父类,父类又可称为基类或超类,新建的类称为派生类或子类python中类的继承分为:单继承和多继承 cl ...