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(贪心)
在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...
随机推荐
- MySQL查询结果复制到新表(更新、插入)
MySQL中可以将查询结果复制到另外的一张表中,复制的话通常有两种情况,一种是更新已有的数据,另一种是插入一条新记录.下面通过例子来说明.首先构建两个测试表. 表t1: 表t2: 1.如果t2表中存在 ...
- angular中要注意的指令
1.ng-repeat 遍历集合,给每个元素生成模板实例,每个实例的作用域中可以用一些特殊属性,如下: $index //遍历集合的下标 $first //遍历集合中的第一个对象 $last //遍历 ...
- openvpn的搭建
openvpn搭建 原创不易,转载请注明 openvpn简介 1.1 openvpn原理 OpenVpn的技术核心是虚拟网卡,其次是SSL协议实现 虚拟网卡是使用网络底层编程技术实现的一个驱动软件,安 ...
- win10下端口被占用解决办法
调试socket通信的时候,如果程序未正常结束,重新启动会报端口被占用的错误. 一 查找被占用的端口 解决办法如下:按win+R输入cmd打开控制台,输入 netstat -ano|findstr 8 ...
- python selenium+phantomjs alert()弹窗报错
问题:用selenium+phantomjs 模拟登陆,网页用JavaScript的alert("登陆成功")弹出框,但是用switch_to_alert().accept()报错 ...
- SpringMVC源码情操陶冶-DispatcherServlet
本文对springmvc核心类DispatcherServlet作下简单的向导,方便博主与读者查阅 DispatcherServlet-继承关系 分析DispatcherServlet的继承关系以及主 ...
- 洛谷 [P1169] [ZJOI2007] 最大的正方形
本题是一道求最大子矩阵的题,可以使用悬线法来做,因为是相邻的01矩阵,所以需要对悬线法进行改动. #include <iostream> #include <cstdio> # ...
- POJ 1873 The Fortified Forest [凸包 枚举]
The Fortified Forest Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6400 Accepted: 1 ...
- Linux 下编写服务器程序时关于Address already in use 的小错误
新手,,学习linux服务器编程的时候,bind()函数出现了Address already in use 的错误,这是因为上一次bind过后,还未释放,,只要在socket和bind之间加一个函数就 ...
- WPF中的Command事件绑定
在项目中使用Command绑定能够使我们的代码更加的符合MVVM模式.不了解的同学可能不清楚,只有继承自ButtonBase类的元素才可以直接绑定Command(Button.CheckBox.Rad ...