I - Doing Homework again

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

zichen 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 zichen 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 zichen 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

//又坑到我了,唉,贪心算法。我想的是按交作业的天数从小到大排,天数一样就扣分多的放前面,然后开始遍历,如果不能完成,看前面有没有分数比这个小的,有就扣那个最少的分,注意是最少的,没有就扣这个分,然后直到遍历结束,求告诉哪里错了。

 #include <iostream>
#include <algorithm>
using namespace std; struct zuoye
{
int day;
int fen;
};
zuoye book[]; int cmp(zuoye a,zuoye b)
{ if (a.day!=b.day)
return a.day<b.day;
return a.fen>b.fen;
} int main()
{
int n,i,all,cur,min,T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for (i=;i<n;i++) scanf("%d",&book[i].day);
for (i=;i<n;i++) scanf("%d",&book[i].fen);
sort(book,book+n,cmp);
cur=,all=;
for (i=;i<n;i++)
{
if (cur<=book[i].day)
{
cur++;
continue;
}
if (cur>book[i].day)
{
min=book[i].fen;
for (int j=i-;j>=;j--)
{
if (book[j].fen<min)
{
min=book[j].fen;
}
}
all+=min;
}
}
printf("%d\n",all);
}
return ;
}

AC的:看别人的,是按分数大的排前面,若分一样,天数小的靠前。遍历每一个数据,将截至日期前的天数再遍历,如果有空闲的日子,就用那天做这个,没有就扣分

 #include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; struct Node
{
int day,fen;
} node[]; int cmp(struct Node a,struct Node b)
{
if(a.fen!=b.fen)
return a.fen > b.fen;//扣分越多的越靠前
return a.day < b.day;//扣分相同的时候,deadline越早的越靠前
} int visit[];//如果当天没用过,值为0;否则为1 int main()
{
int T,n,i,j,all;
scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
for (i=;i<n;i++) scanf("%d",&node[i].day);
for (i=;i<n;i++) scanf("%d",&node[i].fen);
memset(visit,,sizeof(visit));
sort(node,node+n,cmp);
all=;
for (i=;i<n;i++)
{
for(j=node[i].day;j>;j--)
{
if (!visit[j])
{
visit[j]=;
break;
}
}
if (j==) all+=node[i].fen;
}
printf("%d\n",all); } return ;
}

I - Doing Homework again(贪心)的更多相关文章

  1. HDU 1789 Doing Homework again(贪心)

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

  2. hdu--1798--Doing Homework again(贪心)

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

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

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

  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. HDOJ.1789 Doing Homework again (贪心)

    Doing Homework again 点我挑战题目 题意分析 给出n组数据,每组数据中有每份作业的deadline和score,如果不能按期完成,则要扣相应score,求每组数据最少扣除的scor ...

  6. HDU_1789_doing homework again_贪心

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

  7. hdu1789 Doing Homework again(贪心+排序)

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

  8. HDU-1789 Doing Homework again 贪心问题 有时间限制的最小化惩罚问题

    题目链接:https://cn.vjudge.net/problem/HDU-1789 题意 小明有一大堆作业没写,且做一个作业就要花一天时间 给出所有作业的时间限制,和不写作业后要扣的分数 问如何安 ...

  9. 【HDOJ6343】Graph Theory Homework(贪心)

    题意: 给定n个点,每个点有权值a[i],从A走到B的花费是下取整sqrt(a[i]-a[j]),求从1号点走到n号点的最小花费 1<=n,a[i]<=1e5 思路: #include&l ...

随机推荐

  1. 万字总结:学习MySQL优化原理(转)

    本文转自:https://www.tuicool.com/wx/2eMBfmq 前言 说起MySQL的查询优化,相信大家收藏了一堆奇技淫巧:不能使用SELECT *.不使用NULL字段.合理创建索引. ...

  2. OpenERP为form和tree视图同时指定view_id的方法

    Odoo,OpenERP中文网 / 2014-07-16 文所说的是关于OpenERP中同一个对象(同名继承)使用view_id来指定form和tree视图的方法,由于官方文档中Views and E ...

  3. sql分组最大值相关

    房产表tf_estate_card,利润中心组profit_group_code,资产号main_assets_number,原值original_value 查出每个利润中心组的最大原值及其资产号 ...

  4. struts2学习笔记(一)

    1.搭建第一个struts2 app. web.xml  <?xml version="1.0" encoding="UTF-8"?> <we ...

  5. Android API Guides---OpenGL ES

    OpenGL ES Android包含高性能2D和3D图形开放图形库(OpenGL®的).详细而言,OpenGL ES的API支持. OpenGL是一个跨平台的图形API.用于指定的3D图形处理硬件标 ...

  6. 下载文件,ie文件名称乱码问题

    设置响应编码,将文件名称用java.net.URLEncoder.encode编码,这样就不会乱码了 java.net.URLEncoder.encode response.setCharacterE ...

  7. RGB格式等比例缩放

    原理为:将原始图像的每个像素通过一个比例关系式映射到相应的位置. /* lrgb: input 24bits rgb buffer srgb: output 24bits rgb buffer wid ...

  8. Django学习之网站图标

    首先,你要有一个.ico的文件,可以从easy icon直接搜索一个图标. 1.先导入RedirectView,是一个通用类视图. from django.views.generic.base imp ...

  9. 一个奇怪的EL表达式错误

    下图是在Struts2的action中写的一个方法 JSP页面代码如下: 在页面访问如下路径:http://localhost:8088/maven_ssh/cust_getCustList 目前推测 ...

  10. 2016ATF阿里巴巴技术论坛

    转自:http://blog.csdn.net/mini_monster/article/details/51175879 “爱迪生的贡献不在于让灯泡亮的更久一些,爱迪生最大的贡献是在全世界第一个想到 ...