Doing Homework again

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

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

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int MAXN=; struct Node
{
int d,s;
}node[MAXN]; bool used[]; bool cmp(Node a,Node b)
{
if(a.s==b.s)
{
return a.d<b.d;
}
return a.s>b.s;
} //按减分从大到小排,按日期从小到大排 int main()
{
int T;
int n;
int j;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%d",&node[i].d);
for(int i=;i<n;i++) scanf("%d",&node[i].s);
sort(node,node+n,cmp);
memset(used,false,sizeof(used));//装每天所学的课程
int ans=;
for(int i=;i<n;i++)
{
for(j=node[i].d;j>;j--)//从截止日期开始往前数
{
if(!used[j])
{
used[j]=true;
break;
}
}
if(j==)//当一个位置都没有,就减分
ans+=node[i].s;
}
printf("%d\n",ans);
}
return ;
}

都说这个是水题,但是我想了很久。。。。。

继续努力吧!

HDU 1789 Doing Homework again(排序,DP)的更多相关文章

  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(贪心) ~~~学了一波sort对结构体排序

    题目中因为天数和分数是对应的,所以我们使用一个结构体来存分数和截止如期. 一开始做这道题的时候,很自然的就想到对天数排序,然后天数一样的分数从大到小排序,最后WA了之后才发现没有做到"舍小取 ...

  3. HDU 1789 Doing Homework again (贪心)

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

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

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

  5. HDU 1789 Doing Homework again(非常经典的贪心)

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

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

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

  7. HDU 1789 Doing Homework again(贪心)

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

  8. HDU 1074 Doing Homework(像缩进DP)

    Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of h ...

  9. HDU 1789 Doing Homework again(贪心)

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

随机推荐

  1. redis安装成功后get: command not found

    安装redis后客户端无法使用,即redis-cli执行后报找不到的错误. 这主要是安装redis的时候没有把客户端装上,在StackOverFlow上找到了一种只安装redis cli的方法. 安装 ...

  2. mybatis invalid bound statement (not found)

    Spring boot + Mybatis : Invalid bound statement (not found) 如果只在启动类上配置@MapperScan注解,默认只扫描和mapper接口同名 ...

  3. 前端学习之一_html学习

    html元素分类 内连元素:出现在行内的元素            <img>,<q>,<a> 块元素:前后自动插入换行的元素         <h1> ...

  4. 第六周总结 & 实验报告(四)

    第六周小结 一.instanceof关键字         在Java中使用instanceof关键字判断一个对象到底是哪个类的实例,返回boolean类型 1.instanceof关键字的作用 例c ...

  5. 【python】小型神经网络的搭建

    import numpy as np def sigmoid(x): # Sigmoid activation function: f(x) = 1 / (1 + e^(-x)) return 1 / ...

  6. Win10无法修改编辑hosts文件

    Win10无法修改编辑hosts文件 一.总结 一句话总结: 这里我的问题是windows的某次更新中把hosts文件或者上级目录设置成了只读,在文件属性中去掉这个只读就好 后文的操作相当于是给文件添 ...

  7. 使用 split 命令分割 Linux 文件,使用 cat 合并文件

    一些简单的 Linux 命令能让你根据需要分割以及重新组合文件,来适应存储或电子邮件附件大小的限制. Linux 系统提供了一个非常易于使用的命令来分割文件.在将文件上传到限制大小的存储网站或者作为邮 ...

  8. c++11多线程---线程锁(mutex)

    #include<mutex> 包含四类锁: 1      std::mutex    最基本也是最常用的互斥类 2      std::recursive_mutex  同一线程内可递归 ...

  9. Mac 安装 Novicat

    https://blog.csdn.net/jor_ivy/article/details/81323199 详细见这篇文章

  10. 1.2.1 Maven到底是什么鬼

    解释之前,提1个小问题. 1.1.假如你正在Eclipse下开发两个Java项目,姑且把它们称为A.B,其中A项目中的一些功能依赖于B项目中的某些类,那么如何维系这种依赖关系的呢? 很简单,这不就是跟 ...