ZOJ 3790 Consecutive Blocks】的更多相关文章

problemCode=3790">Consecutive Blocks 先离散一下,然后模拟,把一种颜色i所在的位置都放入G[i]中.然后枚举一下终点位置,滑动窗体使得起点和终点间花费不超过K,求中间过程的最大值就可以. #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #includ…
There are N (1 ≤ N ≤ 105) colored blocks (numbered 1 to N from left to right) which are lined up in a row. And the i-th block's color is Ci (1 ≤ Ci ≤ 109). Now you can remove at most K (0 ≤ K ≤ N) blocks, then rearrange the blocks by their index from…
大致题意就是给你一个数列,让你最多移除K个数字,使得连续的相同数字的长度最大,并求出最大长度. 我们将此序列按颜色排序,颜色相同的话按位置排序,那么排完序之后颜色相同的blocks就在一起,只是他们的位置不同而已.因此颜色相同的两个相邻blocks的位置之差-1就是要移除的个数. 当发现所剩的移除个数不足时,那么就删除左边已经连续放在一起的block,同时把那部分所消耗的移除个数加回来;如果所剩移除个数充足那么长度就+1.如果发现相邻的两个block颜色不同那么就要重新开始,所剩移除个数就要重新…
题目链接 虽然是一道暴力的题目,但是思路不好想.刚开始还超时,剪枝了以后1200ms,不知道为什么还是这么慢. 题意:给你n个点,每个点有一种颜色ci,给你至多k次删除操作,每次删除一个点,问最多k次操作后连在一起的点颜色相同的最大长度. 思路:由于ci 最大为10^9, 所以需要首先离散化.然后暴力. #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #inc…
当时不知道怎么下手,后来一看原来就是排个序然后乱搞就行了. 解法不想写了,可见:http://blog.csdn.net/u013368721/article/details/28071241 其实就是滑动窗口的思想. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <algor…
C - Crusaders Quest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3983 Description Crusaders Quest is an interesting mobile game. A mysterious witch has brought great darkness to the game world,…
比赛链接:点击打开链接 上来先搞了f.c,,然后发现状态不正确,一下午都是脑洞大开,, 无脑wa,无脑ce...一样的错犯2次.. 硬着头皮搞了几发,最后20分钟码了一下G,不知道为什么把1直接当成不能加油的站就会wa..太弱.. 唔···太懒第二天才发题解.. B:Gears 并查集 题解:点击打开链接 C:Consecutive Blocks 离散化一下然后模拟 题解:点击打开链接 D:An Easy Game 设dp[i][j]为前i个位置已经匹配了j个位置的方法数. #include <…
A.Another Recurrence Sequence problemId=5287">B.Gears 题目大意:有n个齿轮,一開始各自为一组.之后进行m次操作,包含下面4种类型: 1.合并两组齿轮.合并的两个应该反向旋转 2.把某个齿轮从所在组删除,自为一组.但不影响同组其他齿轮的状态与关系 3.询问两个齿轮是同向.反向或无关系(即不在同一组) 4.询问某个齿轮所在组的齿轮总数 分析:典型的并查集操作,可是注意两点: 1.因为操作3要询问两个齿轮的相对状态.因此对并查集中每一个元素应…
Restoring IPv6 DescriptionAn IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here i…
HFileBlock官方源码注释:   Reading HFile version 1 and 2 blocks, and writing version 2 blocks. In version 1 all blocks are always compressed or uncompressed, as specified by the HFile's compression algorithm, with a type-specific magic record stored in the…