HDU - 1789 贪心
贪心策略:按照分数降序排列,如果分数相同将截止时间早的排在前面。每次让作业尽量晚完成,因此需要逆序枚举判断这一天是否已经做了其他作业,如果没时间做这个作业说明不能完成,否则将这一天标记。
AC代码
#include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <utility> #include <string> #include <iostream> #include <map> #include <set> #include <vector> #include <queue> #include <stack> using namespace std; #pragma comment(linker, "/STACK:1024000000,1024000000") #define eps 1e-10 #define inf 0x3f3f3f3f #define PI pair<int, int> typedef long long LL; const int maxn = 1000 + 5; int vis[maxn]; struct sub{ int lim, score; bool operator < (const sub& p) const { return score > p.score || (score == p.score && lim < p.lim); } }a[maxn]; int main() { int T, n; scanf("%d", &T); while(T--) { memset(vis, 0, sizeof(vis)); scanf("%d", &n); for(int i = 0; i < n; ++i) scanf("%d", &a[i].lim); for(int i = 0; i < n; ++i) scanf("%d", &a[i].score); sort(a, a+n); int ans = 0; for(int i = 0; i < n; ++i) { int flag = 0; for(int j = a[i].lim; j > 0; --j) { if(!vis[j]) { vis[j] = 1; flag = 1; break; } } if(!flag) ans += a[i].score; } printf("%d\n", ans); } return 0; }
如有不当之处欢迎指出!
HDU - 1789 贪心的更多相关文章
- HDU 1789 贪心经典
题意 给出n门作业的截止时间与分数 如果不能在那天结束前做完就扣掉相应分数 问怎么安排能让扣分最少 思路 先按分数从大到小排序 先研究大的 做好标记 一开始每天都能放作业 全是true 如果这一天已经 ...
- hdu 1257 && hdu 1789(简单DP或贪心)
第一题;http://acm.hdu.edu.cn/showproblem.php?pid=1257 贪心与dp傻傻分不清楚,把每一个系统的最小值存起来比较 #include<cstdio> ...
- hdu 1789 Doing HomeWork Again (贪心算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 /*Doing Homework again Time Limit: 1000/1000 MS ...
- HDU 1789 - Doing Homework again - [贪心+优先队列]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...
- HDU 1789 Doing Homework again(非常经典的贪心)
Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 题解报告:hdu 1789 Doing Homework again(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has just come back ...
- HDU 1789 Doing Homework again (贪心)
Doing Homework again http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has ...
- HDU 1789 Doing Homework again(贪心)
Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...
- HDU 1789 Doing Homework again(贪心)
在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...
随机推荐
- Maven的Archetype简介
Archetype,骨架的意思. 文章出处:http://m.blog.csdn.net/blog/FireOfStar/42526027 Archetype是什么? 简单的说,Archetype是M ...
- zabbix监控-自定义监控与报警(二)
标签: linux 笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 1.web界面操用(host groups) 1.1创建一个组名字为damo 1.2配置文件解 ...
- float 的不确定性
很多时候,大家都知道,浮点型这个东西,本身存储就是一个不确定的数值,你永远无法知道,它是 0 = 0.00000000000000123 还是 0 = 0.00000000000999这样的东西.也许 ...
- 初识DIV+CSS
div元素是用来为html文档内大声(block-level)的内容提供结构和背景的元素. css是Cascading Style Sheets(层叠样式表单)的缩写,是一种用来表现html或xml等 ...
- JMeter监控服务器CPU、内存的方法
jmeter也可以像loadrunner一样监控服务器CPU.内存等性能参数,不过需要安装一些插件 一.首先下载监控服务器的插件 链接:https://pan.baidu.com/s/1o9Zuw ...
- BZOJ 1845: [Cqoi2005] 三角形面积并 [计算几何 扫描线]
1845: [Cqoi2005] 三角形面积并 Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 1151 Solved: 313[Submit][Stat ...
- POJ 1873 The Fortified Forest [凸包 枚举]
The Fortified Forest Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6400 Accepted: 1 ...
- AMDP + XSLX Workbench 报表开发模式
本文介绍了我和同事通过使用AMDP + XSLX Workbench缩短报表开发周期.分离数据查询处理逻辑和前端展示工作的经验.欢迎讨论. 前言 最近接到了一套人力资源报表的开发需求,需要以EXCEL ...
- MessagePack简析
一.MessagePack是什么 先看官方的定义:MessagePack是一种高效的二进制序列化格式.它允许您像JSON一样在多个语言之间交换数据.但是,它更快并且更小. 从官方定义中,可以有如下的结 ...
- python脚本0b文件处理
要处理的文件: 此处处理将00的数据干掉. 处理python脚本: dir_fd = open('abc.yuv','rb+') tmp_fd = open('tmp.yuv','wb+') whil ...