CF985E Pencils and Boxes】的更多相关文章

思路: 先对a数组排序,然后使用动态规划.dp[i]表示前i个能否正确划分.则如果存在dp[j] == 1, i - j + 1 >= k并且a[i] - a[j] < d,那么dp[i] = 1,否则dp[i] = 0.可以使用树状数组对区间查询操作进行优化.复杂度O(n * log(n)).实现: #include <bits/stdc++.h> using namespace std; ; int n, k, d, a[MAXN], bit[MAXN]; inline int…
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w…
E - Pencils and Boxes 思路: dp 先排个序,放进一个袋子里的显然是一段区间 定义状态:pos[i]表示小于等于i的可以作为(放进一个袋子里的)一段区间起点的离i最近的位置 显然,初始状态:pos[i] = 1,1 <= i <= k 状态转移: pos[i+1] = i+1 ,如果 a[i] - a[pos[i-k+1]] <= d , 因为在这种情况下pos[i-k+1] 到 i 可以放进一个袋子里,那么i+1就可以作为新的起点了 pos[i+1] = pos[…
E. Pencils and Boxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where ev…
E. Pencils and Boxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where ev…
题意: 把一个数组分成若干组,保证每组的size >= k并且一组中任意两个数字的差的绝对值 <= d,问存不存在这样的分法. 思路: 线性dp. 用dp[i]表示前i个数是否有分法. 设j为满足a[i] - a[j] <= d的最小的a[j]的下标,那么dp[i]就可以从dp[j-1] ~ dp[i-k]转移,j可以二分得到. 首先一定得满足i - k,因为至少有k个数字: 假设前j-1个数字有分法,那么当j - 1 <= i - k的时候,说明第j到第i个数字至少有k个数字并且…
题意:n个数 把他们放进一些盒子里 每个盒子最少放k个数 且最小和最大的差不能大于d 题解:显然排个序 对于当前点 存一下前面有哪些节点可以当作结尾 那么就可以枚举这些点的下一个点作为起点能否和当前点组成合法区间 找到的第一个大小不超过d的点显然是最优的 这样会使区间尽可能大于k 如果找到了这个点就把他放入队列 那么就是单调队列了... #include <bits/stdc++.h> using namespace std; ]; ]; int main() { int n, k, d; c…
CF习题集三 一.CF8C Looking for Order 题目描述 \(Lena\)喜欢秩序井然的生活.一天,她要去上大学了.突然,她发现整个房间乱糟糟的--她的手提包里的物品都散落在了地上.她想把所有的物品都放回她的手提包.但是,这里有一点问题:她一次最多只能拿两个物品,她也不能移动她的手提包.并且,因为她爱整洁的习惯,如果她拿起了一个物品,她也不能将它放在其他地方,除非放回她的手提包. \(Lena\)把她的房间划分为了一个平面直角坐标系.现在Lena给你她的手提包和每个散落的物品的坐…
题目链接:https://codeforces.com/contest/985 ’A.Chess Placing 题意:给了一维的一个棋盘,共有n(n必为偶数)个格子.棋盘上是黑白相间的.现在棋盘上有n/2个棋子,让你全部移动到黑色格子或者白色格子,要求步数最少,并输出步数. 题解:由于黑色或者白色都是固定位置,我们对棋子位置排个序,然后全部移动到任意一个颜色,取两个最小步数的最小值就好了. #include<bits/stdc++.h> #define clr(x) memset(x,0,s…
A B /* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a,b) make_pair(a,b) #define pb push_back ][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }}; using namespace std; typedef long long ll; inline v…
\(CodeForces 706E ~Working routine\) 给出一个矩阵,每次操作交换两个子矩阵,求最后状态. 使用链表存储,每次交换后,影响到的之后矩阵边缘的指针,暴力修改. \(~~~~\) \(CodeForces 985E ~Pencils and Boxes\) 每个铅笔盒至少放\(k\)个铅笔,每个盒子中的铅笔价值的绝对值之差不能超过\(d\).求是否有方案. 放在一个盒子里的铅笔价值是连续的一段,这样一定不劣.使用线段树维护合法的权值起始位置. \(~~~~\) \(…
安装Fedora 24在试用虚拟机时发现无法ping通外网. 我傻傻地以为是软件问题. 问题描述: 尝试ping程序来测试网络连通性: (我之前也是ping百度,后来在为了少打字百度了一些比较短的域名. 比如: "to." , "g.cn" , "j.mp" 等等.) (http://wenku.baidu.com/link?url=oSb0I5xzI1UBhU3aKTXoWll7PYaIm0zNiORJbx_h6PlT-bURWFOCXkW9W…
 省赛B题....手写链表..其实很简单的.... 比赛时太急了,各种手残....没搞出来....要不然就有金了...注:对相邻的元素需要特判..... Problem B Boxes in a Line You have n boxes in a line on the table numbered 1~n from left to right. Your task is to simulate 4 kinds of commands: 1 X Y: move box X to the lef…
C. Inna and Candy Boxes   Inna loves sweets very much. She has n closed present boxes lines up in a row in front of her. Each of these boxes contains either a candy (Dima's work) or nothing (Sereja's work). Let's assume that the boxes are numbered fr…
boxes [英][bɒksɪz][美][bɑ:ksɪz] n.盒( box的名词复数 ); 一盒; 电视; 小亭; v.把…装入盒[箱,匣]中( box的第三人称单数 ); 拳击;   以上结果来自金山词霸…
B. Candy Boxes Problem's Link:   http://codeforces.com/contest/488/problem/B Mean: T题目意思很简单,不解释. analyse: 这道题还是很有意思的,需要考虑到各种情况才能AC. 解这个题目之前,首先要推出两条式子 x4=3x1 4x1=x2+x3 然后就是分类讨论,枚举各种情况就可. Time complexity: O(1) Source code:  // Memory Time // 1347K 0MS…
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=39  Stacking Boxes  Background Some concepts in Mathematics and Computer Science are simple in one or two dimensions but become…
9.10 You have a stack of n boxes, with widths w., heights hir and depths drThe boxes cannot be rotated and can only be stacked on top of one another if each box in the stack is strictly larger than the box above it in width, height, and depth. Implem…
#include <bits/stdc++.h> using namespace std; ]; ][]; ][][]; ][][][]; ][][][][]; ][][][][][]; ][][][][][][]; struct node{ ]; int step; }; map<int,int> Hash; ],b[],c[]; bool check(int a[],int num,int step){ //检查有没有走过 ){ ]]>=) return true; ]]…
题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=126 /* 找规律,智商不够,看了题解 详细解释:http://blog.csdn.net/ahfywff/article/details/7432524 */ #include <cstdio> #include <cmath> #include <cstring> #include <string> #include <iostrea…
http://poj.org/problem?id=1475 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=249 Pushing Boxes Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 4662   Accepted: 1608   Special Judge Description Imagine you are standing insid…
Boxes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVALive 6500 #include<stdio.h> #include<string.h> int main() { int T,m,n; int i,j,s; ][]; scanf("%d",&T); while(T--) { s=; sc…
Suppose you want to give an option to user to select only 5 check boxes from given any number of check boxes in an Oracle Form and if user selects more than 5 than give a message that you can not select more than 5. For this follow these steps:Create…
 Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Description 题目描述 Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. In the experiment, he thr…
C. Balls and Boxes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from…
原文链接:http://www.zhangxinxu.com/wordpress/2010/01/css-float%E6%B5%AE%E5%8A%A8%E7%9A%84%E6%B7%B1%E5%85%A5%E7%A0%94%E7%A9%B6%E3%80%81%E8%AF%A6%E8%A7%A3%E5%8F%8A%E6%8B%93%E5%B1%95%E4%B8%80/ <p>这是一行普通的文字,这里有个 <em>em</em> 标签.</p> 这段HTML代…
UVa 103 题目大意:给定n个箱子,每个箱子有m个维度, 一个箱子可以嵌套在另一个箱子中当且仅当该箱子的所有的维度大小全部小于另一个箱子的相应维度, (注意箱子可以旋转,即箱子维度可以互换),求最多能套几个箱子. 第一行输入为n,m,之后是n行m维的箱子 解题思路:嵌套关系是二元关系,因此这题即在DAG上做动态规划, 只不过将二维的判断改成了n维,其他不变. 详细看考:DAG上的动态规划之嵌套矩形  (ps:这题可以理解成嵌套m边形) /* UVa 103 Stacking Boxes --…
function script_faster_rcnn_demo() close all; clc; clear mex; clear is_valid_handle; % to clear init_key run(fullfile(fileparts(fileparts(mfilename('fullpath'))), 'startup')); %% -------------------- CONFIG -------------------- opts.caffe_version = '…
C. GukiZ hates Boxes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/problem/C Description Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way. In total there…
Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. In the experiment, he throws n balls into m boxes in such a manner t…