CF1066D Boxes Packing

时间:2022-01-05 02:37:22

传送门

这题为什么要用二分呢?/huaji

首先可以\(O(n)\)预处理出从某个物品\(i\)开始放,只放一个盒子,能放的最后物品的位置\(j\),只要用两个指针维护左右端点,每次移动一下左端点同时尽量把右端点右移救星了

然后我们要放的所有物品是原来的一个后缀,所以要从后往前放,但是直接贪心放是错的.考虑构建一棵树,根据前面对每个\(i\)预处理出的\(j\),连\((j+1,i)\)的单向边,然后从\(n+1\)开始dfs,记\(n+1\)的深度为0,那么我们不能访问深度大于\(m\)的点.记能访问到最小的点为\(y\),答案为\(n-y+1\)

#include<bits/stdc++.h>
#define LL long long
#define il inline
#define re register
#define db double
#define eps (1e-5) using namespace std;
const int N=200000+10;
il LL rd()
{
LL x=0,w=1;char ch=0;
while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*w;
}
int to[N],nt[N],hd[N],tot=1;
il void add(int x,int y){++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot;}
int n,m,k,a[N],ans,tt=-1;
il void dfs(int x)
{
++tt;
ans=max(ans,n-x+1);
if(tt<m) for(int i=hd[x];i;i=nt[i]) dfs(to[i]);
--tt;
} int main()
{
n=rd(),m=rd(),k=rd();
for(int i=1;i<=n;i++) a[i]=rd();
for(int i=1,su=a[1],j=1;i<=n;i++)
{
while(j<n&&su+a[j+1]<=k) su+=a[++j];
add(j+1,i),su-=a[i];
}
dfs(n+1);
printf("%d\n",ans);
return 0;
}

CF1066D Boxes Packing的更多相关文章

  1. CF1066D Boxes Packing(二分答案)

    题意描述: 你有$n$个物品,每个物品大小为$a_i$,$m$个盒子,每个盒子的容积为$k$.$Maksim$先生想把物品装入盒子中.对于每个物品,如果能被放入当前的盒子中,则放入当前盒子,否则换一个 ...

  2. Educational Codeforces Round 34 &lpar;Rated for Div&period; 2&rpar; C&period; Boxes Packing

    C. Boxes Packing time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  3. Educational Codeforces Round 34 C&period; Boxes Packing【模拟&sol;STL-map&sol;俄罗斯套娃】

    C. Boxes Packing time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. Boxes Packing

    Boxes Packing Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side le ...

  5. CodeForces Round &num;515 Div&period;3 D&period; Boxes Packing

    http://codeforces.com/contest/1066/problem/D Maksim has nn objects and mm boxes, each box has size e ...

  6. D&period; Boxes Packing

    链接 [http://codeforces.com/contest/1066/problem/D] 题意 题目大意 n个物品m个篮子每个篮子容量为k 每个物品重量为a[i] 问能装多少物品 这个人是强 ...

  7. 903C&period; Boxes Packing&num;俄罗斯套娃问题&lpar;map使用&rpar;

    题目出处:http://codeforces.com/problemset/problem/903/C 题目大意:求这组数据中数据出现的最大重复次数 #include<iostream> ...

  8. Codeforces Round &num;515 &lpar;Div&period; 3&rpar;

    Codeforces Round #515 (Div. 3) #include<bits/stdc++.h> #include<iostream> #include<cs ...

  9. Codeforces Round &num;515 &lpar;Div&period; 3&rpar; 解题报告(A~E)

    题目链接:http://codeforces.com/contest/1066 1066 A. Vova and Train 题意:Vova想坐火车从1点到L点,在路上v的整数倍的点上分布着灯笼,而在 ...

随机推荐

  1. Javascript模块化编程(一):模块的写法&lpar;转&rpar;

    随着网站逐渐变成"互联网应用程序",嵌入网页的Javascript代码越来越庞大,越来越复杂. 网页越来越像桌面程序,需要一个团队分工协作.进度管理.单元测试等等......开发者 ...

  2. jQuery原型方法each使用和源码分析

    jQuery.each方法是jQuery的核心工具方法之一,通用例遍方法,可用于例遍对象和数组.不同于例遍 jQuery 对象的 $().each() 方法,此方法可用于例遍任何对象.通常需要两个参数 ...

  3. SNF开发平台WinForm之十三-单独从服务器上获取PDF文件进行显示-SNF快速开发平台3&period;3-Spring&period;Net&period;Framework

    1运行效果: 2开发实现: 如果需要单独显示PDF文件时用下面代码去实现,指定url地址. 地址: . 获取附件管理的实体对象: List<KeyValuePair<string, obj ...

  4. c&plus;&plus; float 带 e 的指数

    带e是指10的 e后面次方 #include <iostream> int main() { float f; f = 9.87654321f; std::cout << f ...

  5. jQuery相关知识

    1.jQuery中$符号有何作用? $作为jQuery的别名,如$(document).ready() 即是 jQuery(document).ready() 2.jQuery选择器有哪几种? 基本选 ...

  6. &period;NET及&period;NET Core系统架构

    三层及多层架构 Multitier Architecture ASP.NET N-Tier Architecture Schema Visual Studio N-Tier Example 来源:ht ...

  7. const的用法,特别是用在函数前面与后面的区别!

    const的用法,特别是用在函数后面 在普通的非 const成员函数中,this的类型是一个指向类类型的 const指针.可以改变this所指向的值,但不能改变 this所保存的地址. 在 const ...

  8. php exec返回状态为1

    之前在用到php exec 时 总是保存,返回状态1,那这时怎么排查呢 exec('ls 2>&1', $output, $return_val); print_r($output); ...

  9. How to export data from Thermo-Calc 如何从Thermo-calc导出文本数据

    记录20180510 问题:如何从thermo-calc导出文本数据供origin绘图? 解决: In Thermo-Calc graphical mode, you can just add a ' ...

  10. python导包显示No module named XXX问题

    最近用sublime text写python脚本,在导包是一直显示No module named XXX. 问题描述: 首先文件夹的目录结构如下: count.py文件,代码如下: #coding=u ...