Doing Homework again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8638    Accepted Submission(s):
5090

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
先对分数从大到小排序 然后设出一个数组vis[]来按照分数从高到低记录必须占用的日期如果有空闲的日期
则标记为1 若没有空闲的日期则舍弃这个分数
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct record
{
int day;
int score;
}num[1100];
bool cmp(record a,record b)
{
if(a.score!=b.score)
return a.score>b.score;
else
return a.day<b.day;
}
int main()
{
int n,m,j,i,t,l,sum;
int vis[1100];//用来储存必须要占用的日期
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
memset(vis,0,sizeof(vis));
for(i=0;i<n;i++)
scanf("%d",&num[i].day);
for(i=0;i<n;i++)
scanf("%d",&num[i].score);
sort(num,num+n,cmp);
sum=0;
for(i=0;i<n;i++)
{
for(j=num[i].day;j>=1;j--)
{
if(vis[j]==0)
{
vis[j]=1;
break;
}
}
if(j==0)
sum+=num[i].score;
}
printf("%d\n",sum);
}
return 0;
}

  

hdoj 1789 Doing Homework again的更多相关文章

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

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

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

  3. hdu 1789 Doing HomeWork Again (贪心算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 /*Doing Homework again Time Limit: 1000/1000 MS ...

  4. HDU 1789 Doing Homework again (贪心)

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

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

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

  6. HDU 1789 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 Problem Description Ignatius has just come back ...

  8. HDU 1789 Doing Homework again(贪心)

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

  9. HDU 1789 Doing Homework again(贪心)

    在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...

随机推荐

  1. Boost.Build 简明教程

    Boost.Build 简明教程 目录1. 介绍2. 构建过程3. 基本任务4. 项目管理5. 最佳实践6. 规则参考7. 特征参考 介绍 编译器和平台无关编译系统Boost.Build是一个高级编译 ...

  2. uboot的mkconfig分析

    uboot的mkconfig是一个shell脚本.对于笔者这种Linux学习初学者,不太可能认真的把shell脚本学习一遍.但是,倘若不能理解mkconfig的含义,又很难从整体的理解uboot(我认 ...

  3. Servlet+Tomcat制作出第一个运行在Tomcat上的Java应用程序

    转载自:http://www.linuxidc.com/Linux/2011-08/41685.htm [日期:2011-08-27] 来源:csdn  作者:Cloudyxuq     1.IDE工 ...

  4. 查看sqlserver数据库的端口号

    最近正在用sqlserver作为java的数据库进行开发,在写连接字符串的时候,想起一个问题,怎么查找sqlserver的端口号呢?有两种方法 1,用存储过程 --查询端口号exec sys.sp_r ...

  5. Apple 公司开发者账号注册

    苹果公司开发者账号注册流程详解   这段时间在给朋友申请苹果账号,从个人开发者账号.公司账号到企业账号,申请了个遍.这里对申请流程做一下介绍,方便其他朋友,少走弯路,账号早日申请通过. 1.首先介绍下 ...

  6. C语言中返回字符串函数的四种实现方法

    转自C语言中返回字符串函数的四种实现方法 其实就是要返回一个有效的指针,尾部变量退出后就无效了. 有四种方式: 1.使用堆空间,返回申请的堆地址,注意释放 2.函数参数传递指针,返回该指针 3.返回函 ...

  7. 分析ECMall的注册与登录机制

    ecmall的注册流程index.php?app=member&act=register. 首先app是member,act是register方法. index.php中.通过ecmall的s ...

  8. OneAPM Cloud Test——系统性能监控神器

    2015 年 8 月,OneAPM 推出了一款系统性能监控产品--Cloud Test,产品上线以来以「两低一高」的特点迅速成为市场增长率最快的一匹黑马.「两低一高」,即低使用成本.低学习成本以及高服 ...

  9. JavaSE 国际化 简单例子

    ①在src下添加两个文件: base_zh_CN.properties Test=\u8fd9\u662f\u4e2d\u6587 base_en_US.properties Test=english ...

  10. 【HDU 4276】The Ghost Blows Light(树形DP,依赖背包)

    The Ghost Blows Light Problem Description My name is Hu Bayi, robing an ancient tomb in Tibet. The t ...