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

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

做作业,每门作业都有规定的期限和分值,每天只能做一门,如果不能在规定时间内做完,就会扣相应的分数,问最少扣多少分。

可以先按期限从小到大排序,如果期限相同就按分值从大到小排。排完序之后从第一天开始一门门做过去,还有一个要注意的问题就是如果有两门课的作业期限相同,分值都很高,而因为时间问题只能做其中一门,但在他们前面有一门课的分值比较低,那么就不要做那门分值低的,而改做这两门分值高的

代码实现就是每遇到这样的情况就去前面找有没有分值比较低的,而且没有被扣过分的(扣过分的会标记)

 #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(贪心+排序)的更多相关文章

  1. HDU-1789 Doing Homework again 贪心问题 有时间限制的最小化惩罚问题

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

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

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

  3. HDU1789 Doing Homework again 【贪心】

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

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

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

  5. HDU 1789 Doing Homework again(贪心)

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

  6. hdu--1798--Doing Homework again(贪心)

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

  7. HDU 1789 - Doing Homework again - [贪心+优先队列]

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

  8. HDOJ.1789 Doing Homework again (贪心)

    Doing Homework again 点我挑战题目 题意分析 给出n组数据,每组数据中有每份作业的deadline和score,如果不能按期完成,则要扣相应score,求每组数据最少扣除的scor ...

  9. HDU_1789_doing homework again_贪心

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

随机推荐

  1. 十三、IntelliJ IDEA 中的版本控制介绍(下)

    我们已经简单了解了 IntelliJ IDEA 的版本控制机制,那么接下来,就让我们一起看看在 IntelliJ IDEA 中进行具体的版本控制操作. 标注1:Checkout from Versio ...

  2. GoldenGate -- OGG EXTRACT进程 OGG-00446 报错

    -- :: INFO OGG- Positioning to (Thread ) Sequence , RBA , SCN 0.470706262. Source Context : SourceMo ...

  3. Vue--- vue-cli 脚手架 安装 -reeber

    vue-cli 脚手架 安装   一. node安装 1)如果不确定自己是否安装了node,可以在命令行工具内执行: node -v  (检查一下 版本): 2)如果 执行结果显示: xx 不是内部命 ...

  4. vue项目出现空格警告的原因及其解决办法

    原因: 因为你的Webpack 配置中大概是使用了 eslint-loader,这是用来规范代码风格的,在多人协作或大项目中推荐使用,不想要则可以在 webpack.config.js 中去掉.esl ...

  5. input 输入的一些限制说明

    input输入框 只能输入 数字可以有小数点 <input class="form_text" id="purchasePrice" name=" ...

  6. 《MySQL必知必会》--使用cmd登陆数据库

    数据库:保存有组织的数据的容器(通常是一个文件或一组文件). 表:某种特定类型数据的结构化清单. 模式:关于数据库和表的布局及特性的信息. 列:表中的一个字段.所有表都是由一个或多个列组成的. 数据类 ...

  7. ElasticSearch : APT-GET安装方式

    Ubuntu下安装ES 新建非ROOT管理员用户 安装和配置JDK 打开下面的地址 https://www.elastic.co/guide/en/elasticsearch/reference/cu ...

  8. 搭建Jupyter Notebook服务器

    昨天发了Jupyter的使用,补一篇Jupyter服务器的搭建~ 一.搭建Jupyter 1.安装 使用virtualenv建虚拟环境.在虚拟环境中安装jupyter.matplotlib等等需要的库 ...

  9. Waltz of love

    Waltz of love Love me tenderly Love me softly Close your eyes,fling to the dangcing hall Follow your ...

  10. 『Linux基础 - 1』计算机基础概念

    这篇笔记的知识点结构目录: 认识计算机: (1)什么是计算机; (2)计算机的发展过程 计算机的构成: (1) 计算机硬件系统; (2) 计算机软件系统 二进制: (1) 为什么用二进制 (2) 二进 ...