Doing Homework again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 6833    Accepted Submission(s): 4070

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<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int str[1010]; //用来标记该天是否占用,刚開始都未使用标记0,用过则标记1。
struct st
{
int time,fen;
}data[1010];
int cmp(st a,st b) //科目按扣分从高到低排序。假设扣分同样。则科目期限短的考前。
{
if(a.fen!=b.fen)
return a.fen>b.fen;
else
return a.time<b.time;
}
int main()
{
int i,j,T,n;
scanf("%d",&T);
while(T--)
{
memset(str,0,sizeof(str));
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&data[i].time);
}
for(i=0;i<n;i++)
{
scanf("%d",&data[i].fen);
}
sort(data,data+n,cmp);
int sum=0;
for(i=0;i<n;i++)
{
j=data[i].time;
while(j) //将扣分多的科目优先放到期限的最后一天完毕。 {
if(!str[j]) //假设那天未被占用,占用那天。跳出while循环,再考虑扣分次多的那个科目。
{
str[j]=1;
break;
}
j--; // 假设那天已经被占用,考虑前一天是否被占用。
}
if(j==0)
sum+=data[i].fen; //假设在期限之内的全部天数均已经被占用。则不得不扣分。 }
printf("%d\n",sum);
}
return 0;
}


Doing Homework again(杭电1789)的更多相关文章

  1. 杭电 1789 Doing Homework again (贪心 求最少扣分)

    Description zichen has just come back school from the 30th ACM/ ICPC. Now he has a lot of homework t ...

  2. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  3. 杭电dp题集,附链接还有解题报告!!!!!

    Robberies 点击打开链接 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱  最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f ...

  4. 杭电ACM题单

    杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...

  5. 杭电acm习题分类

    专注于C语言编程 C Programming Practice Problems (Programming Challenges) 杭电ACM题目分类 基础题:1000.1001.1004.1005. ...

  6. 杭电OJ1789、南阳OJ236(贪心法)解题报告

    杭电OJ1789http://acm.hdu.edu.cn/showproblem.php?pid=1789 南阳OJ236http://59.69.128.203/JudgeOnline/probl ...

  7. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  8. 杭电acm 1002 大数模板(一)

    从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...

  9. 杭电OJ——1198 Farm Irrigation (并查集)

    畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...

随机推荐

  1. display:block什么时候使用

    所有的块级元素不需要再在使用display:block定义,块级元素本身的默认属性就是block display:block:比较常用于<a><span>这两个标签,因为他们不 ...

  2. Github上的iOS资料-个人记录

    动画 awesome-ios-animation收集了iOS平台下比较主流炫酷的几款动画框架 RCTRefreshControlqq的下拉刷新 TBIconTransitionKiticon 的点击动 ...

  3. FindFirstVolume系列函数遍历驱动器,获取驱动器信息

    什么是“卷”?卷,又称为“逻辑驱动器”,是 NTFS, FAT32 等文件系统组织结构的最高层.卷是存储设备(如硬盘)上由文件系统管理的一块区域,是在逻辑上相互隔离的存储单元.一个磁盘分区至少包含一个 ...

  4. 使用apt-cache search搜索想要的软件包

    环境: Ubuntu14.10 我在编译u-boot代码的时候遇到了如下问题: LD test/dm/built-in.o CC examples/standalone/stubs.o LD exam ...

  5. spring+activity+mysql集群

     第一步:先配置好第一个activityMQ 在broker外面加入数据库的连接信息,并将mysql的mysql-connector-java.jar,即java连接mysql的jar包放入apach ...

  6. android线程及线程池

    众所周知,在UI系统中进行一些耗时操作,都会导致卡顿现象,因为一次刷新在16ms,如果当次操作过了这个时间,那么用户就能感觉到明显的卡顿,甚至引起ANR . 对于这种情况,一般都是再起一个线程,进行一 ...

  7. solr File Upload "Unsupported ContentType: application/vnd.ms-excel Not in: [application/xml, application/csv, application/json, text/json, text/csv, text/xml, application/javabin]",

    今天在用solr管理界面导入文件时报错:"Unsupported ContentType: application/vnd.ms-excel  Not in: [application/xm ...

  8. RocketMQ的异步调用

    这个异步调用方法中传入一个final 回调对象. public void invokeAsyncImpl(final Channel channel, final RemotingCommand re ...

  9. [GraphQL] Filter Data Based on Query Arguments with GraphQL

    With GraphQL, every field and nested object can have a set of arguments which can be used to request ...

  10. Mac机装Win7后 启动只见鼠标怎么办

    我有一台Mac机,用Bootcamp的方式装了Win7,昨天一按开机键发现只有鼠标没有别的. 当时按热启动无效,把笔记本盖子合上一会再开也无效,按关机键关掉再开也无效(这时是短按). 当时想是不是Ma ...