贪心策略:按照分数降序排列,如果分数相同将截止时间早的排在前面。每次让作业尽量晚完成,因此需要逆序枚举判断这一天是否已经做了其他作业,如果没时间做这个作业说明不能完成,否则将这一天标记。

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 贪心的更多相关文章

  1. HDU 1789 贪心经典

    题意 给出n门作业的截止时间与分数 如果不能在那天结束前做完就扣掉相应分数 问怎么安排能让扣分最少 思路 先按分数从大到小排序 先研究大的 做好标记 一开始每天都能放作业 全是true 如果这一天已经 ...

  2. hdu 1257 && hdu 1789(简单DP或贪心)

    第一题;http://acm.hdu.edu.cn/showproblem.php?pid=1257 贪心与dp傻傻分不清楚,把每一个系统的最小值存起来比较 #include<cstdio> ...

  3. hdu 1789 Doing HomeWork Again (贪心算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 /*Doing Homework again Time Limit: 1000/1000 MS ...

  4. HDU 1789 - Doing Homework again - [贪心+优先队列]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...

  5. HDU 1789 Doing Homework again(非常经典的贪心)

    Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  6. 题解报告:hdu 1789 Doing Homework again(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has just come back ...

  7. HDU 1789 Doing Homework again (贪心)

    Doing Homework again http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has ...

  8. HDU 1789 Doing Homework again(贪心)

    Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...

  9. HDU 1789 Doing Homework again(贪心)

    在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...

随机推荐

  1. 国内不谈java

    今天晚上在整理电脑,不知道怎么回事,电脑里面放着一篇文章.打开一看写的挺好的,现在就贴出来,望共勉.   国内不谈java--会有千万人跳出来和你争嘴的.越是如此,我越是不忍心不说出来,越是不不忍心看 ...

  2. Arrays.sort解析

    Arrays.sort()解读 在学习了排序算法之后, 再来看看 Java 源码中的, Arrays.sort() 方法对于排序的实现. 都是对基本数据类型的排序实现, 下面来看看这段代码: Arra ...

  3. redis动态配置

    Config get CONFIG GET parameter CONFIG GET 命令用于取得运行中的 Redis 服务器的配置参数(configuration parameters),在 Red ...

  4. Spring AOP小记

    一.概述 在通常的开发过程中,我们调用的顺序通常是controller->service-dao,其中,service中包含着太多的业务逻辑,并且还要不断调用dao来实现自身的业务逻辑,经常会导 ...

  5. Hyperledger Fabric Chaincode for Operators——实操智能合约

    什么是Chaincode(智能合约)? chaincode是一个程序,它是使用Go语言编写的,最终在Java等其他编程语言中实现了指定的接口.chaincode运行在一个被背书peer进程独立出来的安 ...

  6. linux下安装phpunit简单方法

    现在安装phpunit相当简单,只需要下载phar压缩格式的phpunit文件,给个执行权限,就可以执行了 以下是一段官方安装文档 wget https://phar.phpunit.de/phpun ...

  7. SpringMVC源码情操陶冶-AbstractHandlerMapping

    分析下springmvc的HandlerMapping映射的抽象类 初始化操作 通过initApplicationContext()方法进行初始化,其一般是由父类执行ApplicationContex ...

  8. fiddler2请求参数乱码

    win7 1.windows按钮+R 2.输入regedit +回车+是 3.HKEY_CURRENT_USER\Software\Microsoft\Fiddler2 4.右键新建,选字符串值 加上 ...

  9. JS高级程序设计第3章读书笔记

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 一步一步从原理跟我学邮件收取及发送 12.telnet命令行收一封信pop3

    本系列上一篇文章中我们就说到了,这一次我们要说 pop3 收信了.虽然我觉得应该先说完 mime 格式,不过估计大家已经不耐烦了 -- 怎么老在说发送啊?我们要看收取!    好吧,来啦,来啦!收取邮 ...