Doing Homework again

http://acm.hdu.edu.cn/showproblem.php?pid=1789

Problem Description
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test. And now we assume that doing everyone homework always takes one day. So Ignatius wants you to help him to arrange the order of doing homework to minimize the reduced score.
 
Input
The input contains several test cases. The first line of the input is a single integer T that is the number of test cases. T test cases follow.
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.
 
Output
For each test case, you should output the smallest total reduced score, one line per test case.
 
Sample Input
3
3
3 3 3
10 5 1
3
1 3 1
6 2 3
7
1 4 6 4 2 4 3
3 2 1 7 6 5 4
 
Sample Output
0
3
5
 

解题思路:每次取扣分最多的先安排,安排到那天没有任务的那天,所以将数据按扣分多少,由高到低排序,扣分相同的按最后期限,由少到多排序!

解题代码 :

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

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

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

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

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

  3. HDU 1789 Doing Homework again(贪心)

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

  4. hdu 1789 Doing Homework again (Greedy)

    Problem - 1789 继续贪心.经典贪心算法,如果数据比较大就要用线段树来维护了. 思路很简单,只要按照代价由大到小排序,然后靠后插入即可.RE了一次,是没想到deadline可以很大.如果d ...

  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(贪心)

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

  8. HDU - 1789 Doing Homework again(贪心) ~~~学了一波sort对结构体排序

    题目中因为天数和分数是对应的,所以我们使用一个结构体来存分数和截止如期. 一开始做这道题的时候,很自然的就想到对天数排序,然后天数一样的分数从大到小排序,最后WA了之后才发现没有做到"舍小取 ...

  9. HDU 1789 Doing Homework again【贪心】

    题意:给出n个作业的截止时间,和该作业没有完成会被扣掉的分数.问最少会被扣掉多少分. 第一次做这一题是好久之前,当时不会(不会处理两个关键字关系@_@)---现在还是不会---看了题解---原来是这样 ...

随机推荐

  1. Android清除本地数据缓存代码案例

    Android清除本地数据缓存代码案例 直接上代码: /*  * 文 件 名:  DataCleanManager.java  * 描    述:  主要功能有清除内/外缓存,清除数据库,清除shar ...

  2. Xcode全局断点

    1.将导航器视图切换到断点导航器视图下,也可以用快捷键Command+7一步搞定,键盘是window风格的用户Command键是win键(有微软logo),然后点击左下角的+号,选择Add Symbo ...

  3. 如何在github上fork一个项目来贡献代码以及同步原作者的修改

    [-] 如何贡献自己的力量 如何让自己的项目与原作者的项目保持同步 作为一个IT人,通过github进行学习是最快的成长手 段.我们可以浏览别人的优秀代码.但只看不动手还是成长得很慢,因此为别人贡献代 ...

  4. Oracle 11g 11201_RHEL5.5_RAC_VBOX 详细搭建步骤

    1.安装好vbox,创建好虚拟机(红帽5.5),注意:VBOX全局设置VBOX磁盘的位置和备份位置     IP.hostname 规划:              hostname          ...

  5. UITableView设置cell为不可选?

    本文选自StackOverflow(简称:SOF)精选问答汇总系列文章之一,本系列文章将为读者分享国外最优质的精彩问与答,供读者学习和了解国外最新技术.本文将为读者讲解UITableView如何设置单 ...

  6. 安装v2meet客户端 进入会议依然 提示 您还未安装视频会议的客户端,请下载安装

    解决办法 1.安装软件,要用管理员权限安装 2.装一个360浏览器,登录会议,这样就成功了.原装IE9却不行. 估计是IE9做了一些安全限制,由于时间关系就没有再处理了.

  7. 校园导游之NABC个人分析

    校园导游之NABC个人分析 Need: 为不熟悉校园环境的人们(如新生,来咱们学校参观滴)提供便利. Approach: 了解Andriod应用开发:导航功能之外还可以对学校进行宣传,比如拍一些学校的 ...

  8. multipart/form-data

    Content-Type的类型扩充了multipart/form-data用以支持向服务器发送二进制数据

  9. Careercup - Microsoft面试题 - 6337018766295040

    2014-05-10 06:38 题目链接 原题: What do you think is the next big thing in technology? For example, search ...

  10. 关于Python中的yield

    关于Python中的yield   在介绍yield前有必要先说明下Python中的迭代器(iterator)和生成器(constructor). 一.迭代器(iterator) 在Python中,f ...