Doing Homework again

点我挑战题目

题意分析

给出n组数据,每组数据中有每份作业的deadline和score,如果不能按期完成,则要扣相应score,求每组数据最少扣除的score是多少。

典型的贪心策略。

既然是要求最少的扣分,那么肯定是要先完成分数最多的。所以可以推出按照分数排序。那么最佳策略应该是在deadline当天完成作业,如果那天已经占用,只能在deadline-1天完成,如果那天也被占用了,就只能在deadline-2天完成……直到推到第1天,如果还被占用的话,那么这个作业肯定是完不成了,扣除相应分数。遍历完数据,判断有哪些作业没有完成,输出其分数之和即可。

代码总览

/*
Title: HDOJ.1789
Author: pengwill
Date:2016-11-22
*/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
struct hw{
int dline;
int score;
bool fish;
}item[1005];
bool judge[1005];
int cmp(hw a, hw b)
{
return a.score > b.score;
}
int main()
{
int n;
scanf("%d",&n);
while(n--){
memset(judge,0,sizeof(judge));
memset(item,0,sizeof(item));
int i,t,j;
scanf("%d",&t);
for(i = 0;i<t;i++){
scanf("%d",&item[i].dline);
}
for(i = 0;i<t;i++){
scanf("%d",&item[i].score);
item[i].fish = false;
}
sort(item,item+t,cmp);
for(i = 0;i<t;i++){
for(j = item[i].dline;j>=1;j--){
if(!judge[j]){
judge[j] = true;
item[i].fish = true;
break;
}
}
}
int ret = 0;
for(i = 0;i<t;i++){
if(item[i].fish == false){
ret += item[i].score;
}
}
printf("%d\n",ret);
}
return 0;
}

HDOJ.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 - [贪心+优先队列]

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

  3. HDU 1789 Doing Homework again(贪心)

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

  4. Hdoj 1789 Doing Homework again 题解

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

  5. hdoj 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 (Greedy)

    Problem - 1789 继续贪心.经典贪心算法,如果数据比较大就要用线段树来维护了. 思路很简单,只要按照代价由大到小排序,然后靠后插入即可.RE了一次,是没想到deadline可以很大.如果d ...

  7. HDU 1789 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(贪心)

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

  9. HDU 1789 Doing Homework again (贪心)

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

随机推荐

  1. 『Python Kivy』API说明:kivy.app.App

    App类是创建Kivy应用的基础.我们可以将其看成是Kivy运行循环当中的主入口.在绝大多数的例子中,你创建这个类的子类,然后构建你自己的应用.当你已经准备好开始应用的整个生命周期时,你可以实例化你定 ...

  2. ElasticSearch-Java-low-level-rest-client官方文档翻译

    人肉翻译,非谷歌机翻,部分地方添加了个人的理解,并做了分割,如有错误请在评论指出.转载请指明原链接,尊重个人劳动成果.        High-Level-Rest-Client基于Low-Level ...

  3. Objective-C 构造方法 分类 类的深入研究

    构造方法 1.对象创建的原理 new的拆分两部曲 Person *p = [Person alloc]; 分配内存(+alloc) Person *p = [p init]; 初始化(-init) 合 ...

  4. TPO-15 C1 The campus newspaper's reporter position

    TPO-15 C1 The campus newspaper's reporter position 第 1 段 1.Listen to a conversation between a Studen ...

  5. <cerrno>

    文件头名称: <cerrno>(errno.h) 文件头描述: 文件内定义了如下的宏  errno 最后一个错误代码 加上其他至少的三个宏常量:EDOM,ERANGE 和EILSEQ 宏定 ...

  6. 互联网行业求职课-教你进入BAT

    互联网行业求职课--教你进入BAT 课时1. 课程内容介绍.导师介绍.服务安排和介绍等 课时2. 互联网行业.职业选择指导 互联网公司选择: 大公司:收获:大平台,系统思维,系统培训,系统性的发展,薪 ...

  7. 了解Python控制流语句——while 语句

    while 语句 Python 中 while 语句能够让你在条件为真的前提下重复执行某块语句. while 语句是 循环(Looping) 语句的一种.while 语句同样可以拥有 else 子句作 ...

  8. DNA序列 (DNA Consensus String,ACM/ICPC Seoul 2006,UVa1368

    题目描述:算法竞赛入门经典习题3-7 题目思路:每列出现最多的距离即最短 #include <stdio.h> #include <string.h> int main(int ...

  9. LeetCode 145 ——二叉树的后序遍历

    1. 题目 2. 解答 2.1. 递归法 定义一个存放树中数据的向量 data,从根节点开始,如果节点不为空,那么 递归得到其左子树的数据向量 temp,将 temp 合并到 data 中去 递归得到 ...

  10. js随机数算法

    function rnd( seed ){ seed = ( seed * 9301 + 49297 ) % 233280; //为何使用这三个数? return seed / ( 233280.0 ...