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. gentoo下的wpa_supplicant无线网配置

    在linux使用wpa_supplicant获得无线网的最痛苦的是莫过于去配置wpa_supplicant.conf文件了(当然对于linux老手这不算什么), 但是可以用一种简便的方法直接输入命令行 ...

  2. MySQL - “Timeout error occurred trying to start MySQL Daemon”解决方法

    前几天,网站出现Many connections的问题,进入mysql,show full processlist发现有154个进程,晕....直接service mysqld restart 但是不 ...

  3. Python正则表达式Regular Expression基本用法

    资料来源:http://blog.csdn.net/whycadi/article/details/2011046   直接从网上资料转载过来,作为自己的参考.这个写的很清楚.先拿来看看. 1.正则表 ...

  4. osg(OpenSceneGraph)学习笔记1:智能指针osg::ref_ptr<>

    OSG的智能指针,osg::ref_ptr<> osg::Referenced类管理引用计数内存块,osg::ref_ptr需要使用以它为基类的其它类作为模板参数. osg::ref_pt ...

  5. POJ 1472 Instant Complexity 应该叫它编程题。。

    题目:http://poj.org/problem?id=1472 这个题目是分到“模拟题”一类的,我觉得模拟的成分比较少,主要考察编程能力.独立写完这个题特别兴奋...所以我必须好好说一说,独家哦. ...

  6. iOS Copy 和 MutableCopy的区别 深浅拷贝的区别-供参考

    概述 对于系统的非容器类对象,对一不可变对象复制,copy是指针复制(浅拷贝)和mutableCopy就是对象复制(深拷贝).如果是对可变对象复制,都是深拷贝,但是copy返回的对象是不可变的. 对于 ...

  7. 这是从word发的第一篇博客。

    喜欢做的事,怎么样都不会厌倦. 以前只知道office功能强大,但不太清楚到底还能干些啥,印象最深的是outlook了,自己也在用,挺好 今天偶然发现,word还能发布博客,真是太惊喜了 这算是一篇实 ...

  8. Apache httpd.conf的翻译

    本人初学,15年暑假翻译了一些,前几天翻译完,有机器翻译,也有自己翻译的内容,不准确之处请指出. --------------------------------------------------- ...

  9. Linq Distinct List 去重复

    //调用 return producePlantlst.Distinct(new item_collection_DistinctBy_item1()).ToList(); //方法 public c ...

  10. Jrtplib

    RTP/RTCP 视频数据传输 (续) http://blog.csdn.net/neohuo/article/details/821442