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. FCL研究-LINQ-System.Linq Enumerable

    .net 里面集合操作极为方便,尤其是实现了IEnumerable接口的集合,一直在使用,系统的研究一下集合的操作也是极好的. 类型 操作符名称 投影操作符 Select,SelectMany 限制操 ...

  2. mysql-启动、关闭与重启

    启动 service mysqld start mysql.server start 停止 service mysqld stop mysql.server stop 重启 mysql.server ...

  3. Linux下使用Shell过滤重复文本(转)

    ffffffffffffffffff ffffffffffffffffff eeeeeeeeeeeeeeeeeeee fffffffffffffffffff eeeeeeeeeeeeeeeeeeee ...

  4. cssz中<a>标签鼠标选中去除选中边框

    IE: <a href="#" hidefocus="true"></a> 非IE: a:focus { outline:none; } ...

  5. microsoft sql server - online Resources 在线资源

  6. Debian6 安装Kscope(也适用于Ubuntu)

    参考:http://soft.chinabyte.com/os/134/12307634.shtml kscope1.6.2在这里下载,下载后解压出kscope-1.6.2.tar.gz. 在ubun ...

  7. 下载谷歌浏览器(Chrome)扩展离线安装包crx文件最简单的方法

    转:http://alyzq.com/?p=627 如果不会使用,请看下面的操作步骤 引言(可以不看): 下面介绍一下,下载谷歌浏览器(Google Chrome)扩展的离线安装包crx文件最简单的方 ...

  8. Scut游戏服务器免费开源框架--快速开发(3)

    Scut快速开发(3) 1     开发环境 Scut Lib版本:5.2.3.2 需要安装的软件 a)        IIS和消息队列(MSMQ) b)        数据库,Sql2005以上版本 ...

  9. php简单常用的API

    1.var_dump($x),查看数据类型,以及数据 var_dump($x); //string(12) "就是就是" 2.memory_get_usage()到当前这一步为止一 ...

  10. ubuntu16.04给普通用戸提成root权限,会出现造成重启系统,没有登录用户

    一.导致问题的原因 直接修改配置文件提权,会造成重启系统后没有原来的登录用户 vim /etc/passwd nulige:x:0:0:nulige,,,:/home/gree:/bin/bash 解 ...