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. shiro权限控制入门

    一:权限控制两种主要方式 粗粒度 URL 级别权限控制和细粒度方法级别权限控制 1.粗粒度 URL 级别权限控制 可以基于 Filter 实现在数据库中存放 用户.权限.访问 URL 对应关系, 当前 ...

  2. SQL语句整理(一) 数据库查询语言DQL

    前言: 这是我学数据库时整理的学习资料,基本上包括了所以的SQL语句的知识点. 我的教材是人大王珊老师的<数据库系统概论>. 因为是手打的,所以会用一些细节打错了,但都挺明显也不多(考完试 ...

  3. Spring和Hibernate结合的一个小例子

    1.新建一个SpringHibernate的maven项目 2.pom文件的依赖为 <dependency> <groupId>junit</groupId> &l ...

  4. webpack build后生成的app、vendor、manifest三者有何职能不同?

    贴一下之前vue脚手架的webpack3配置: app.js是入口js,vendor则是通过提取公共模块插件来提取的代码块(webpack本身带的模块化代码部分),而manifest则是在vendor ...

  5. JavaEE之会话技术Cookie&Session

    会话技术简介 存储客户端的状态 由一个问题引出今天的内容,例如网站的购物系统,用户将购买的商品信息存储到哪         里?因为Http协议是无状态的,也就是说每个客户访问服务器端资源时,服务器并 ...

  6. #!/bin/sh & #!/bin/bash区别

    在shell脚本的开头往往有一句话来定义使用哪种sh解释器来解释脚本.目前研发送测的shell脚本中主要有以下两种方式:(1) #!/bin/sh(2) #!/bin/bash以上两种方式有什么区别? ...

  7. 原生JS的轮播图

    学习前端也有一小段时间了,当初在学习javascript的时候,练手的一个轮播图实例,轮播图也是挺常见的了. 着是通过获取图片偏移量实现的.也实现了无缝切换.还有一点问题就是没有加上图片切换的时候的延 ...

  8. C# 使用Guid类生成不重复的随机数

    什么是Guid GUID(全局唯一标识符)         全局唯一标识符(GUID,Globally Unique Identifier)是一种由算法生成的二进制长度为128位的数字标识符.GUID ...

  9. Android 友盟统计的集成与使用(包含多渠道打包配置)

    前言 app上线后,一般公司都希望跟踪app在市场上的使用情况.包括新增用户.活跃用户.渠道信息.错误信息等,还有例如商城类的app,需要跟踪用户最喜欢浏览哪种类型的店铺或商品.这些都可以通过集成友盟 ...

  10. 如何让LoadRunner实现多个场景运行?

    如何让LoadRunner实现多个场景运行? 发布时间: 2013-11-29 10:59    作者: stevenlee    来源: 51Testing软件测试网博客 字体:  小  中  大  ...