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. webstorm 2016

    2017.2.27更新 选择“license server” 输入:http://idea.imsxm.com/ 2016.2.2 版本的破解方式: 安装以后,打开软件会弹出一个对话框:选择“lice ...

  2. python列表和分片

    列表的分片 str = " print("打印第0个元素:" ,str[0]) print("负数表示倒数第N个元素,-1表示倒数第一个元素:" ,s ...

  3. vscode 使用笔记

    https://code.visualstudio.com/docs/setup/setup-overview#_proxy-server-support 如果使用代理上网时,需要配置:   在 se ...

  4. 部署web Service到tomcat

    建立项目 打开jdeveloper 12c,然后新建一个java项目,点击java,生成web services. package simple; import javax.jws.WebMethod ...

  5. Coherence的集群成员的离开和加入机制研究

    最近在客户那里环境中coherence集群不稳定,所以找出一些文档,需要搞清楚Coherence内部的一些机制 1.集群成员的离开 关于状态的检测,官方的说法是: Death detection is ...

  6. Objective-C:运行时runtime

    1.是否可以把比较耗时的操作放在通知中心中?   通知在哪一个线程发的,那么对通知事件的处理就在同一个线程中进行; 如果在异步线程发的通知,那么可以执行比较耗时的操作: 如果在主线程发的通知,那么就不 ...

  7. 50行代码实现缓存,JAVA内存模型原理

    遇见这样的高人怎么办??下面是一个简单缓存的实现,相当牛叉!自己看吧,只有50行代码. 摘自:http://www.oschina.net/code/snippet_55577_3887 import ...

  8. Tempter of the Bone——DFS(王道)

    Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...

  9. gensim加载word2vec训练结果(bin文件)并进行相似度实验

    # -*- coding: utf-8 -*- import gensim # 导入模型 model = gensim.models.KeyedVectors.load_word2vec_format ...

  10. Python——Socket 编程教程

    这是用来快速学习 Python Socket 套接字编程的指南和教程.Python 的 Socket 编程跟 C 语言很像. Python 官方关于 Socket 的函数请看 http://docs. ...