https://cn.vjudge.net/problem/HihoCoder-1384

题目

Advanced CPU Manufacturer (ACM) is one of the best CPU manufacturer in the world. Every day, they manufacture n CPU chips and sell them all over the world.

As you may know, each batch of CPU chips must pass a quality test by the QC department before they can be sold. The testing procedure is as follows:

1) Randomly pick m pairs of CPU chips from the batch of chips (If there are less than 2m CPU chips in the batch of chips, pick as many pairs as possible.)

2) For each pair, measure the Relative Performance Difference (RPD) between the two CPU chips. Let Di be the RPD of the i-th pair

3) Calculate the Sqared Performance Difference (SPD) of the batch according to the following formula:

\[\text{SPD}=\sum D_i^2\]

If there are only 1 CPU in a batch, then the SPD of that batch is $0$.

4) The batch of chips pass the test if and only if $\text{SPD}\leqslant k$, where $k$ is a preseted constant

Usually they send all the n CPU chips as a single batch to the QC department every day. As one of the best CPU manufacturer in the world, ACM never fail the test. However, with the continuous improvement of CPU performance, they find that they are at risk!

Of course they don't want to take any risks. So they make a decision to divide the n chips into several batches to ensure all of them pass the test. What’s more, each batch should be a continuous subsequence of their productions, otherwise the QC department will notice that they are cheating. Quality tests need time and money, so they want to minimize the number of batches.

Given the absolute performance of the $n$ chips $P_1$ ... $P_n$ mesured by ACM in order of manufacture, your task is to determine the minimum number of batches to ensure that all chips pass the test. The RPD of two CPU chips equals to the difference of their absolute performance.

Input

The first line contains a single integer $T$, indicating the number of test cases.

In each test case, the first line contains three integers $n$, $m$, $k$. The second line contains $n$ integers, $P_1$ ... $P_n$.

T≤12
    1≤n,m≤5×105
    0≤k≤1018
    0≤Pi≤220
Output

For each test case, print the answer in a single line.
Sample Input

2
    5 1 49
    8 2 1 7 9
    5 1 64
    8 2 1 7 9

Sample Output

2
    1

题解

贪心+倍增

考虑一个区间,为了保险,选最大的和最小的为一对。因为$(a+\delta_1)^2+(b-\delta_2)^2\geqslant a^2+b^2$。

可以分段排序后归并,分段排序$\mathcal{O}(n\log n)$,归并$\mathcal{O}(n)$,选对$\mathcal{O}(n)$,加起来$\mathcal{O}(n\log n)$……

倍增:pos+step,成功就step*=2,失败就step/=2,step到0时考虑下一区间。

数据规模有点大,用了读写挂= =

AC代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<iomanip>#define REP(r,x,y) for(register int r=(x); r<(y); r++)
#define REPE(r,x,y) for(register int r=(x); r<=(y); r++)
#ifdef sahdsg
#define DBG(...) printf(__VA_ARGS__)
#else
#define DBG(...) (void)0
#endifusing namespace std;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;char ch; int f;
template <class T>
inline void read(T &x) {x=0; f=1; do ch=getchar(); while(!isdigit(ch) && ch!='-');if(ch=='-') ch=getchar(),f=-1; while(isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();} x*=f;
}
//template <class T, class ...P> inline void read(T &x, P &...y) {read(x); read(y...);}
#define MAXN 500007int n,m;
LL k;
int oar[MAXN];
int arr[MAXN];
int sd[MAXN];
int nar[MAXN];
int pos=0, step=1;
int l=0;
inline LL pf(int x) {return (LL)x*x;
}
inline bool vali() {memcpy(nar+pos,oar+pos,step*sizeof(int));sort(nar+pos, nar+pos+step);int l1=l, l2=pos, r1=pos, r2=pos+step;int N=pos+step;REP(i,l,N) {if(l2>=r2 || (l1<r1 && nar[l2]>=arr[l1]) ) sd[i]=arr[l1++];else sd[i]=nar[l2++];}int M=min(m+l,(N+l)/2);LL s=0;REP(i,l,M) {s+=pf(sd[i]-sd[N+l-i-1]);if(s>k) return false;}REP(i,l,N) {arr[i]=sd[i];}return true;
}
int main() {int t;read(t);while(t--) {read(n); read(m); read(k);pos=0, step=1, l=0;REP(i,0,n) {read(oar[i]);}int ans=0;while(l<n) {ans++;step=1;while(step && pos<n) {if(vali()) {pos+=step;step=min(step*2,n-pos);} else {step/=2;}}l=pos;}printf("%d\n", ans);}return 0;
}

转载于:https://www.cnblogs.com/sahdsg/p/10673076.html

