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. 【C/C++学院】0831-类与对象的异常/面试100题1-100

    类与对象的异常 Cpp异常 #include <iostream> #include <string.h> using namespace std; //标识错误的类型 cla ...

  2. Excel 读取

    using UnityEngine; using System.Collections; using NPOI; using Ionic.Zip; using System.IO; using NPO ...

  3. unity3d NGUI 本地化 多语言

    原地址:http://cl314413.blog.163.com/blog/static/1905079762014421115528670/ NGUI的本地化操作: Localization UIL ...

  4. iOS tableView下拉图片放大

    事实上这个效果,本质上就是在你tableView下拉 造成offset时候. 保持你顶部图片的y坐标点还停留在下拉时屏幕的顶点(offset), 而图片的长度变为原始的height长度-(offset ...

  5. TP框架在做上传时候提示:没有上传的文件!

      这个一般是由于上传的文件超过了php.ini里面的限制.修改一下参数就行了 具体,打开php.ini 文件 搜索post_max_size upload_max_filesize 改一个比较大的, ...

  6. iOS开发-XCode常用快捷键整理

    前言:如果我们能够掌握并巧妙地使用快捷键,可以大大加快我们的工作效率,这个对经常使用快捷键的人们来说,应该很容易理解.因此我们需要做的是,针对于自己经常使用的快捷键去进行记忆.我不会推荐你们去把所有的 ...

  7. Python 的基本运算和内置函数

    一.运算符 (一)Python算术运算符 以下假设变量: a=10,b=20: 运算符 描述 实例 + 加 - 两个对象相加 a + b 输出结果 30 - 减 - 得到负数或是一个数减去另一个数 a ...

  8. 04-2winPE里面下载系统并安装系统教程

    winPE里面下载系统并安装系统教程 首先需要注意的是,你已经使用 装机助理 工具制作好U盘启动盘,通过电脑功能键进入PE界面(不同型号的电脑进入PE界面的功能键不同,根据不同搜索属于她的功能键): ...

  9. eclipse spring xml 无提示解决

    增加自动提示的步骤: 1.window->preference.->xml-xml catalog 2.选中 user specified entried 3.选则Add..按钮 URI: ...

  10. nginx跨域(转2)

    当出现403跨域错误的时候 No 'Access-Control-Allow-Origin' header is present on the requested resource,需要给Nginx服 ...