BZOJ 1293 生日礼物(尺取法)
把坐标离散化之后就是很普通的尺取法啦。
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi 3.1415926535
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int res=, flag=;
char ch;
if((ch=getchar())=='-') flag=;
else if(ch>=''&&ch<='') res=ch-'';
while((ch=getchar())>=''&&ch<='') res=res*+(ch-'');
return flag?-res:res;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... struct Node{int c; LL pos;}node[N];
int vis[], num; bool comp(Node a, Node b){return a.pos<b.pos;}
int main ()
{
LL ans=(LL)<<;
int n, k, t;
n=Scan(); k=Scan();
FOR(i,,k) {
t=Scan();
while (t--) node[++num].pos=Scan(), node[num].c=i;
}
sort(node+,node+n+,comp);
num=;
int l=, r=;
while () {
while (num<k) {
++r;
if (r>n) break;
if (vis[node[r].c]==) ++num;
++vis[node[r].c];
}
if (r>n) break;
ans=min(ans,node[r].pos-node[l].pos);
--vis[node[l].c];
if (vis[node[l].c]==) --num;
++l;
}
printf("%lld\n",ans);
return ;
}
BZOJ 1293 生日礼物(尺取法)的更多相关文章
- bzoj1293[SCOI2009]生日礼物 尺取法
1293: [SCOI2009]生日礼物 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2838 Solved: 1547[Submit][Stat ...
- [BZOJ 1293] 生日礼物
Link: BZOJ 1293 传送门 Solution: 这题直接上尺取法就行了吧 先将每种颜色第一个放入优先队列,用$mx$维护当前的末尾位置 每次取出第一个颜色,更新答案.将其下一个放入队列中去 ...
- [SCOI2009]生日礼物(尺取法)
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2201 Solved: 1186[Submit][Status][Discuss] Descript ...
- P2564 [SCOI2009]生日礼物(尺取法)
P2564 [SCOI2009]生日礼物 三个字.尺取法......... 坐标按x轴排序. 蓝后尺取一下.......... #include<iostream> #include< ...
- 【BZOJ 1293】[SCOI2009]生日礼物
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然的滑动窗口题. (尺取法 如果l..i这一段已经有k种珍珠了. 那么就尝试把l++; (即把l这个影响尝试去掉一下 如果不足k种 ...
- 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 ...
随机推荐
- 数据库 MySQL part3
外键约束 如果表A的主关键字是表B中的字段,则该字段称为表B的外键,表A称为主表,表B称为从表. 外键是用来实现参照完整性的,不同的外键约束方式将可以使两张表紧密的结合起来,特别是修改或者删除的级联操 ...
- 优步UBER司机全国各地奖励政策汇总 (3月21日-3月27日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- mysql c 获取error_code
#include <stdio.h> #include <mysql.h> int main(int argc, char **argv) { MYSQL *con = mys ...
- 怎样通过Qt编写C/C++代码查询当前Linux的版本号?
遇到一个问题:如题. 我的开发环境是:嵌入式ARM + Linux系统 + Qt 4.5 + C/C++ 现在需要查询 当前Linux系统的版本号. 问题: 1)Qt 4.5 提供怎样的API来获取? ...
- MySQL☞abs函数
abs( )函数:求出绝对值 格式: select abs(数值) from 表名 如下图:
- Linux命令应用大词典-第24章 任务计划
24.1 contab:针对个人用户维护crontab文件
- Docker Remote API v1.24
1. Brief introduction The Remote API has replaced rcli. The daemon listens on unix:///var/run/docker ...
- 【第五章】MySQL数据库的安全机制
MySQL权限表MySQL用户管理MySQL权限管理SSL加密连接
- Django创建App报错
在django下创建APP项目时遇到的坑 python manage.py startapp app01 报错内容如下: 解决:找到报错中的文件夹151行删除items(),)中的逗号即可 在命令行下 ...
- 关于14道魔鬼js考题的整理
1.(function(){ return typeof arguments })(); 这里返回时是argument类型,它是个类数组,也就对象,所以是object,准确谁是[object argu ...