[SCOI2009]生日礼物(尺取法)
Time Limit: 10 Sec Memory Limit: 162 MB
Submit: 2201 Solved: 1186
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 5
2 1 7
3 1 3 8
Sample Output
HINT
有多种方案可选,其中比较短的是1~5和5~8。后者长度为3最短。
【数据规模】
对于50%的数据, N≤10000;
对于80%的数据, N≤800000;
对于100%的数据,1≤N≤1000000,1≤K≤60,0≤彩珠位置<2^31。
坑点在于,我往二分里使劲钻
尺取法:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; #define MAXN 1000005
#define INF 2147483647 struct Node
{
int pos;
int k;
bool operator < (const Node & b)const {return pos<b.pos;}
}zhu[MAXN]; int n,k; int kind[]; int main()
{
while (scanf("%d%d",&n,&k)!=EOF)
{
int num=;
for (int i=;i<k;i++)
{
int x;
scanf("%d",&x);
while (x--)
{
int v;
scanf("%d",&v);
zhu[num++]=(Node){v,i};
}
}
sort(zhu,zhu+num); memset(kind,,sizeof(kind));
int ans=INF;
int l=,r=;
int k_n=;
while()
{
while (r<n&&k_n<k)
if (!kind[zhu[r++].k]++) k_n++;
while (k_n==k&&l<r)
{
if (zhu[r-].pos-zhu[l].pos<ans) ans = zhu[r-].pos-zhu[l].pos;
if (!--kind[zhu[l++].k]) k_n--;
}
if (r>=n) break;
}
printf("%d\n",ans);
}
return ;
}
[SCOI2009]生日礼物(尺取法)的更多相关文章
- bzoj1293[SCOI2009]生日礼物 尺取法
1293: [SCOI2009]生日礼物 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2838 Solved: 1547[Submit][Stat ...
- BZOJ 1293 生日礼物(尺取法)
把坐标离散化之后就是很普通的尺取法啦. # include <cstdio> # include <cstring> # include <cstdlib> # i ...
- P2564 [SCOI2009]生日礼物(尺取法)
P2564 [SCOI2009]生日礼物 三个字.尺取法......... 坐标按x轴排序. 蓝后尺取一下.......... #include<iostream> #include< ...
- NC20565 [SCOI2009]生日礼物
NC20565 [SCOI2009]生日礼物 题目 题目描述 小西有一条很长的彩带,彩带上挂着各式各样的彩珠.已知彩珠有 \(N\) 个,分为 \(K\) 种.简单的说,可以将彩带考虑为 \(x\) ...
- 5806 NanoApe Loves Sequence Ⅱ(尺取法)
传送门 NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K ...
- POJ3061 尺取法
题目大意:从给定序列里找出区间和大于等于S的最小区间的长度. 前阵子在zzuli OJ上见过类似的题,还好当时补题了.尺取法O(n) 的复杂度过掉的.尺取法:从头遍历,如果不满足条件,则将尺子尾 部增 ...
- POJ 2739 Sum of Consecutive Prime Numbers(尺取法)
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Description S ...
- CF 701C They Are Everywhere(尺取法)
题目链接: 传送门 They Are Everywhere time limit per test:2 second memory limit per test:256 megabytes D ...
- nyoj133_子序列_离散化_尺取法
子序列 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描述 给定一个序列,请你求出该序列的一个连续的子序列,使原串中出现的所有元素皆在该子序列中出现过至少1次. 如2 8 ...
随机推荐
- 《Linux性能及调优指南》----1.1 Linux进程管理
翻译:飞哥 ( http://hi.baidu.com/imlidapeng ) 版权所有,尊重他人劳动成果,转载时请注明作者和原始出处及本声明. 原文名称:<Linux Performance ...
- Timeline简单配置
Timeline是一个Jquery时间轴插件.效果如图 获取地址:https://github.com/ka215/jquery.timeline 配置 (1)html表头加入 <link re ...
- 2017.8.5 VMware的介绍与安装
1 VMware简介 官网地址:http://www.vmware.com VMware的功能: 是一个虚拟PC的软件,可以在现有的操作系统上虚拟出一个新的硬件环境,相当于模拟出一台新的PC,以此来实 ...
- perl学习笔记三
子程序 定义子程序(可以在程序的任意位置) 关键字sub.子程序名(不包含与号)以及用花括号封闭起来的代码快. 如:sub marine{ $n+=1; print "hello,sailo ...
- Django——静态文件(如bootstrap)的配置
静态文件如CSS, javascript(如bootstrap), 图片等文件在django中的配置官方文档写的比较模糊,自己通过实验验证后并整理如下,以防遗忘,目前只整理了关于本地开发中的设置方式, ...
- hdu4930 Fighting the Landlords(模拟 多校6)
题目链接:pid=4930">http://acm.hdu.edu.cn/showproblem.php? pid=4930 Fighting the Landlords Time L ...
- cisco 为每个单独的人员设置不同的用户名和密码
cisco 为每个单独的人员设置不同的用户名和密码 2010-12-15 17:00:16 分类: 系统运维 Router1#configure terminalEnter configuration ...
- Spark on Intellij IDEA
添加scala插件 如果网络有问题,可以手动下载插件安装包(http://plugins.jetbrains.com/plugin/?id=1347),在上面选择“Install plugin fro ...
- 解决java.math.BigDecimal divide方法运算结果为无限小数问题
http://samueli.iteye.com/blog/224755 BigDecimal除法运算报错,错误如下:Non-terminating decimal expansion; no exa ...
- windows快捷启动命令
gpedit.msc-----组策略 sndrec32-----录音机 nslookup----- ip地址侦测器 explorer------ 打开资源管理器 logoff-------注销命令 t ...