HDU 1789 Doing Homework again【贪心】
题意:给出n个作业的截止时间,和该作业没有完成会被扣掉的分数。问最少会被扣掉多少分。
第一次做这一题是好久之前,当时不会(不会处理两个关键字关系@_@)---现在还是不会---看了题解---原来是这样的---
因为要使得扣的分数尽可能少,那就先把扣分多的作业做了,即按照扣分降序排序,再遍历看该份作业能不能完成,不能完成则扣去相应的分数
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 10005
using namespace std;
int used[maxn];
struct node
{
int d,p;
} a[maxn];
int cmp(node n1,node n2)
{
return n1.p>n2.p;
}
int main()
{
int ncase,n,i,j,ans;
scanf("%d",&ncase);
while(ncase--)
{
scanf("%d",&n);
for(i=1;i<=n;i++) scanf("%d",&a[i].d);
for(i=1;i<=n;i++) scanf("%d",&a[i].p);
sort(a+1,a+1+n,cmp);
memset(used,0,sizeof(used));
ans=0; for(i=1;i<=n;i++)
{
for(j=a[i].d;j>=1;j--)
{
if(!used[j])
{
used[j]=1;
break;
}
}
if(j==0) ans+=a[i].p;
}
printf("%d\n",ans);
}
}
HDU 1789 Doing Homework again【贪心】的更多相关文章
- 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 - [贪心+优先队列]
题目链接: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 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...
- hdu 1789 Doing Homework again (Greedy)
Problem - 1789 继续贪心.经典贪心算法,如果数据比较大就要用线段树来维护了. 思路很简单,只要按照代价由大到小排序,然后靠后插入即可.RE了一次,是没想到deadline可以很大.如果d ...
- 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 http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has ...
- HDU 1789 Doing Homework again(贪心)
在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...
- HDU - 1789 Doing Homework again(贪心) ~~~学了一波sort对结构体排序
题目中因为天数和分数是对应的,所以我们使用一个结构体来存分数和截止如期. 一开始做这道题的时候,很自然的就想到对天数排序,然后天数一样的分数从大到小排序,最后WA了之后才发现没有做到"舍小取 ...
随机推荐
- 前端防止button被多次点击
前端的部分逻辑有时候控制前端的显示.比方记录收藏数目等等.有时候多次反复点击会造成前端显示的bug.所以须要有部分逻辑推断去筛除掉反复多次的点击. 实现部分代码例如以下,主要是通过setTimeout ...
- android 处理Back键按下事件
package com.example.keyevent; import android.os.Bundle; import android.view.KeyEvent; import android ...
- iOS7实现带文本输入框的UIAlertView及获取TextField文本内容
if (customAlertView==nil) { customAlertView = [[UIAlertView alloc] initWithTitle:@"自定义服务器地址&quo ...
- FastJSON杂项
//通过TypeReference解决泛型的问题 List<Integer> rst = JSON.parseObject(v,new TypeReference<List<I ...
- java web项目中资源国际化
有一些网站会有语言栏选项: 选择英文,内容就显示为英文: 选择中文,内容就显示文中文. 这里就用到了国际化资源. 先看效果图: 步骤: 1.建立资源包: mess_en_US.properties ( ...
- Creating a Custom Page Layout in SharePoint 2013
Creating a Custom Page Layout in SharePoint 2013 In my last article, I documented how to create a Ma ...
- 【转载】犀利的 oracle 注入技术
介绍一个在web上通过oracle注入直接取得主机cmdshell的方法. 以下的演示都是在web上的sql plus执行的,在web注入时 把select SYS.DBMS_EXPORT_EXTEN ...
- jsp表单验证格式
- QT笔记 -- (4) 为QLabel添加鼠标响应方法2
1.实现 bool eventFilter(QObject *target,QEvent *event) 函数内容如下: bool eventFilter(QObject *target,QEvent ...
- swift语言点评三 - Basic Operators
1.Tuples are compared from left to right, one value at a time, until the comparison finds two values ...