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(贪心)
在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...
随机推荐
- Max Sum Plus Plus(最大m字段和,优化)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description Now I t ...
- A. Be Positive
A. Be Positive time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 安装OpenCV 3 on Raspbian Jessie
环境: 硬件:树莓派三代B型, 5MP Camera Board Module 软件:Raspbian,Opencv 安装依赖 $ sudo apt-get update $ sudo apt-g ...
- C++入门经典-例5.8-使用指针函数进行运算
1:函数指针式指向函数内存的指针,一个函数在编译时被分配给一个入口地址,这个函数的入口地址就称为函数指针.可以用一个指针变量指向函数,然后通过该指针变量调用此函数. 一个函数可以返回一个整数型值.字符 ...
- C++入门经典-例2.15-逗号表达式的应用
1:代码如下: // 2.15.cpp : 定义控制台应用程序的入口点. #include "stdafx.h" #include<iostream> using na ...
- HTML控件 隐藏
div的visibility可以控制div的显示和隐藏,但是隐藏后页面显示空白: style="visibility: none;" document.getElementById ...
- 数据框架对比:Hadoop、Storm、Samza、Spark和Flink——flink支持SQL,待看
简介 大数据是收集.整理.处理大容量数据集,并从中获得见解所需的非传统战略和技术的总称.虽然处理数据所需的计算能力或存储容量早已超过一台计算机的上限,但这种计算类型的普遍性.规模,以及价值在最近几年才 ...
- vuex 的介绍
vue-cli 中 css 的作用域 scoped vue 数据的为响应数据,一改全改,一变全变的特性,我们的很多处理也会围绕着他 vuex 是处理数据的,是 vue 的数据仓库 vuex 的作用:采 ...
- 11G 新特性之 密码延迟认证
11G 新特性之 密码延迟认证 11G 新特性之 密码延迟认证 Table of Contents 1. 特性简述 2. 特性潜在引发问题 3. 关闭特性 1 特性简述 为了防止用户密码的暴力破解,从 ...
- Jmeter(八)乱码处理
发贴的内容和标题在进行参数化之后, 由于包含中文, 情理之中地出现了乱码(得意地笑, 坐等你跳坑中.)