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. sharepoint 訪问缩略图

    Sharepoint缩略图 简单介绍 Sharepoint2010中有专门的图片库,当你新建图片库后,向图片上传一部分图片.当你浏览这个库时显示一排排小图片.当点击一个图片时进入显示的是大图.不要简单 ...

  2. Python获取CPU、内存使用率以及网络使用状态代码

    Python获取CPU.内存使用率以及网络使用状态代码_python_脚本之家 http://www.jb51.net/article/134714.htm

  3. android MediaRecorder start failed:-38【转】

    本文转载自:http://blog.csdn.net/fnuwfnh/article/details/46698509 最近在学习android 录音方面的知识,发现在部分手机正常运行的APP,在华为 ...

  4. POJ 1477:Box of Bricks

    Box of Bricks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19949   Accepted: 8029 De ...

  5. 8-12 canvas专题-阶段练习一(上)

    8-12 canvas专题-阶段练习一(上) <!DOCTYPE html> <html lang="zh-cn"> <head> <me ...

  6. Mac系统打开命令行终端及查看操作系统版本号的方法

    Mac系统打开命令行终端的方法: 应用程序 --> 实用工具 --> 终端 Mac系统终端查看操作系统版本号的方法: 输入:#more /System/Library/CoreServic ...

  7. uva 12265 贩卖土地

    题目大意: 有一个矩阵 有些点可以取有些不能 求以每个点为右下角的子矩阵(里面点都可以取)的周长最大值 最后统计出每个周长对应矩阵的个数 思路: 单调栈 先预处理出每个点向上最多能延伸多长记为h(i, ...

  8. 洛谷 P1131 [ ZJOI 2007 ] 时态同步 —— 树形DP

    题目:https://www.luogu.org/problemnew/show/P1131 记录 x 子树内同步的时间 f[x],同步所需代价 g[x]: 直接转移即可,让该儿子子树与其它儿子同步, ...

  9. the odb manual

    http://www.codesynthesis.com/products/odb/doc/manual.xhtml#18.4

  10. 模块化编程:AMD规范

    目前,通行的Javascript模块规范共有两种:ComonJS和AMD. CommonJS node.js的模块系统,就是参照CommonJS规范实现的.在ConmonJS中,有一个全局方法requ ...