首页 技术 正文
技术 2022年11月6日
0 收藏 497 点赞 380 浏览 2599 个字

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

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

#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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903