Doing Homework again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 17622    Accepted Submission(s): 10252

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
 
Author
lcy
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  1978 1421 2159 1231 2571 
 
题目连接:
 
分析:
非常经典的贪心题
在自己学校贪心专项的时候写过这道题,自己没有思考出来,还是看了题解,但总算搞懂了
今天在csu又遇到了这道题,开心
贪心思想:先将作业排序:扣分大的排前面,扣分相同的截至时间小的放前面
开一个标记数组,从排序号的第一个作业开始遍历,作业的完成时间安排在作业截至时间的前一天,如果前一天被占用了的话,就看前前天,如果前前天没有被占用的话,就安排在前前天,如果前前天也被占用了的话,就继续前移,如果没有时间给你安排此作业的话,那么此作业就必须被扣分了
注意:一个作业:day:3,权值:5,截止时间是4,就是第四天以前,所以一开始是安排在第三天
code:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define max_v 1005
int vis[max_v];
struct node
{
int d,w;
}p[max_v];
bool cmp(node a,node b)//扣分大的排前面,扣分相同的截至时间小的放前面
{
if(a.w!=b.w)
{
return a.w>b.w;
}
else
{
return a.d<b.d;
}
}
int main()
{
int t;
cin>>t;
int n;
while(t--)
{
memset(vis,,sizeof(vis));//天数占用情况标记数组
cin>>n;
for(int i=;i<n;i++)
{
cin>>p[i].d;
}
for(int i=;i<n;i++)
{
cin>>p[i].w;
}
sort(p,p+n,cmp);
int sum=;
for(int i=;i<n;i++)
{
if(vis[p[i].d]==)//没有被占用
{
vis[p[i].d]=;//直接安排
}else//被占用了
{
int f=;
for(int j=p[i].d-;j>=;j--)//在前面找一个没有被占用的天,如果没有那此作业就是要被扣分的
{
if(vis[j]==)
{
vis[j]=;
f=;
break;
}
}
if(f==)
{
sum+=p[i].w;
}
}
}
cout<<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 (贪心)

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

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

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

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

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

  5. hdu 1789 Doing Homework again (Greedy)

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

  6. HDU 1789 Doing Homework again(贪心)

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

  7. HDU 1789 Doing Homework again(贪心)

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

  8. HDU 1789 Doing Homework again(馋)

    意甲冠军  参加大ACM竞争是非常回落乔布斯  每一个工作都有截止日期   未完成必要的期限结束的期限内扣除相应的积分   求点扣除的最低数量 把全部作业按扣分大小从大到小排序  然后就贪阿  能完毕 ...

  9. HDU 1789 Doing Homework again(排序,DP)

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

随机推荐

  1. request方法总结

     1.获得指定的头 String header = response.getHeader("user-agent"); 2.获得所有头的名称 Enumeration<Stri ...

  2. java 错误: 未报告的异常错误Exception; 必须对其进行捕获或声明以便抛出

    import java.io.FileInputStream; import java.util.Properties; import java.sql.Connection; import java ...

  3. php动态链接扩展库

    文章来源:http://keping.me/php-call-so/ PHP调用C/C++动态链接库 David June 19, 2013 C++, Linux, Study 摘要 有时候,单纯依靠 ...

  4. svg拖拽和缩放

    需求:做机房平面图,用svg实现拖拽和缩放,刚开始一头雾水,不知所措,好在皇天不负有心人........ 本文重点介绍拖拽,单纯实现很简单,但是由于vue项目,机房图有很多事件,拖拽就成了难点 简单介 ...

  5. Oracle INSERT ALL 语句介绍

    描述 Oracle INSERT ALL 语句用来用一个 INSERT 语句添加多行.该行可以只使用一个SQL命令插入到一个表或多个表. 语法 Oracle INSERT ALL 语法如下: INSE ...

  6. 【译】MapCSS 与 CartoCSS

    原文地址: https://gist.github.com/tmcw/4319642 CartoCSS 的作者是通过 Cascadenik 为灵感进而创作的 CartoCSS. CartoCSS 与 ...

  7. CentOS 7运维管理笔记(1)----设置默认启动模式为GUI模式或命令行模式

    昨天在虚拟机中安装CentOS 7时选择了GNOME模式安装,开机默认进入GUI模式.网上搜找修改为默认命令行模式的方法,看到说修改 /etc/inittab文件,在最低下一行添加 但是 使用 cat ...

  8. JAVA程序编写入门

    在任意文件夹下创建一个文本,然后重命名,把文本后缀名改为.java.然后用eclipse打开此文件编写程序内容. public class nihao{ public static void main ...

  9. 【Android】移动项目位置

    一.前言 有时候,我们新建一个项目后,因为一些原因想要重新移动项目到别的文件夹.然而,移动到新的文件夹后,却发现之前好好的项目运行不了.点击运行后,弹出如下对话框.  Installation fai ...

  10. flask框架下的jinja2模板引擎(1)(模板渲染)

    #转载请留言联系 模板是什么? 在 flask 框架中,视图函数有两个作用:处理业务逻辑和返回响应内容.在大型应用中,把业务逻辑和表现内容放在一起,会增加代码的复杂度和维护成本.模板作用即是承担视图函 ...