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. react 项目实战(二)创建 用户添加 页面 及 fetch请求 json-server db.json -w -p 8000

    1.安装 路由 npm install -S react-router@3.x 2.新增页面 我们现在的应用只有一个Hello React的页面,现在需要添加一个用于添加用户的页面. 首先在/src目 ...

  2. DES加密算法的C++实现

    <信息安全技术>这门课又在讲 DES 加密算法了,以前用纯C写过一次,这次我用 C++ 重新写了一个,写篇文章以备后用.本文介绍了 DES 算法加密的大致步骤和整体流程. 一.DES算法原 ...

  3. AVAudioSessionCategory的选择

    AVAudioSessionCategoryAmbient 或 kAudioSessionCategory_AmbientSound --用于非以语音为主的应用,使用这个category的应用会随着静 ...

  4. Windows 驱动开发 - 7

    在<Windows 驱动开发 - 5>我们所说的读写操作在本篇实现. 在WDF中实现此功能主要为:EvtIoRead和EvtIoWrite. 首先,在EvtDeviceAdd设置以上两个回 ...

  5. Android 网络学习之获取server文本文件

    上次我们学习怎样从网络上获取一张图片,今天我们学习怎样从网络上获取文本文件.以XML文件为样例. 由于XML文件在实际开发中最为常见. 我们以以下图片为样例学习怎样从网络上获取XML文件 我们的xml ...

  6. BZOJ1179 : [Apio2009]Atm 缩点+spfa

    1179: [Apio2009]Atm Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 2069  Solved: 826[Submit][Status ...

  7. qq xxs

    qq xxs qq xxs 有很多举个简单例子 : QQ空间发段文章 带上 <script> 提交(document.cookie) 到 自己服务端获取 </script> 在 ...

  8. hdu 5074 Hatsune Miku DP题目

    题目传送门http://acm.hdu.edu.cn/showproblem.php?pid=5074 $dp[i][j] =$ 表示数列前$i$个数以$j$结尾的最大分数 $dp[i][j] = - ...

  9. 美国诚实签经验——我们准备了XX万的存款,这足以应付我预算表中涉及的所有开支,如果有意外情况我们的资金不足以应付,我们双方的父母也会支援我们,绝对不会占用美国的任何福利

    闲话少絮,直接分享本人诚实签的经验,希望对有此打算的朋友有帮助! 个人经验有限,经历仅供参考~~ 第一步:决定赴美生子. 第二步:选择诚实签. 第三步:填写DS160表格(网址https://ceac ...

  10. 【前端】window.resize的优化

    一.概述 window.resize事件会在窗口尺寸改变的时候触发,哪怕只是改变了1像素.所以当窗口进行拖动的时候会触发很多次,很容易就卡死. 虽然部分浏览器已经进行了一点优化,但这还不够. 二.优化 ...