Doing Homework again

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

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
 
之前做doing homework是用的dp,这道题一来也想用dp,没想到思路,想了好久,然后搜了题解,发现是用的贪心,然后又不知道怎么贪。。。
最后用了题解的思路,按罚分由大到小排序,deadline之前只要有空着的天,那么就在最晚的那一天完成这项任务,否则,无空闲天,则会被罚分。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; struct Node
{
int dead;
int sco;
} node[];
int dead[];
int sco[]; bool cmp(Node a,Node b)
{
if(a.sco>b.sco)
return ;
return ;
} int vis[]; int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
memset(vis,,sizeof(vis));
scanf("%d",&n);
for(int i=; i<n; i++)
scanf("%d",&dead[i]);
for(int i=; i<n; i++)
scanf("%d",&sco[i]);
for(int i=; i<n; i++)
{
node[i].dead=dead[i];
node[i].sco=sco[i];
}
sort(node,node+n,cmp);
int day=,spent=;
for(int i=; i<n; i++)
{
int j;
for( j=node[i].dead; j>=; j--)
{
if(vis[j]==)
{
vis[j]=;
break;
}
}
if(j==)
spent+=node[i].sco;
}
printf("%d\n",spent);
}
return ;
}

HDU_1789_doing homework again_贪心的更多相关文章

  1. HDU 1789 Doing Homework again(贪心)

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

  2. hdu--1798--Doing Homework again(贪心)

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

  3. hdu 1789 Doing HomeWork Again (贪心算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 /*Doing Homework again Time Limit: 1000/1000 MS ...

  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. HDOJ.1789 Doing Homework again (贪心)

    Doing Homework again 点我挑战题目 题意分析 给出n组数据,每组数据中有每份作业的deadline和score,如果不能按期完成,则要扣相应score,求每组数据最少扣除的scor ...

  6. I - Doing Homework again(贪心)

    I - Doing Homework again Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  7. hdu1789 Doing Homework again(贪心+排序)

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

  8. HDU-1789 Doing Homework again 贪心问题 有时间限制的最小化惩罚问题

    题目链接:https://cn.vjudge.net/problem/HDU-1789 题意 小明有一大堆作业没写,且做一个作业就要花一天时间 给出所有作业的时间限制,和不写作业后要扣的分数 问如何安 ...

  9. 【HDOJ6343】Graph Theory Homework(贪心)

    题意: 给定n个点,每个点有权值a[i],从A走到B的花费是下取整sqrt(a[i]-a[j]),求从1号点走到n号点的最小花费 1<=n,a[i]<=1e5 思路: #include&l ...

随机推荐

  1. 改动select默认样式,兼容IE9

    前面有篇文章已经提供了怎样改动select标签的默认样式,可是仅仅能兼容到ie10,要兼容ie9仅仅能模拟一个类似的 html结构: <div class="select_diy&qu ...

  2. node+vue-cli+webpack搭建教程

    链接:https://segmentfault.com/a/1190000009160934?_ea=1849098 链接:https://www.jianshu.com/p/2769efeaa10a ...

  3. C语言之基本算法21—可逆素数

    /* ================================================================== 题目:可逆素数是指一个数是素数,逆序后还是素数,如ABC是素 ...

  4. python模块之 paramiko(转载)

    paramiko模块提供了ssh及sft进行远程登录服务器执行命令和上传下载文件的功能.这是一个第三方的软件包,使用之前需要安装. 1 基于用户名和密码的 sshclient 方式登录 # 建立一个s ...

  5. Git经常使用命令总结

    Git是一款开源的分布式版本号控制系统,由Linux之父Torvalds用C语言开发. "the stupid content tracker",Git自诩为stupid,却是一个 ...

  6. HDU 4070 + 赤裸裸的贪心~~

    J - Phage War Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Phage ...

  7. [NOIP 2010] 引入入城

    [题目链接] https://loj.ac/problem/2595 [算法] 显然 , 每个第一行的成市控制的一定是一段区间 那么 , 问题就转化为了经典的区间覆盖问题 , 贪心即可 , 时间复杂度 ...

  8. 再读headfirst-原则与模式摘录

    原则 1.找到原则中可能需要变化之处,把它们独立出来,不要和那些不需要变化的代码混在一起 2.针对接口编程,而不是针对实现编程 3.多用组合,少用继承 4.依赖倒置原则:要依赖抽象,不要依赖具体类(不 ...

  9. 4-2 买家类目-dao(下)

    查询出来的对象ProductCategory就已经有updateTime和createTime了,然而你只是把对象的categoryType给修改了一下,修改之后就执行save方法保存了.所以它还是原 ...

  10. 清北考前刷题day6早安

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #d ...