3969: [WF2013]Low Power

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://www.lydsy.com/JudgeOnline/problem.php?id=3969

Description

有n个机器,每个机器有2个芯片,每个芯片可以放k个电池。
每个芯片能量是k个电池的能量的最小值。
两个芯片的能量之差越小,这个机器就工作的越好。
现在有2nk个电池,已知它们的能量,我们要把它们放在n个机器上的芯片上,
使得所有机器的能量之差的最大值最小。

Input

第一行,两个正整数,n和k。
第二行,2nk个整数,表示每个电池的能量。

Output

一行一个整数,表示所有机器的能量之差的最大值最小是多少。

Sample Input

2 3
1 2 3 4 5 6 7 8 9 10 11 12

Sample Output

1

HINT

2nk <= 10^6, 1 <= pi <= 10^9。

题意

题解:

排序之后二分答案

check 是否前2ik个数里面至少有i个对满足题意的数

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1000001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int n,m,k;
int a[maxn];
int l,r,mid;
bool check(int x)
{
for(int p=,q=;q<n;++p)
{
if(p->q**k)
return false;
if(a[p+]-a[p]<=x)
++p,++q;
}
return true;
}
int main()
{
n=read(),k=read();
m=*n*k;
l=,r=;
for(int i=;i<=m;i++)
{
a[i]=read();
r=max(r,a[i]);
}
sort(a+,a+m+);
while(l<r)
{
mid=(l+r)>>;
if(check(mid))
r=mid;
else
l=mid+;
}
printf("%d\n",l);
}

bzoj 3969: [WF2013]Low Power 二分的更多相关文章

  1. BZOJ_3969_[WF2013]Low Power_二分答案

    BZOJ_3969_[WF2013]Low Power_二分答案 Description 有n个机器,每个机器有2个芯片,每个芯片可以放k个电池. 每个芯片能量是k个电池的能量的最小值. 两个芯片的能 ...

  2. bzoj3969 [WF2013]Low Power

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3969 [题解] 二分答案x,贪心选取,如果选取了i个,有j对,那么要满足i<=2*j* ...

  3. 【二分贪心】Bzoj3969 [WF2013] Low Power

    Description 有n个机器,每个机器有2个芯片,每个芯片可以放k个电池. 每个芯片能量是k个电池的能量的最小值. 两个芯片的能量之差越小,这个机器就工作的越好. 现在有2nk个电池,已知它们的 ...

  4. tensorfolw配置过程中遇到的一些问题及其解决过程的记录(配置SqueezeDet: Unified, Small, Low Power Fully Convolutional Neural Networks for Real-Time Object Detection for Autonomous Driving)

    今天看到一篇关于检测的论文<SqueezeDet: Unified, Small, Low Power Fully Convolutional Neural Networks for Real- ...

  5. Low Power Consumption Design --- MCU Attention

    20161008 note : I have a PCB board called 'A' where a piece of STM8L052C6 and a piece of CC1101 are ...

  6. Low Power之CPF/UPF

    1 CPF The Common Power Format is a standard promoted by the Low Power Coalition at Si2. CPF is also ...

  7. [CortexM0--stm32f0308]Low Power Mode

    问题描写叙述 stm32f0308正常是运行在Run mode下.这样的mode是在reset之后的默认模式.Low Power Mode.即低功耗模式.用于在IC空暇时能够考虑选择进入.使系统耗能减 ...

  8. PatentTips - Fast awake from low power mode

    BACKGROUND Electronic devices, such as electronic book readers ("eBook reader devices"), c ...

  9. Network management system scheduling for low power and lossy networks

    In one embodiment, a network management system (NMS) determines an intent to initialize a request-re ...

随机推荐

  1. 【Python学习】csv库

    csv(Comma-Separated Values, 逗号分割值)是存储表格数据的常用文件格式. 它每一行都用一个换行符分隔,列与列之间用逗号分隔. 本地文件 Python的csv库可以非常简单地修 ...

  2. i8042 键盘控制器-------详细介绍

    [转]http://shanzy.bokee.com/834368.html ps/2 键盘硬件概述 对于驱动来说,和键盘相关的最重要的硬件是两个芯片.一个是 intel 8042 芯片,位于主板上, ...

  3. 14个最常见的Kafka面试题及答案【转】

    原创 IT168企业级 2017-08-21 17:40 本文为您盘点了14个最常见的Kafka面试题,同时也是对Apache Kafka初学者必备知识点的一个整理与介绍. 1.请说明什么是Apach ...

  4. WebClient vs HttpClient vs HttpWebRequest

    转载:http://www.diogonunes.com/blog/webclient-vs-httpclient-vs-httpwebrequest/ Just when I was startin ...

  5. SpringBoot微服务

    在企业级软件的架构模型上,我们主要讨论下SOA与微服务架构. SOA的全称是Service-Oriented Architecture,可译为“面向服务的架构”,它是一个组件模型,将应用程序的不同功能 ...

  6. objective-c Quick Reference

  7. MIAC HW2

    MIAC的第二次作业,翻了一些fashion网站找了点灵感,重新设计了一下UI. 因为给的html里有nav之类的HTML5新特性,所以索性就不管IE的兼容了.chrome下的效果: FF下也差不多. ...

  8. chrome浏览器使用HTML5预览图片

    chrome浏览器对HTML5支持的较好,使用HTML5的File相关的api,可以实现前台页面在选定图片后,不上传即可预览.代码如下: 1.前台代码,使用<input type="f ...

  9. 使用STL sort对字符串按字典序排序

    使用string数组 #include<iostream> #include<string> #include<algorithm> using namespace ...

  10. loadrunner 三种post函数区别

    web_custom_request方法可以发送POST和GET类型的请求 web_submit_data只能发送POST类型的请求,提供了所有的数据,不管Cache存在不存在Web_submit_d ...