hdu1789 Doing Homework again(贪心+排序)
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 18294 Accepted Submission(s): 10648
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.
做作业,每门作业都有规定的期限和分值,每天只能做一门,如果不能在规定时间内做完,就会扣相应的分数,问最少扣多少分。
可以先按期限从小到大排序,如果期限相同就按分值从大到小排。排完序之后从第一天开始一门门做过去,还有一个要注意的问题就是如果有两门课的作业期限相同,分值都很高,而因为时间问题只能做其中一门,但在他们前面有一门课的分值比较低,那么就不要做那门分值低的,而改做这两门分值高的
代码实现就是每遇到这样的情况就去前面找有没有分值比较低的,而且没有被扣过分的(扣过分的会标记)
#include<bits/stdc++.h>
using namespace std;
struct node
{
int day,score;
int flag;
} a[];
bool cmp(node x,node y)
{
if(x.day==y.day)
{
return x.score>y.score;
}
else
{
return x.day<y.day;
}
}
void init()
{
for(int i=; i<; i++)
{
a[i].day=;
a[i].score=;a[i].flag=;
}
}
int main()
{
int t;
while(~scanf("%d",&t))
{
while(t--)
{
int n;
scanf("%d",&n);
init();
for(int i=;i<n;i++)
{
scanf("%d",&a[i].day);
}
for(int i=;i<n;i++)
{
scanf("%d",&a[i].score);
}
sort(a,a+n,cmp);
int temp=,ans=;
for(int i=;i<n;i++)
{
if(a[i].day>=temp)
{
temp++;
continue;
}
int p=a[i].score,pos=i;
for(int j=;j<i;j++)
{
if(a[j].score<p&&a[j].flag)//前面有耗时少的,而且没有扣过分
{
p=a[j].score;
pos=j;
}
}
ans+=p;
a[pos].flag=;//扣分标记
}
printf("%d\n",ans);
}
}
return ;
}
hdu1789 Doing Homework again(贪心+排序)的更多相关文章
- HDU-1789 Doing Homework again 贪心问题 有时间限制的最小化惩罚问题
题目链接:https://cn.vjudge.net/problem/HDU-1789 题意 小明有一大堆作业没写,且做一个作业就要花一天时间 给出所有作业的时间限制,和不写作业后要扣的分数 问如何安 ...
- HDU1789 Doing Homework again 做作业【贪心】
题目链接:https://vjudge.net/problem/HDU-1789 题目大意: 给出N个作业的截至日期,和N个作业不交所扣掉的分数,要求输出扣除分数做少的方案. 解析: 与上一道销售商品 ...
- HDU1789 Doing Homework again 【贪心】
Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu1789 Doing Homework again---(经典贪心)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1789 题目大意: 给出N个作业的截至日期,和N个作业不交所扣掉的分数,要求输出扣除分数做少的方案. ...
- HDU 1789 Doing Homework again(贪心)
Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...
- hdu--1798--Doing Homework again(贪心)
Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 1789 - Doing Homework again - [贪心+优先队列]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...
- HDOJ.1789 Doing Homework again (贪心)
Doing Homework again 点我挑战题目 题意分析 给出n组数据,每组数据中有每份作业的deadline和score,如果不能按期完成,则要扣相应score,求每组数据最少扣除的scor ...
- HDU_1789_doing homework again_贪心
Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
随机推荐
- PHP中使用substr()截取字符串出现中文乱码问题该怎么办
一.使用mbstring扩展库的mb_substr()截取就不会出现乱码了. 可以用mb_substr()/mb_strcut()这个函数,mb_substr()/mb_strcut()的用法与sub ...
- Python常用库之一:Numpy
Numpy支持大量的维度数组和矩阵运算,对数组运算提供了大量的数学函数库! Numpy比Python列表更具优势,其中一个优势便是速度.在对大型数组执行操作时,Numpy的速度比Python列表的速度 ...
- springmvc(3)注解
有疑问可以参考博主其他关于spring mvc的博文 此时直接进行代码的实现 一般的步骤: -加入jar包 -配置DispatcherServlet -加入Spring MVC配置文件 -编写请求的处 ...
- 2019.1.4 SSH框架整合步骤(一)
SSH整合 1.三大框架整合原理 Spring与Struts2整合就是将Action对象交给Spring容器负责创建 Spring与Hibernate整合就是将sessionFactory交给Spri ...
- 四. 引入unittest单元测试框架
1. 安装 SeleniumIDE(firefox) (1)下载地址:https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/ (2 ...
- PX4地面站QGroundControl在ubuntu下的安装
1.引言 相信很多玩开源无人机的朋友手上都有一架无人机,而不是仅仅停留在理论的学习和程序的学习.放飞自己组装的无人机才是乐趣所在,那么这本文就介绍玩无人机必不可少的地面站软件qgroundcontro ...
- 微信小程序 | 未来O2O电商的“阴谋”
发展历史 2016年1月11日,微信之父张小龙时隔多年的公开亮相,提出了公众号服务的短板,而透露微信内部正在研发的新形态工具,称之"微信小程序". 2016年9月21日,微信小程序 ...
- hdu_5698_瞬间移动
有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右下方格子,并瞬移过去(如从下图中的红色格子能直接瞬移到蓝色格子),求到第nn行第mm列的格子有几种方案,答案对100000 ...
- Redis服务端和客户端的命令
服务器端 服务器端的命令为redis-server 可以使⽤help查看帮助⽂档 redis-server --help 个人习惯 ps aux | grep redis 查看redis服务器进程su ...
- 跨浏览器实现placeholder效果的jQuery插件
曾经遇到这样一个问题,处理IE8密码框placeholder属性兼容性.几经周折,这个方案是可以解决问题的. 1.jsp页面引入js插件 <script type="text/java ...