HDU 1789 Doing Homework again (贪心)
Doing Homework again
http://acm.hdu.edu.cn/showproblem.php?pid=1789
Each test case start with a positive integer N(1<=N<=1000) which indicate the number of homework.. Then 2 lines follow. The first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the reduced scores.
解题思路:每次取扣分最多的先安排,安排到那天没有任务的那天,所以将数据按扣分多少,由高到低排序,扣分相同的按最后期限,由少到多排序!
解题代码 :
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std; const int max_n = ; struct SBU
{
int a, b;
bool operator < (const SBU sbu) const
{
if (b == sbu.b)
return a < sbu.a;
return b > sbu.b;
}
}; int dp[max_n], tag[max_n]; int main ()
{
int T, n;
scanf ("%d", &T);
SBU home[max_n];
while (T--)
{
int max_sum = ;
scanf ("%d", &n);
memset (tag, , sizeof (tag));
for (int i = ; i < n; i ++)
{
scanf ("%d", &home[i].a);
}
for (int i = ; i < n; i ++)
{
scanf ("%d", &home[i].b);
max_sum += home[i].b;
}
sort(home, home+n);
int sum = ;
for (int i = ; i < n; i ++)
{
int d = home[i].a;
for (;d >= ; d --)//寻找能放置任务的那天
{
if (tag[d] == )//找到退出
break;
}
if (tag[d] == && d > )//判断是否可以安置
{
tag[d] = ;//可以的话,将这天标记已有任务
sum += home[i].b;
}
}
cout << (max_sum - sum) <<endl;
}
return ;
}
HDU 1789 Doing Homework again (贪心)的更多相关文章
- 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 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...
- hdu 1789 Doing Homework again (Greedy)
Problem - 1789 继续贪心.经典贪心算法,如果数据比较大就要用线段树来维护了. 思路很简单,只要按照代价由大到小排序,然后靠后插入即可.RE了一次,是没想到deadline可以很大.如果d ...
- 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(贪心)
在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...
- HDU - 1789 Doing Homework again(贪心) ~~~学了一波sort对结构体排序
题目中因为天数和分数是对应的,所以我们使用一个结构体来存分数和截止如期. 一开始做这道题的时候,很自然的就想到对天数排序,然后天数一样的分数从大到小排序,最后WA了之后才发现没有做到"舍小取 ...
- HDU 1789 Doing Homework again【贪心】
题意:给出n个作业的截止时间,和该作业没有完成会被扣掉的分数.问最少会被扣掉多少分. 第一次做这一题是好久之前,当时不会(不会处理两个关键字关系@_@)---现在还是不会---看了题解---原来是这样 ...
随机推荐
- DWR在Spring中应用
这里以传递一个对象为例,来说明dwr在Spring中是怎么配置的. JSP页面: <script src='dwr/interface/instructionOuterService.js'&g ...
- orcle 查询数据集对变量赋值函数
create or replace function test(Name in varchar2 ) return varchar2 is V_CONTAINERDESC CHAR ); BEGIN ...
- [转]Ubuntu下配置NFS服务
[转]Ubuntu下配置NFS服务 http://blog.163.com/liu8821031%40126/blog/static/111782570200921021253516/ Table ...
- [转]tftp在put上传的时候显示File not found的解决办法
[转]tftp在put上传的时候显示File not found的解决办法 http://blog.163.com/pengcz%40126/blog/static/35908607201182433 ...
- 学习IOS需要知道的事
什么是iOS iOS是一款由苹果公司开发的操作系统(OS是Operating System的简称),就像平时在电脑上用的Windows XP.Windows 7,都是操作系统 那什么是操作系统呢?操作 ...
- Java实现TCP之Echo客户端和服务端
Java实现TCP之Echo客户端和服务端 代码内容 采用TCP协议编写服务器端代码(端口任意) 编写客户机的代码访问该端口 客户机按行输入 服务器将收到的字符流和接收到的时间输出在服务器consol ...
- html readme
取html页面高度 document.documentElement.scrollHeight在IE和Chrome下,可以正常取到合适的全文高度,但是firefox下取到的则过高: 用document ...
- [Android Training视频系列] 8.3 Dealing with Audio Output Hardware
用户在播放音乐的时候有多个选择,可以使用内置的扬声器,有线耳机或者是支持A2DP的蓝牙耳机.(补充:A2DP全名是Advanced Audio Distribution Profile 蓝牙音频传输模 ...
- VS中设置#define _CRT_SECURE_NO_WARNINGS的两种方式
1.我们在编译老的用C语言的开源项目如lua源包的时候,可能因为一些老的.c文件使用了strcpy,scanf等不安全的函数,而报警告和错误,而导致无法编译通过. 2.此时我们有两种解决方案: a.在 ...
- C++中不可重载的5个运算符
大多数运算符都是可以重载的,但是有5个运算符C++语言规定是不可以重载的. 1. .(点运算符),通常用于去对象的成员,但是->(箭头运算符),是可以重载的 2.::(域运算符),即类名+域运算 ...