codeforces 985E Pencils and Boxes】的更多相关文章

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个数字并且…
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…
题目链接:http://codeforces.com/problemset/problem/551/C time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Professor GukiZ is concerned about making his way to school, because massive piles of bo…
Problem C. GukiZ hates Boxes Solution: 假设最后一个非零的位置为K,所有位置上的和为S 那么答案的范围在[K+1,K+S]. 二分这个答案ans,然后对每个人尽量在ans时间内搬最多的砖.可以得出至少需要多少个人才能搬完.这个可以在O(n)的时间内利用贪心得到 只要判断需要的人数是否小于等于实际的人数就好了 时间复杂度O(nlogS) #include <bits/stdc++.h> using namespace std; ; int a[N]; int…
C - Putting Boxes Together 思路: 求带权中位数 用树状数组维护修改 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define LL long long //…
821C - Okabe and Boxes 思路:模拟.因为只需要比较栈顶和当前要删除的值就可以了,所以如果栈顶和当前要删除的值不同时,栈就可以清空了(因为下一次的栈顶不可能出现在前面那些值中). 代码: #include<bits/stdc++.h> using namespace std; #define ll long long vector<int>st; int main() { ios::sync_with_stdio(false); cin.tie(); ,ans=…
260C - Balls and Boxes 思路:模拟.在x前面找到最小值,如果没有,从0跳到n,继续找到最小值,边找最小值路过的点边减1.然后所有值都减去最小值,最小值那个点加上减去的值. 找到x前面离x最近的最小值的原因:如果如果在x到最小值之间还有最小值,那么这个最小值最后会变成-1. 简单代码: #include<bits/stdc++.h> using namespace std; #define ll long long ; const ll INF=0x7f7f7f7f; ll…
C. Boxes Packing time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai. Mishka can put a box i into a…
Putting Boxes Together 题意: 现在有n个物品,第i个物品他的位置在a[i],他的重量为w[i].每一个物品移动一步的代价为他的w[i].目前有2种操作: 1. x y 将第x的物品的重量改为y 2.l r 将编号在 [ l, r ]之间的所有物品移动到一起,求最小的花费是多少. 如果移动一个物品移动一步的代价是1的话,对于[1,n]来说,那么中间位置就是 a[(1+n)/2]. 也就是最中间的那个物品的位置. 现在移动一步他的代价是w[i],那么中间位置就是 sum(1,…
题目链接 题意:  一共同拥有n个空地(是一个数轴,从x=1 到 x=n),每一个空地上有a[i]块石头  有m个学生  目标是删除全部石头  一開始全部学生都站在 x=0的地方  每秒钟每一个学生都能够在原地删除一块石头,或者向 → 移动一格距离  问:删除全部石头的最短时间 案例解析:  3 2  1 0 2  第一个学生第一秒向→走.第二秒删a[1]的一块石头  第二个学生一直走到头.删掉a[3] ,所以第二个学生花费是 1+1+1+2 = 5 两个学生能够同一时候运动. 思路: 二分答案…
题目大意:给你编号为1-n的箱子,放的顺序不定,有n条add指令将箱子放入栈中,有n条remove指令将箱子移除栈,移出去的顺序是从1-n的,至少需要对箱子重新排序几次. 解题思路:可以通过把栈清空表示已经排过序了,如果下一次remove时栈为空,说明已经排序过且没有新的箱子放入,因为题目确保在需要删除之前添加每个箱子,所以肯定栈顶的箱子是我们所需要的.如果栈不为空则判断栈顶箱子序号是否是我们需要的,不是则重新排序,用清空栈来表示. 这里用数字模拟了栈. #include<iostream>…
思路: 先对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…
N堆石头排成一列,每堆有Ai个石子.有M个学生来将所有石头搬走.一开始所有学生都在原点, 每秒钟每个学生都可以在原地搬走一块石头,或者向前移动一格距离,求搬走所有石头的最短时间. *解法:二分答案x(时间),即每位学生均有x秒的时间,模拟搬石头过程看能否搬完即可(一个人一个人计算,每个人均尽力完成任务即可). 记得开longlong #include <iostream> #include <cstdio> #include <cstdlib> #include <…
题意:n个数 把他们放进一些盒子里 每个盒子最少放k个数 且最小和最大的差不能大于d 题解:显然排个序 对于当前点 存一下前面有哪些节点可以当作结尾 那么就可以枚举这些点的下一个点作为起点能否和当前点组成合法区间 找到的第一个大小不超过d的点显然是最优的 这样会使区间尽可能大于k 如果找到了这个点就把他放入队列 那么就是单调队列了... #include <bits/stdc++.h> using namespace std; ]; ]; int main() { int n, k, d; c…
题意略. 思路: 这个题目开始想的有点暴力,后来发现有搜索的性质,因此转而用动态规划.首先,我们要把这些数排个序. 定义状态:dp[i]为排序后i~n能否成功打包,1表示可以,0表示不能打包. 状态转移方程:dp[i] = max{dp[j]} (i + k <= j <= upper)upper为在有序数组中,第一个比当前值store[i] + d大的数的下标. 为了防止它卡数据,这里可以用单调队列优化一下,由于确定upper要使用二分搜索,所以总的复杂度是O(nlogn). 详见代码: #…
\(CodeForces 706E ~Working routine\) 给出一个矩阵,每次操作交换两个子矩阵,求最后状态. 使用链表存储,每次交换后,影响到的之后矩阵边缘的指针,暴力修改. \(~~~~\) \(CodeForces 985E ~Pencils and Boxes\) 每个铅笔盒至少放\(k\)个铅笔,每个盒子中的铅笔价值的绝对值之差不能超过\(d\).求是否有方案. 放在一个盒子里的铅笔价值是连续的一段,这样一定不劣.使用线段树维护合法的权值起始位置. \(~~~~\) \(…
题目链接:https://codeforces.com/contest/985 ’A.Chess Placing 题意:给了一维的一个棋盘,共有n(n必为偶数)个格子.棋盘上是黑白相间的.现在棋盘上有n/2个棋子,让你全部移动到黑色格子或者白色格子,要求步数最少,并输出步数. 题解:由于黑色或者白色都是固定位置,我们对棋子位置排个序,然后全部移动到任意一个颜色,取两个最小步数的最小值就好了. #include<bits/stdc++.h> #define clr(x) memset(x,0,s…
目录 Codeforces 990 A.Commentary Boxes B.Micro-World C.Bracket Sequences Concatenation Problem D.Graph And Its Complement(思路 构造) E.Post Lamps(贪心) F.Flow Control(思路) G.GCD Counting(思路) Codeforces 990 比赛链接 真特么菜啊 后一个多小时无所事事.. 要多做CF的题啊,也许没有那么难但是就是容易想不到,代码也…
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…
CF习题集三 一.CF8C Looking for Order 题目描述 \(Lena\)喜欢秩序井然的生活.一天,她要去上大学了.突然,她发现整个房间乱糟糟的--她的手提包里的物品都散落在了地上.她想把所有的物品都放回她的手提包.但是,这里有一点问题:她一次最多只能拿两个物品,她也不能移动她的手提包.并且,因为她爱整洁的习惯,如果她拿起了一个物品,她也不能将它放在其他地方,除非放回她的手提包. \(Lena\)把她的房间划分为了一个平面直角坐标系.现在Lena给你她的手提包和每个散落的物品的坐…
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…
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…
B. Candy Boxes 题目链接:http://codeforces.com/problemset/problem/488/B time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There is an old tradition of keeping 4 boxes of candies in the house in Cy…
http://codeforces.com/contest/1066/problem/D Maksim has nn objects and mm boxes, each box has size exactly kk. Objects are numbered from 11 to nn in order from left to right, the size of the ii-th object is aiai. Maksim wants to pack his objects into…
D. Boxes And Balls time limit per test2 seconds memory limit per test256 megabytes 题目链接:http://codeforces.com/contest/884/problem/D Description Ivan has n different boxes. The first of them contains some balls of n different colors. Ivan wants to pla…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way. In total there are n piles of…
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…