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. http所有请求头在Console中打印

    1.目标:将http中的请求头全部打印在Console中 2.基本语句 //1.获得指定的头 String header = response.getHeader("User-Agert&q ...

  2. mysql Backup &recovery

    备份数据库非常重要,这样您就可以恢复数据,并在发生问题时重新启动并运行,例如系统崩溃,硬件故障或用户错误地删除数据. 在升级MySQL安装之前,备份也是必不可少的保护措施,它们可用于将MySQL安装转 ...

  3. poj 3260 最少硬币(01+多重+完全背包)

    http://www.cnblogs.com/ACMan/archive/2012/08/14/2637437.html #include <iostream> #include < ...

  4. ul li各属性设置

    1. ul li删除前面的黑点:style=“list-style:none;” <ul style=“list-style:none;”> <li></li> & ...

  5. 高德地图 API JavaScript API

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm12.aspx ...

  6. JavaScript有限状态机实现方式

    阮一峰博客 http://www.ruanyifeng.com/blog/2013/09/finite-state_machine_for_javascript.html 开源实现库(javascri ...

  7. Java 监听器,国际化

    1. 监听器 1.1 概述 监听器: 主要是用来监听特定对象的创建或销毁.属性的变化的! 是一个实现特定接口的普通java类! 对象: 自己创建自己用 (不用监听) 别人创建自己用 (需要监听) Se ...

  8. GDAL安装和使用

    1.安装 下载源程序包 ,解压,运行以下三条命令 ./configure --prefix=~ make make install

  9. 【Leetcode】【Medium】Construct Binary Tree from Preorder and Inorder Traversal

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  10. 【源码分析】cocos2dx的Action

    第一次去学习Action,总会找到一篇入门的帖子(官网:http://cn.cocos2d-x.org/article/index?type=cocos2d-x&url=/doc/cocos- ...