题目:

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

题解:

贪心····直接按扣的分数从大到小排序··如果分数相等就按截止日期从小到大排序····然后从第一项作业开始枚举··每此从这项作业的截止日期往以前的天枚举··第一次枚举到的空闲天数作为这项作业的完成天数··然后打上标记即可··如果找不到空闲天数ans加上这项作业的扣分

代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
using namespace std;
const int N=;
struct node
{
int dl,re;
}hw[N];
int T,n;
inline int R()
{
char c;int f=;
for(c=getchar();c<''||c>'';c=getchar());
for(;c<=''&&c>='';c=getchar()) f=(f<<)+(f<<)+c-'';
return f;
}
inline bool cmp(node a,node b)
{
if(a.re==b.re) return a.dl<b.dl;
return a.re>b.re;
}
bool visit[];
int main()
{
// freopen("a.in","r",stdin);
T=R();
while(T--)
{
int ans=;
memset(visit,false,sizeof(visit));
n=R();
for(int i=;i<=n;i++) hw[i].dl=R();
for(int i=;i<=n;i++) hw[i].re=R();
sort(hw+,hw+n+,cmp);
for(int i=;i<=n;i++)
{
bool flag=false;
for(int j=hw[i].dl;j>=;j--)
if(!visit[j])
{
visit[j]=true,flag=true;break;
}
if(flag) continue;
else ans+=hw[i].re;
}
cout<<ans<<endl;
}
return ;
}

刷题总结——doing homework again(hdu1789)的更多相关文章

  1. LeetCode刷题系列

    LeetCode 我们工作面试和提高自身数据结构和算法能力的时候往往需要刷刷题,我选择LeetCode是通过一个留学论坛了解的.专业,覆盖语种全面. 提前说说刷题的心得: 尽量手写代码,少使用IDE的 ...

  2. ife任务刷题总结(一)-css reset与清除浮动

    本文同时发布于本人的个人网站www.yaoxiaowen.com 百度创办的前端技术学院,是一个面向大学生的前端技术学习平台.虽然只有大学生才有资格报名,提交代码进行比赛排名.但是这并不妨碍我们这些初 ...

  3. 刷题ING...

    我用codeVS刷题.. 努力准备!!

  4. XidianOJ 1020 ACMer去刷题吧

    题目描述 刷题是每个ACMer必由之路,已知某oj上有n个题目,第i个题目小X能做对的概率为Pi(0<=Pi<=1,1<=i<=n) 求小X至少做对k道题的概率 输入 第一行输 ...

  5. 【BZOJ-4590】自动刷题机 二分 + 判定

    4590: [Shoi2015]自动刷题机 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 156  Solved: 63[Submit][Status ...

  6. NOI题库分治算法刷题记录

    今天晚自习机房刷题,有一道题最终WA掉两组,极其不爽,晚上回家补完作业欣然搞定它,特意来写篇博文来记录下 (最想吐槽的是这个叫做分治的分类,里面的题目真的需要分治吗...) 先来说下分治法 分治法的设 ...

  7. NOI题库刷题日志 (贪心篇题解)

    这段时间在NOI题库上刷了刷题,来写点心得和题解 一.寻找平面上的极大点 2704:寻找平面上的极大点 总时间限制:  1000ms  内存限制:  65536kB 描述 在一个平面上,如果有两个点( ...

  8. 用js刷题的一些坑

    leecode可以用js刷题了,我大js越来越被认可了是吧.但是刷题中会因为忽略js的一些特性掉入坑里.我这里总结一下我掉过的坑. 坑1:js中数组对象是引用对象 js中除了object还有数组对象也 ...

  9. BZOJ4590 自动刷题机

    Description 曾经发明了信号增幅仪的发明家SHTSC又公开了他的新发明:自动刷题机--一种可以自动AC题目的神秘装置.自动 刷题机刷题的方式非常简单:首先会瞬间得出题目的正确做法,然后开始写 ...

随机推荐

  1. 爬虫1_python2

    # -*- coding: UTF-8 -*- # python2爬虫 import urllib f = urllib.urlopen("http://www.itcast.cn/&quo ...

  2. MFC多文档无法显示可停靠窗格

    当我们使用MFC多文档创建项目时,我们可停靠窗格关闭之后就无法显示了.即使重新编译项目也无法再次显示它们. 原因:因为MFC多文档把这些设置存储在注册表 “HKEY_CURRENT_USER \ SO ...

  3. docker单主机网络

    当你安装Docker时,它会自动创建三个网络.你可以使用以下docker network ls命令列出这些网络: [root@localhost ~]# docker network ls NETWO ...

  4. linux基本命令及使用方法

    shell环境: shell:命令解释器,是Linux 系统的用户界面,提供了用户与内核进行交互操作的一种接口,它接收用户输入的命令并把它送入内核去执行. bash:是GNU 计划中重要的工具软件之一 ...

  5. sessionStorage对象

    sessStorage对象是一个会话形式的数据存储,当用户关闭浏览器的窗口后,数据就会被删除. 实例: <!DOCTYPE html><html><head> &l ...

  6. PCA检测人脸的简单示例_matlab实现

    PCA检测人脸的简单示例,matlab R2009b上实现训练:训练用的20副人脸: %训练%Lx=X'*Xclear;clc;train_path='..\Data\TrainingSet\';ph ...

  7. Linux Ptrace 详解

    转 https://blog.csdn.net/u012417380/article/details/60470075 Linux Ptrace 详解 2017年03月05日 18:59:58 阅读数 ...

  8. WCF_基础学习

    1.https://www.cnblogs.com/swjian/p/8126202.html 2.https://www.cnblogs.com/dotnet261010/p/7407444.htm ...

  9. Java中将字符串与unicode的相互转换工具类

    unicode编码规则 unicode码对每一个字符用4位16进制数表示.具体规则是:将一个字符(char)的高8位与低8位分别取出,转化为16进制数,如果转化的16进制数的长度不足2位,则在其后补0 ...

  10. robotframework的列表与字典

    这里以Get Element Size为例,Selenium2Library返回的是列表,AppiumLibrary返回的是字典. 列表用 ${width}获取:字典用 &{ui}[width ...