HihoCoder 1384 Genius ACM相关推荐

  1. hihoCoder #1384 : Genius ACM [枚举+倍增]

    描述 Advanced CPU Manufacturer (ACM) is one of the best CPU manufacturer in the world. Every day, they ...

  2. hihoCoder#1384 : Genius ACM

    对于一个固定的区间$[l,r]$,显然只要将里面的数字从小到大排序后将最小的$m$个和最大的$m$个配对即可. 如果固定左端点,那么随着右端点的右移,$SPD$值单调不降,所以尽量把右端点往右移,贪心 ...

  3. [hihoCoder 1384]Genius ACM

    Description 题库链接 给定一个整数 \(M\),对于任意一个整数集合 \(S\),定义"校验值"如下: 从集合 \(S\) 中取出 \(M\) 对数(即 \(2\tim ...

  4. CH - 0601 Genius ACM(倍增+归并排序)

    题目链接:点击查看 题目大意: 给定一个正整数M,对于任意一个整数集合S,定义"检验值"如下: 从集合S中取出M对数(即2*M个数,不能重复使用集合中的数,如果S中的整数不够M对, ...

  5. 0x06.基本算法 — 倍增

    目录 一.倍增 0.例题引入 1.AcWing 109.Genius ACM(归并+倍增) 二.ST算法 2.luogu P3865 [模板]ST表 三.求LCA(Least Common Ances ...

  6. 最短路径问题经典题目汇总

    50道数据结构最短路径问题 HDU 1142 http://acm.hdu.edu.cn/showproblem.php?pid=1142 HDU 1217 http://acm.hdu.edu.cn ...

  7. 《算法竞赛进阶指南》刷题记录

    总算闲下来一些辣!然后最近发现其实看书是真真很有效但是一直没有落实!所以决定落实一下这段时间把这本书看完题目做完! 然后发现还有挺多题目挺巧妙的于是一堆博客预警,,,可能最近会写很多比较水(但是我还是 ...

  8. 《算法竞赛进阶》学习笔记

    N数码判定性问题 大意就是给你两个N数码(N为奇数),判定是否能互相转化的问题 首先展开成一维,空格不计 如 1 2 3 4 5 6 7 0 8转化为1 2 3 4 5 6 7 8 然后判断两个序列的 ...

  9. ST算法 - RMQ(区间最值问题)—— 倍增

    文章目录 引入倍增: 例题1:区间和 例题2:Genius ACM 应用: ST算法 求解 RMQ(区间最值问题) 模板Code: 练习题: ST算法 维护区间最大公约数 例题:Pair of Num ...

  10. 【读书笔记】《算法竞赛进阶指南》读书笔记——0x00基本算法

    to-do: 例题: POJ 1845 Sumdiv 所有的课后习题: 随缘~~~ 位运算 对于一个二进制数,通常称其最低位为第0位,从右往左依此类推. 补码 unsigned int 直接将其看作3 ...

最新文章

  1. 【资源总结】国内AI领域的赛事全集
  2. 二十二、“此生无悔入华夏,来世还在种花家”(2021.7.1)
  3. socket buffer套接字缓存
  4. JavaScript遍历DOM
  5. 移动端跨平台框架分析
  6. Web浏览器测试,怎么提取测试点 - web测试方法总结
  7. 御剑端口扫描工具2020下载
  8. 凹点匹配 matlab源码,粘连类圆形目标图像的分割方法与流程
  9. 第三方支付平台如何对接?
  10. 明翰英语教学系列之形容词与副词篇V0.1(持续更新)
  11. android linux 双系统实现(android+buster)同时运行
  12. SAP BASIS ADM100 中文版 Unit 9(5)
  13. linux系统的种类
  14. loraserver 源码解析 (六) lora-app-server
  15. 【推荐】javaweb JAVA JSP家政服务管理系统服务网站jsp服务信息管理jsp保姆月嫂招聘系统案例设计与实现源码
  16. 组合导航(一):定位技术分类与介绍
  17. 【Linux 内核 内存管理】分区伙伴分配器 ② ( free_area 空闲区域结构体源码 | 分配标志位 | GFP_ZONE_TABLE 标志位区域类型映射表 |分配标志位对应的内存区域类型 )
  18. mysql数据库表添加列的语句(例子)
  19. 【清华大学-郑莉教授】C++语言程序设计 类与对象
  20. 他是国家的儿子 如不再优秀请原谅他

热门文章

  1. 如何使用MyBatis-Plus中的代码生成器?
  2. PS快速更换照片背景色【一寸照片效果最好】
  3. 阿里腾讯进击韩国互联网
  4. 文本加密(PTA厦大慕课)
  5. Unknown column 'hghefsdhjd' in 'where clause'
  6. 龙之谷手游微信连接授权服务器失败,龙之谷手游ios微信授权失败怎么办_龙之谷手游ios微信授权失败解决办法-66街机网...
  7. javascript创建表格
  8. 【转载】学习可能用到的英语单词
  9. 【吐血整理】超全golang面试题合集+golang学习指南+golang知识图谱+成长路线 一份涵盖大部分golang程序员所需要掌握的核心知识。
  10. android 墓碑日志,关于清明节扫墓的日记