HDU1789(Doing Homework again)题解

以防万一,题目原文和链接均附在文末。那么先是题目分析:

【一句话题意】

给定任务分数和其截止日期,每日可完成一任务,输出当罚分尽可能小时的最小罚分。

【题目分析】

由于写的时候就知道是贪心了(专项练习= =||),所以要设计贪心策略,但是应该先处理数据以便使用。
由于要求罚分尽可能小,那么我们就根据罚分来排序。根据罚分从大到小排序,如果罚分相同则根据日期从小到大排序。(现在想想觉得似乎日期排不排都行。。)
那么我们的贪心策略应该尽可能保证分数高的作业完成。于是我们从排好的序列依次访问,并根据其作业指定的截止日期来决定这个作业啥时候写就行了。
如果出现该日已经安排有作业了,那么只需要让这次作业提前一天写就是了。如果还是有之前安排的作业,就再提前一天。如果全满了,那么这项作业可以扔掉了。由于之前排序是根据作业分数多少排序的,所以如果这项作业被扔掉了,那么这项作业的分数一定是很低的。符合舍弃目的。

【算法流程】

结构体:

“作业”结构具有的属性为

  • 截止时间;
  • 作业权重;
  • 标记;//标记则做此作业

贪心策略:

我们先按照作业的分数来进行排序,
权重处理后根据作业时间进行处理
如果该日已有作业,则该作业提前一天写

 #include <iostream>
#include <stdio.h>
#include <algorithm> using namespace std; typedef struct SubjectType{
int deadline;
int mark;
bool isSelected;
} subject; bool cmp(SubjectType a,SubjectType b){
if (a.mark != b.mark) return a.mark > b.mark;
return a.deadline < b.deadline;
} int main()
{
int dataCount,subjectCount;
int i,j,k,flag[];//flag用以标记该日要做的作业编号 ,0为最远天数
subject arr[];
scanf("%d",&dataCount);
while(dataCount--){
memset(flag,,sizeof(flag));
scanf("%d",&subjectCount);
arr[].deadline = ;
arr[].mark = ;
arr[].isSelected = false;
for(i = ;i<=subjectCount;i++){
scanf("%d",&arr[i].deadline);
if (arr[i].deadline>flag[])
flag[] = arr[i].deadline;
}
for(i = ;i<=subjectCount;i++){
scanf("%d",&arr[i].mark);
arr[i].isSelected = false;
}
sort(arr+,arr+subjectCount+,cmp);
for(i = ;i<=subjectCount;i++){
j = arr[i].deadline;
while(j>=){
if (flag[j] != ) j--;
else break;
}
if (j == ) continue;
flag[j] = i;
}
for(i = ;i<=flag[];i++){
arr[flag[i]].isSelected = true;
}
int sum;
sum = ;
for(i = ;i<=subjectCount;i++){
if (!arr[i].isSelected)
sum+= arr[i].mark;
}
//for(i = 1;i<=flag[0];i++)printf("%d_",flag[i]);
printf("%d\n",sum);
}
return ;
}
/*
TestData(IN)
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
TestData(OUT)
0
3
5
*/

这里是附带的题目信息:

题目链接:(HDU 1789)Doing Homework again
题目属性:贪心(当然,也可以用dp写)
相关题目:1009、1045、1049、1050、1051、1052、1257、1800、2037、2111、2124、2187、2391、2570
题目原文:
【Desc】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.
【In】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.
【Out】For each test case, you should output the smallest total reduced score, one line per test case.
【SampIn/Out】参见代码下方的注释。

HDU1789(Doing Homework again)题解的更多相关文章

  1. HDU1789 Doing Homework again 【贪心】

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

  2. 解题报告 HDU1789 Doing Homework again

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

  3. 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 ...

  4. HDU1789 Doing Homework again 做作业【贪心】

    题目链接:https://vjudge.net/problem/HDU-1789 题目大意: 给出N个作业的截至日期,和N个作业不交所扣掉的分数,要求输出扣除分数做少的方案. 解析: 与上一道销售商品 ...

  5. hdu1789 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 贪心问题 有时间限制的最小化惩罚问题

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

  7. HDU1789 Doing Homework again

    基础单调队列: #include<cstdio> #include<cstdlib> #include<iostream> #include<algorith ...

  8. hdu1789 Doing Homework again---(经典贪心)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1789 题目大意: 给出N个作业的截至日期,和N个作业不交所扣掉的分数,要求输出扣除分数做少的方案. ...

  9. HDU 6343.Problem L. Graph Theory Homework-数学 (2018 Multi-University Training Contest 4 1012)

    6343.Problem L. Graph Theory Homework 官方题解: 一篇写的很好的博客: HDU 6343 - Problem L. Graph Theory Homework - ...

随机推荐

  1. linux重要的标准目录和文件

    linux重要的标准目录和文件 / 根目录,所有其他文件在根文件系统的子目录下 /bin 基本命令的二进制文件,存放linux下常用的命令和工具 /boot 引导加载器的固有文件,linux就是从这里 ...

  2. (ZZ)WPF经典编程模式-MVVM示例讲解

    http://www.cnblogs.com/xjxz/archive/2012/11/14/WPF.html 本篇从两个方面来讨论MVVM模式: MVVM理论知识 MVVM示例讲解 一,MVVM理论 ...

  3. Floyd算法(弗洛伊德算法)

    算法描述: Floyd算法又称为弗洛伊德算法,插点法,是一种用于寻找给定的加权图中顶点间最短路径的算法.从图的带权邻接矩阵A=[a(i,j)] n×n开始,递归地进行n次更新,即由矩阵D(0)=A,按 ...

  4. AngularJS路由和模板

    前言 如果想开发一款类似gmail的web应用,我们怎么做呢? 以jQuery的思路,做响应式的架构设计时,我们要监听所有点击事件,通过事件函数触发我们加载数据,提交,弹框,验证等的功能:以 Angu ...

  5. CSS display:table属性用法- 轻松实现了三栏等高布局

    display:table:此元素会作为块级表格来显示(类似 <table>); display:table-cell属性指让标签元素以表格单元格的形式呈现,类似于td标签.目前IE8+以 ...

  6. Scrapy:python3下的第一次运行测试

    1,引言 <Scrapy的架构初探>一文讲解了Scrapy的架构,本文就实际来安装运行一下Scrapy爬虫.本文以官网的tutorial作为例子,完整的代码可以在github上下载. 2, ...

  7. QT Creator 2.7.2 代码自动补全快捷键设置

    在QT Creater界面点[工具]再进[选项]找到[环境]下的[键盘]选项,搜索[CompleteThis]发现默认快捷键就是CTRL+SPACE,把它删除,然后添加自己想设置的快捷键(因为之前用e ...

  8. Delphi 常用API 函数(好多都没见过)

    AdjustWindowRect 给定一种窗口样式,计算获得目标客户区矩形所需的窗口大小AnyPopup 判断屏幕上是否存在任何弹出式窗口ArrangeIconicWindows 排列一个父窗口的最小 ...

  9. lsof查看进程打开了哪些文件目录套接字

    lsof查看进程打开了哪些文件目录套接字

  10. relay 2015-02-05 21:00 27人阅读 评论(0) 收藏

    scanf函数是以在输入多个数值数据时,若格式控制串中没有非格式字符作输入数据之间的间隔,则可用空格,TAB或回车作间隔. C编译在碰到空格,TAB,回车或非法数据(如对"%d"输 ...