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. CentOS 6 安装 MySQL 8.0.+

    1.先查询是否安装MySQL 大多数centos 6 自带 MySQL5.1 命令: rpm -qa|grep mysql 执行: [root@lifan ~]# rpm -qa|grep mysql ...

  2. Safari无痕模式下,storage被禁用问题

    前言 Safari开启无痕模式后,localStorage和sessionStorage为空,对其进行set操作也会报错,也就是说这种情况下,storage是被禁止使用了.接下来说一下解决方法. 解决 ...

  3. ccf-201609-3 炉石传说

    问题描述 <炉石传说:魔兽英雄传>(Hearthstone: Heroes of Warcraft,简称炉石传说)是暴雪娱乐开发的一款集换式卡牌游戏(如下图所示).游戏在一个战斗棋盘上进行 ...

  4. [国家集训队2012]middle(陈立杰)

    我是萌萌的传送门 我是另一个萌萌的传送门 脑残错误毁一下午…… 其实题解早就烂大街了,然而很久之前我只知道是二分答案+主席树却想不出来这俩玩意儿怎么一块儿用的……今天又翻了几篇题解才恍然大悟,是把权值 ...

  5. Stirling数

    第一类: 定义 第一类Stirling数表示表示将 n 个不同元素构成m个圆排列的数目.又根据正负性分为无符号第一类Stirling数    和带符号第一类Stirling数    .有无符号Stir ...

  6. Python入门-深浅拷贝

    首先我们在这里先补充一下基础数据类型的一些知识: 一.循环删除 1.前面我们学了列表,字典和集合的一些操作方法:增删改查,现在我们来看一下这个问题: 有这样一个列表: lst = ['周杰伦','周润 ...

  7. css模仿百度首页

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. 如何在一台机器上运行2个Tomcat

    比如:有两个版本的tomcat,一个5.*,一个6.*,此时由于两个工程分别部署在两个 版本的tomcat下,需要同时启动两个tomcat,以下是方法: 1.特别要注意:不要设置CATALINA_HO ...

  9. JS是单线程的吗?

    Javascript是单线程的深入分析 首先一个引子:为什么JavaScript是单线程的却能让AJAX异步发送和回调请求,还有setTimeout也看起来像是多线程的? 先看例子1: functio ...

  10. Nancy使用Razor视图引擎时,提示对C:\Windows\temp 没有权限访问的问题

    Nancy下使用Razor视图需要添加DLL文件引用,通过Nuget安装: 发布网站,在IIS上建立站点后,提示错误:对C:\Windows\temp\XXXX 的访问被拒绝(在VS里F5调试的时候没 ...