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. UNIX管道符

    在Unxi操作系统中,标准输入和标准输出是外壳程序中可以单独使用的两个独立流.但是有时候系统工程师需要让某些特定的输入源不起作用.当系统工程师在开发一些实用的脚本程序的过程中,经常需要用到.   一. ...

  2. grep和map计算两个集合交集、并集、补集

    #!/usr/bin/perl use strict; ######################################## 用grep 和map 获取两个列表的交集并集.补集###### ...

  3. 使用node.js 文档里的方法写一个web服务器

    刚刚看了node.js文档里的一个小例子,就是用 node.js 写一个web服务器的小例子 上代码 (*^▽^*) //helloworld.js// 使用node.js写一个服务器 const h ...

  4. Mac和Windows上Android Studio经常使用的快捷键

    小编整理了一些Mac和Windows上超有用的Android Studio经常使用的快捷键. Ctrl(Command)+Y 删除行 Ctrl(Command)+Z 倒退 Ctrl(Command)+ ...

  5. C++设计模式之代理模式

        IPhone 6已经在中国香港开售了,圆了在专卖店等候一个多月苹果粉丝的苹果梦.然而对中国大陆而言.须要到9月17日苹果才在大陆开售.这对中国大陆的粉丝而言,不亚于一种煎熬,因此而滋生一种代购 ...

  6. Linux下lvm在线扩容步骤

    转 :https://jingyan.baidu.com/article/25648fc18f22b29191fd0011.html 图片看不清可以看原文 LVM是逻辑盘卷管理(Logical Vol ...

  7. mongodb 实现关系型数据库中查询某一列 的效果

    近期在tornado\mongodb\ansible mongodb中有个find()方法非常牛逼,能够将集合中全部的表都传出来,一開始我这么写 class Module_actionHandler( ...

  8. 159. Find Minimum in Rotated Sorted Array 【medium】

    159. Find Minimum in Rotated Sorted Array [medium] Suppose a sorted array is rotated at some pivot u ...

  9. PHP获取QQ群成员QQ号码

    .加入某个群 .进入群空间http://qun.qzone.qq.com/group#!/25998059/member 备注:25998059为群号码 .进入群成员列表 .使用浏览,在某个群成员头像 ...

  10. 前端js文件添加版本号

    客户端会缓存这些css或js文件,因此每次升级了js或css文件后,改变版本号,客户端浏览器就会重新下载新的js或css文件 ,刷性缓存的作用.大家可能有时候发现修改了样式或者js,刷新的时候不变,就 ...