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. 在FASTBuild中使用Caching

    上一篇:初识FASTBuild 在FASTBuild中使用缓存只需要注意三个环节: 一.设置编译选项 对于GCC\SNC\Clang编译器,没有特殊的要求 对于MSVC编译器,必须设置/Z7调试模式. ...

  2. IIC读写AT24C02代码2——串口命令控制多页读写

    通过串口输入 R .W 进行控制程序读写IIC设备.波特率9600bps,晶振115200HZ. main.c /*------------------------------------------ ...

  3. java 发送html邮件,苹果或者某些邮件客户端收到的内容为空白解决方案

    需要把网页标签中的双引号替换为  "  或者  \\\" 例如 <div id=\\\"container\\\" style=\\\"widt ...

  4. (转)jquery实现图片轮播

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. oc自定义不定参数函数

    -(void)getValueFormConfig:(NSString *)key,... or -(void)getValueFormConfig:(NSString *)key,...NS_REQ ...

  6. Azure Storage 分块上传

    概述 Azure 存储提供三种类型的 Blob:块 Blob.页 Blob 和追加 Blob.其中,块 Blob 特别适用于存储短的文本或二进制文件,例如文档和媒体文件. 块 Blob 由块组成,每个 ...

  7. Android应用中使用百度地图API之POI(三)

    先看执行后的图吧: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbWFqaWFuamll/font/5a6L5L2T/fontsize/400/fill/ ...

  8. 英语每日一句: What’s your point? 你究竟想说什么?

    今天我们要学习的一句话是:What's your point? 你究竟想说什么?这句话在日常交流中非经常见,当对方说了非常多东西你仍不明确他究竟是什么意思时.你就能够问What's your poin ...

  9. 【LeetCode OJ 016】3Sum Closest

    题目链接:https://leetcode.com/problems/3sum-closest/ 题目:Given an array S of n integers, find three integ ...

  10. 使用maven结合requirejs管理前端脚本

    已有的web项目,一直使用Maven做工程管理,现阶段前端调整为使用requirejs来负责模块加载依赖,同时使用jasmine来完成前端的UT. 便与在maven下统一管理,简单整理了下合在一起的使 ...