Doing Homework again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13847    Accepted Submission(s): 8036

Problem Description
Ignatius 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 Ignatius 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 Ignatius 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
/*
    Name: hdu--1798--Doing Homework again
    Copyright: 2017 日天大帝
    Author: 日天大帝
    Date: 21/04/17 15:32
    Description: 贪心,思路让当前分数大的替换当前分数小的作业
*/
#include<iostream>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
struct work{
    int score,deadline;
    bool operator<(const work &a)const{
        return score>a.score;
    }
}arr[];
bool cmp(work a,work b){
    return a.deadline<b.deadline;
}
priority_queue<work> q;//按照分数排序
int main(){

    ios::sync_with_stdio(false);

    int T;cin>>T;
    while(T--){
        memset(arr,,sizeof(arr));
        while(!q.empty())q.pop();
        int n;cin>>n;
        ; i<n; ++i)cin>>arr[i].deadline;
        ; i<n; ++i)cin>>arr[i].score;
        ,ans = ;
        sort(arr,arr+n,cmp);//按照时间排序
        ; i<n; ++i){
            q.push(arr[i]);
            if(t < arr[i].deadline){
                t++;continue;
            }
            ans += q.top().score;
            q.pop();
        }
        cout<<ans<<endl;
    }
    ;
}
/*大神的代码,优先队列和排序很巧妙*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <utility>
#include <vector>
#include <iterator>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
 << ;
const int INF = 0x3f3f3f3f;
P arr[MAX_N];

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    int T;
    scanf("%d", &T);
    while (T--) {
        int n;
        scanf("%d", &n);
        ; i < n; ++i)
            scanf("%d", &arr[i].first);
        ; i < n; ++i)
            scanf("%d", &arr[i].second);
        sort(arr, arr + n);
        , day = ;
        priority_queue<int, vector<int>, greater<int> > pque;
        ; i < n; ++i) {
            pque.push(arr[i].second);
            if (day < arr[i].first) {
                ++day;
                continue;
            }
            ans += pque.top();
            pque.pop();
        }
        printf("%d\n", ans);
    }
    ;
}

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

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

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

  2. HDU 1789 - Doing Homework again - [贪心+优先队列]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...

  3. HDU 1789 Doing Homework again(贪心)

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

  4. 【状态DP】 HDU 1074 Doing Homework

    原题直通车:HDU  1074  Doing Homework 题意:有n门功课需要完成,每一门功课都有时间期限t.完成需要的时间d,如果完成的时间走出时间限制,就会被减 (d-t)个学分.问:按怎样 ...

  5. HDU 1074 Doing Homework (动态规划,位运算)

    HDU 1074 Doing Homework (动态规划,位运算) Description Ignatius has just come back school from the 30th ACM/ ...

  6. hdu 4825 Xor Sum(trie+贪心)

    hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...

  7. HDU 1789 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(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has just come back ...

  9. HDU 1789 Doing Homework again (贪心)

    Doing Homework again http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has ...

  10. HDU 1789 Doing Homework again(贪心)

    在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...

随机推荐

  1. Markdown: 编译pdf

    在网上发布博文的时候希望能顺便在本地保存一份记录,这样总结的东西很多的时候就可以写成一本给自己看的小书了.在linux下面有两个选择latex和markdown,虽然latex非常强大,但是很少有博客 ...

  2. 记一次服务器Tomcat优化经历

    公司需要一台测试服务器来做测试用,所以花了几天时间把服务全部部署好,在部署好war包之后,发现Tomcat访问超级慢. 1.进入Tomcat的bin目录下,运行 ./catalina.sh run命令 ...

  3. [leetcode-507-Perfect Number]

    We define the Perfect Number is a positive integer that is equal to the sum of all its positive divi ...

  4. 【Android Developers Training】 86. 基于连接类型修改您的下载模式

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  5. Unity-奥义技能背景变黑效果

    [旧博客转移 - 2016年8月29日 12:51 ] 前段时间做了一个放技能的时候,背景缓慢变黑,放完后再变回来的效果,可以很好的突出技能特效的感觉. 算是一种屏幕后期特效,这个特效说难不难,说简单 ...

  6. string can not be resolved

    参考:http://jingyan.baidu.com/article/a17d5285339c828099c8f245.html

  7. kali切换字符界面模式和切换图形界面模式

    我也是走了很多弯路,下面把正确的命令写出来,网上的不是说不正确,是linux命令做出了更改 Systemd是一种新的linux系统服务管理器 它替代了init, 直接上命令吧! 切换至字符界面 sud ...

  8. DDD理论学习系列(11)-- 工厂

    DDD理论学习系列--案例及目录 1.引言 在针对大型的复杂领域进行建模时,聚合.实体和值对象之间的依赖关系可能会变得十分复杂.在某个对象中为了确保其依赖对象的有效实例被创建,需要深入了解对象实例化逻 ...

  9. 自动化运维—tomcat服务起停(mysql+shell+django+bootstrap+jquery)

    项目简介: 项目介绍:自动化运维是未来的趋势,最近学了不少东西,正好通过这个小项目把这些学的东西串起来,练练手. 基础架构: 服务器端:web框架-Django 前端:html css jQuery ...

  10. 一个简单、易用的Python命令行(terminal)进度条库

    eprogress 是一个简单.易用的基于Python3的命令行(terminal)进度条库,可以自由选择使用单行显示.多行显示进度条或转圈加载方式,也可以混合使用. 示例 单行进度条 多行进度条 圆 ...