Juice Extractor |
Jerry loses himself in the interesting game: Fruit Ninja. Fruit Ninja is a game of iPhone and iPad in which the players cut the fruits coming from the bottom of the screen and gain the bonus from cutting more than two fruits with a single slice. Once a fruit is cut, it breaks into small pieces and cannot be cut any more.
After months of training, he becomes pro of this game. Actually, he can cut all the fruits on the screen at any time. Jerry also has a bad habit that he has no willing to leave some fruits for the future cutting. In the other words, after Jerry cuts the fruits, all the fruits on the screen breaks and no one left. That is why all his friends call him `Juice Extractor'.
Now he only consider about the bonus, when he cuts more than two fruits, he can gain some bonus scores as same as the number of fruits he slice at that time. For example, if Jerry cuts 4 fruits with a single slice, he can get 4 scores from this slice.
After Jerry gets the fruit schedule, he knows the appearing time and the disappearing time for every single fruit. He can only cut a fruit into pieces between its appearing time and disappearing time inclusive. He wants to know the maximum possible bonus scores he can receive.
Input
There are several test cases; the first line of the input contains a single integer T, denoting the number of the test cases. (T200)
For each test case, the first line contains an integer N, denoting the total number of fruits. ( 1N
1000)
The next N lines, each line describe a fruit. For each line, there are two integers Xi and Yi, where Xi is the appearing time of the fruit and Yi is the disappearing time of this fruit. ( 0Xi
Yi
1000000000)
Output
For each test case, output a single integer denoting the maximum scores that Jerry could possibly gain. See the sample for further details.
Sample Input
1 10 1 10 2 11 3 12 4 13 13 14 14 15 13 19 20 22 21 23 22 24
Sample Output
Case #1: 10
题意:
给出 T组样例,每个样例都有一个 N,代表有 N 个水果。后给出每个水果出现的开始时间和结束时间。在任意一个时间点切水果的话,能够切到所有在这个时间出现的所有水果,当切的水果数 > 2 的时候,才会有得分,得分为所切的水果数,小于等于2得分为0。问如何切,使其分数达到最大。
思路:
DP + 树状数组。dp [ i ] = max { dp [ t ] + point (t + 1, i) },dp [ i ] 代表在此刻切水果所达到的最大值,在 i 时刻这刀切的话,在 i 之前出现且尚未消失的水果都会被切除。
同理 dp [ t ] 代表的也是 t 时刻前的水果都会消失,那么在 (t + 1 , i )这段时间内出现且尚未消失的水果将会在 i 这刀切下去的时候消失,所以最后的得分应该是 dp [ t ] + point ( t + 1, i ) 。
预处理 dp 应该是只在该时刻切水果所得到的分数,用起点 + 1,(终点 + 1)-1,后 dp [ i ] += dp [ i - 1 ] 可以预处理出来。同时树状数组维护某段时间内的水果数。
AC:
#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <algorithm> using namespace std; const int MAX = 1005; typedef struct { int l, r; } node; node no[MAX]; int ans; int yy[MAX * 2]; int dp[MAX * 2]; int m; int bit[MAX * 5]; int sum (int x) { int s = 0; while (x > 0) { s += bit[x]; x -= x & -x; } return s; } void add (int i, int x) { while (i <= m) { bit[i] += x; i += i & -i; } } int main() { int t; scanf("%d", &t); for (int tt = 1; tt <= t; ++tt) { int n; scanf("%d", &n); ans = 0; for (int i = 1; i <= n; ++i) { scanf("%d%d", &no[i].l, &no[i].r); yy[ans++] = no[i].l; yy[ans++] = no[i].r; } sort(yy, yy + ans); ans = unique(yy, yy + ans) - yy; m = ans * 5; memset(bit, 0, sizeof(bit)); for (int i = 1; i <= n; ++i) { int s = lower_bound(yy, yy + ans, no[i].l) - yy; add(s + 1, 1); } memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; ++i) { int s = lower_bound(yy, yy + ans, no[i].l) - yy; int e = lower_bound(yy, yy + ans, no[i].r) - yy; dp[s + 1] += 1; dp[e + 2] += -1; } for (int i = 1; i <= ans; ++i) dp[i] += dp[i - 1]; for (int i = 1; i <= ans; ++i) { dp[i] = dp[i] > 2 ? dp[i] : 0; } for (int i = 1; i <= ans; ++i) { for (int j = 1; j < i; ++j) { int ans = sum(i) - sum(j); dp[i] = max(dp[i], dp[j] + (ans > 2 ? ans : 0)); } for (int j = 1; j <= n; ++j) { int s = lower_bound(yy, yy + ans, no[j].r) - yy; if (s + 1 == i) { int e = lower_bound(yy, yy + ans, no[j].l) - yy; add(e + 1, -1); } } } printf("Case #%d: ", tt); printf("%d\n", dp[ans]); } return 0; }
相关推荐
面部提取器 用法: 下载 安装带有 python 支持的 opencv 将文件复制到facepp-python-sdk目录中 执行pip install -r requirments.txt 使用: python extract_face.py path_to_img运行extract_face.py ...
ExifLib是一个专门为.NET 2.0框架设计的高效Exif数据提取库。Exif(Exchangeable Image File Format)是图像文件中存储元数据的一种标准,通常包含拍摄照片时相机记录的各种信息,如拍摄时间、曝光参数、GPS坐标等。...
赠送jar包:metadata-extractor-2.6.2.jar; 赠送原API文档:metadata-extractor-2.6.2-javadoc.jar; 赠送源代码:metadata-extractor-2.6.2-sources.jar; 赠送Maven依赖信息文件:metadata-extractor-2.6.2.pom;...
gem 'juice_extractor' 然后执行: $ bundle 或将其自己安装为: $ gem install juice_extractor 用法 待办事项:在此处写下使用说明 贡献 叉它 创建功能分支( git checkout -b my-new-feature ) 提交更改...
"Extractor提取工具"是一款强大的资源提取软件,专为处理各种类型文件而设计。它能够方便用户从不同格式的压缩包中快速、高效地提取所需内容,无论是常见的ZIP、RAR还是其他特殊格式,Extractor都能轻松应对。这款...
在IT领域,尤其是在图像处理和数字媒体管理中,"mediautil+metadata-extractor"是一个用于提取和查看EXIF(Exchangeable Image File Format)信息的工具。这个工具包含两个核心组件:`meduautil-1.0.jar`和`metadata...
PyInstaller Extractor v2.0 (Supports pyinstaller 5.3, 5.2, 5.1, 5.0.1, 5.0, 4.10, 4.9, 4.8, 4.7, 4.6, 4.5.1, 4.5, 4.4, 4.3, 4.2, 4.1, 4.0, 3.6, 3.5, 3.4, 3.3, 3.2, 3.1, 3.0, 2.1, 2.0) Author : Extreme...
STDF_Extractor_2.98.rar 是一个压缩包文件,包含了名为 STDF_Extractor_2.98.exe 的可执行程序,这是一个专门用于处理STDF( Semiconductor Test Data Format)数据的工具。STDF是一种标准格式,用于在半导体测试...
Java开发案例-springboot-57-metadata-extractor读取图片信息-源代码+文档.rar Java开发案例-springboot-57-metadata-extractor读取图片信息-源代码+文档.rar Java开发案例-springboot-57-metadata-extractor读取...
赠送jar包:metadata-extractor-2.6.2.jar; 赠送原API文档:metadata-extractor-2.6.2-javadoc.jar; 赠送源代码:metadata-extractor-2.6.2-sources.jar; 赠送Maven依赖信息文件:metadata-extractor-2.6.2.pom;...
.assets 和 AssetBundle 编辑器。 与 Unity Technologies 无关。 UABE 是 3.4+/4/5/2017-2021.3 .assets 和 ...实用程序插件可以在查看数据编辑器中导出和导入字节数组和资源(StreamingInfo、StreamedResource)
Game Extractor是一款知名的游戏资源提取工具,主要用于帮助用户从游戏安装包或已安装的游戏文件中提取各种资源,如音频、图像、脚本等。这款工具因其功能强大且操作简便,在IT爱好者和游戏开发者中广受欢迎。在使用...
《Flash_Extractor_v6_1066.rar》是一款专门针对Adobe Flash内容的提取工具,其核心功能在于帮助用户从SWF格式的Flash文件中提取出各种资源,如图像、音频、视频、字体等,以便于进一步的编辑、分析或备份。...
Extractor2.5 GAL提取 资源提取 GALGAME提取器 提取器 解包工具
这个组合包包括了三个重要的库:`mediautil-1.0.jar`、`metadata-extractor-2.6.2.jar` 和 `xmpcore-5.1.2.jar`,它们都是用于图像处理和元数据提取的关键工具。 首先,我们来详细了解一下这三个库的功能: 1. **...
【vdexExtractor:Android系统中的vdex与odex反编译利器】 在Android系统中,为了提高应用程序的启动速度和运行效率,系统引入了vdex(Virtual Device Execution)和odex(Optimized Dex)文件。这些文件是Dalvik...
《Inno Extractor v5.1.7:深入解析与应用》 Inno Extractor,一个专门用于解压Inno Setup安装程序的工具,它的最新版本v5.1.7.182,为用户提供了高效且便捷的提取功能。Inno Setup是一款广泛使用的Windows平台安装...
"metadata-extractor-2.8.1" 是一个Java库,专门用于从各种图像和音频文件中提取元数据。这个库是由Dave Coffin创建并维护的,它支持大量的文件格式,包括JPEG、TIFF、PNG、PDF等。元数据通常包含关于文件的详细信息...
MTK_Extractor_v2.6.3.zip 是一个专门针对联发科(MediaTek)芯片设备的提取工具,主要用于从MTK平台的固件或ROM中提取各种文件和数据。这个工具对于开发者、手机维修人员以及对Android系统进行自定义修改的爱好者来...