Doing Homework again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2969    Accepted Submission(s): 1707

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
 
Author
lcy
 
Source
 
Recommend
lcy

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int MAXN=; struct Node
{
int d,s;
}node[MAXN]; bool used[]; bool cmp(Node a,Node b)
{
if(a.s==b.s)
{
return a.d<b.d;
}
return a.s>b.s;
} //按减分从大到小排,按日期从小到大排 int main()
{
int T;
int n;
int j;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%d",&node[i].d);
for(int i=;i<n;i++) scanf("%d",&node[i].s);
sort(node,node+n,cmp);
memset(used,false,sizeof(used));//装每天所学的课程
int ans=;
for(int i=;i<n;i++)
{
for(j=node[i].d;j>;j--)//从截止日期开始往前数
{
if(!used[j])
{
used[j]=true;
break;
}
}
if(j==)//当一个位置都没有,就减分
ans+=node[i].s;
}
printf("%d\n",ans);
}
return ;
}

都说这个是水题,但是我想了很久。。。。。

继续努力吧!

HDU 1789 Doing Homework again(排序,DP)的更多相关文章

  1. hdu 1789 Doing HomeWork Again (贪心算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 /*Doing Homework again Time Limit: 1000/1000 MS ...

  2. HDU - 1789 Doing Homework again(贪心) ~~~学了一波sort对结构体排序

    题目中因为天数和分数是对应的,所以我们使用一个结构体来存分数和截止如期. 一开始做这道题的时候,很自然的就想到对天数排序,然后天数一样的分数从大到小排序,最后WA了之后才发现没有做到"舍小取 ...

  3. HDU 1789 Doing Homework again (贪心)

    Doing Homework again http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has ...

  4. HDU 1789 - Doing Homework again - [贪心+优先队列]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...

  5. HDU 1789 Doing Homework again(非常经典的贪心)

    Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  6. 题解报告:hdu 1789 Doing Homework again(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has just come back ...

  7. HDU 1789 Doing Homework again(贪心)

    Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...

  8. HDU 1074 Doing Homework(像缩进DP)

    Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of h ...

  9. HDU 1789 Doing Homework again(贪心)

    在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...

随机推荐

  1. 分享几个免费IP地址查询接口(API)

    淘宝IP地址库 提供的服务包括:1. 根据用户提供的IP地址,快速查询出该IP地址所在的地理信息和地理相关的信息,包括国家.省.市和运营商.2. 用户可以根据自己所在的位置和使用的IP地址更新我们的服 ...

  2. [LOJ3046][ZJOI2019]语言:树链的并+线段树合并

    分析 问题显然可以转化为对于每个节点询问所有这个节点的所有链的链并的大小. 考场上我直接通过树剖打标记+树剖线段树维护以\(O(n \log^3 n)\)的时间复杂度暴力实现了这个过程.(使用LCT或 ...

  3. Spring Boot教程(二十九)使用JdbcTemplate操作数据库

    使用JdbcTemplate操作数据库 Spring的JdbcTemplate是自动配置的,你可以直接使用@Autowired来注入到你自己的bean中来使用. 举例:我们在创建User表,包含属性n ...

  4. ...扩展运算符+rest参数+call/apply/bind

    之前在set,map里面有提过扩展运算符的概念,但是今天偶然遇到一个问题,类似于扩展运算符的经典用法,突然发现对其了解不是很深,所以再来整理一下扩展运算符的相关知识. 重点:扩展运算符内部调用的是数据 ...

  5. jar 在windows 启动服务,卸载服务,停止端口

    参考:https://www.cnblogs.com/zhuchunlei/p/9469569.html 1,启动服务  install.bat @echo off SET JAVA_HOME=&qu ...

  6. C++入门经典-例5.16-输出引用

    1:如不加特殊说明,一般认为引用指的都是左值引用.引用实际上是一种隐式指针,它为对象建立一个别名,通过操作符&来实现,引用的形式如下: 数据类型 & 表达式: 例如: int a=10 ...

  7. Linux常用命令及操作(第二弹)

    Ctrl l清屏 Ctrl d关闭终端 Ctrl Alt T打开终端 pwd 查看当前的目录 Shift Ctrl C复制 Shift Ctrl V粘贴 Shift Ctrl N打开新的终端 F11 ...

  8. html_javascript 基础操作

    <!DOCTYPE html> <html> <body> <h1>My Web Page</h1> <p id="demo ...

  9. ubuntu下mysql数据库存储路径修改

    一.安装mysql ubuntu系统安装配置APT源,apt install mysql-server mysql-client 二.查看安装端口情况 sudo netstat -tap | grep ...

  10. configprase模块,配置文件模块

    import configparser # config = configparser.ConfigParser() # config["DEFAULT"] = {'Port':3 ...