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. three.js 在vscode的智能提示

    安装nodejs.启动或者重启vscode,打开控制台,输入命令 npm install --save @types/three 回车, 会多了个node_modules文件夹,再试试智能感知,出来. ...

  2. 来谈谈你对CSS盒模型的认识?

    任何一个网页的搭建都离不开盒模型的堆砌.应该说css模型是web的一个根基,最后呈现出来的效果不同无非就是在高宽.内容与背景删的区别而已. 那么CSS模型有什么认识的呢? 首先,css盒模型有几种呢? ...

  3. js数组详解

        1,什么是数组 数组是值得有序集合,每个值叫做一个元素,而每个元素在数组中有一个位置,以数字表示,称为索引.js的数组是无类型的,数组元素可以是任意类型,同一个数组中的不同元素可能是对象或数组 ...

  4. javascript获取文件后缀名

    javascript获取文件后缀名:在需要验证文件格式的时候,首先就要获得文件的格式,下面是一个通过正则表达式获取文件后缀名的一个简单实例. function validate(){ var impo ...

  5. css3 animation运用

    animation:mymove 5s infinite; @keyframes mymove { from {left:0px;} to {left:200px;} } @-webkit-keyfr ...

  6. awk查找

    cat catalina.out|grep "报表 sql"|awk -F '[' '{print $5}'|awk -F ']' '{print $1}'|sort -n|uni ...

  7. 微软发布Azure Stack第一个技术预览版

    为了提升商业灵敏度和加快创新步伐,各个企业都在迅速地转向云服务.在微软,我们已经见到微软智能云Azure的飞速发展和使用,每月我们都有近十万的新增订阅量.然而,我们也了解到还有很多企业在完全移到公有云 ...

  8. Angular2 前端代码规范

    不要重置对象的引用!(重置只应该在组件或服务的初始化时) why:会使页面产生闪烁 不要给图片绑定一个空的值或空的图片引用(如果值从服务器异步过来,那应该在初始化时给它一个默认值)why:会触发一个4 ...

  9. openvpn(上)

    VPN概述:(全称Virtual Private Network)虚拟专用网络,是依靠ISP和其他的NSP,在公网中建立专用的数据通信网络的技术,可以为企业之间或者个人与企业之间提供安全的数据传输隧道 ...

  10. Eigen参考资料

    Getting started https://eigen.tuxfamily.org/dox/GettingStarted.html long tutorial https://eigen.tuxf ...