HDU 1789 Doing Homework again(排序,DP)
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
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.
#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)的更多相关文章
- hdu 1789 Doing HomeWork Again (贪心算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 /*Doing Homework again Time Limit: 1000/1000 MS ...
- HDU - 1789 Doing Homework again(贪心) ~~~学了一波sort对结构体排序
题目中因为天数和分数是对应的,所以我们使用一个结构体来存分数和截止如期. 一开始做这道题的时候,很自然的就想到对天数排序,然后天数一样的分数从大到小排序,最后WA了之后才发现没有做到"舍小取 ...
- HDU 1789 Doing Homework again (贪心)
Doing Homework again http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has ...
- HDU 1789 - Doing Homework again - [贪心+优先队列]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...
- HDU 1789 Doing Homework again(非常经典的贪心)
Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 题解报告:hdu 1789 Doing Homework again(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has just come back ...
- HDU 1789 Doing Homework again(贪心)
Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...
- 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 ...
- HDU 1789 Doing Homework again(贪心)
在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...
随机推荐
- Python 标准库、第三方库
Python 标准库.第三方库 Python数据工具箱涵盖从数据源到数据可视化的完整流程中涉及到的常用库.函数和外部工具.其中既有Python内置函数和标准库,又有第三方库和工具.这些库可用于文件读写 ...
- 关于多个py文件生成一个可运行exe文件(用pyinstaller)
首先下载Pyinstaller,在cmd命令下执行:pip installer Pyinstaller,不需要关心安装在哪 然后把所有相关的py文件都放在一个目录下 在那个目录下执行cmd命令:pyi ...
- POJ 3613 [ Cow Relays ] DP,矩阵乘法
解题思路 首先考虑最暴力的做法.对于每一步,我们都可以枚举每一条边,然后更新每两点之间经过\(k\)条边的最短路径.但是这样复杂度无法接受,我们考虑优化. 由于点数较少(其实最多只有\(200\)个点 ...
- Latex生成的.pdf 公式之间隔了几行空白
如题, 解决办法: \vspace{-1.5cm},这个数值根据需要来设置.
- PX4学习之-uORB msg 自动生成模板解读
最后更新日期 2019-06-22 一.前言 在 PX4学习之-uORB简单体验 中指出, 使用 uORB 进行通信的第一步是新建 msg.在实际编译过程中,新建的 msg 会转换成对应的 .h..c ...
- Java程序,JVM之间的关系
java程序是跑在JVM上的,严格来讲,是跑在JVM实例上的.一个JVM实例其实就是JVM跑起来的进程,二者合起来称之为一个JAVA进程.各个JVM实例之间是相互隔离的. 每个java程序都运行于某个 ...
- 【python】小型神经网络的搭建
import numpy as np def sigmoid(x): # Sigmoid activation function: f(x) = 1 / (1 + e^(-x)) return 1 / ...
- Mysql的BTREE和HASH索引
建议默认使用BTree索引,如果时间太长,可以尝试HAST索引,但限制如下: 不支持between and 只支持 = IN <> 不支持范围查询如between and和like. 无法 ...
- [转]maven中scope详解
在POM 4中,<dependency>中还引入了<scope>,它主要管理依赖的部署.目前<scope>可以使用5个值: * compile,缺省值,适用于所有阶 ...
- c#协变 抗变
public class Fa : TranOut<Fa>, TranIn<Fa> { } public class son : Fa, TranOut<son>, ...