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. 【转】android 常用theme

    android:theme="@android:style/Theme.Dialog" : Activity显示为对话框模式android:theme="@android ...

  2. Fidder学习基础(二)

    一. 巧用代理抓包. 首页,需设置Tools——>Fiddler Options——>Connectons,维护代理端口及允许其他设备连接. 这里,需要注意的是端口配置不能重复,抓包代理设 ...

  3. async--ajax异步传输

    如图:轨迹点组编号依赖所属路口的设置. 所以ajax是异步执行,获取到所属路口还没执行完,就已经执行到根据所述路口获取轨迹点组编号,所以获取不到轨迹点组编号. async:false改成同步执行.就没 ...

  4. sql获取时间、年龄

      mysql数据库获取年龄:TIMESTAMPDIFF(YEAR, [出生日期字段], CURDATE()) select * from (select name 姓名,TIMESTAMPDIFF( ...

  5. HDU 1028 Ignatius and the Princess III 整数的划分问题(打表或者记忆化搜索)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1028 Ignatius and the Princess III Time Limit: 2000/1 ...

  6. 1.Redis介绍以及安装

    Redis介绍 Redis是一个开源的(BSD开源协议),内存数据结构存储,被用于作为数据库,缓存和消息代理. Redis支持如下数据结构: string(字符串) hashes(哈希) lists ...

  7. Java并发包:AtomicBoolean和AtomicReference

      AtomicBoolean AtomicBoolean是一个读和写都是原子性的boolean类型的变量.这里包含高级的原子操作,例如compareAndSet().AtomicBoolean位于J ...

  8. CF1066D Boxes Packing(二分答案)

    题意描述: 你有$n$个物品,每个物品大小为$a_i$,$m$个盒子,每个盒子的容积为$k$.$Maksim$先生想把物品装入盒子中.对于每个物品,如果能被放入当前的盒子中,则放入当前盒子,否则换一个 ...

  9. keepalived+haproxy 安装配置

    1.安装配置keepalived 修改配置文件/etc/keepalived/keepalived.conf ! Configuration File for keepalived global_de ...

  10. ruby中的respond to ?用法

    今天写脚本,遇到了这个函数,遂搜索及阅读相关代码,整理如下: respond_to 是判断是否是某个类型的方法,比如: ar = "ss" p ar.respond_to?(:to ...