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. 探索Windows命令行系列(4):通过命令管理文件和文件夹

    1.文件夹操作 1.1.DIR(directory)命令 1.2.TREE 命令 1.3.CD(change directory)命令 1.4.MD(make directory)命令 1.5.RD( ...

  2. jquery元素是否可见(隐藏)

    var temp1=$(".view_hidden").is(":visible");//是否可见 var temp2=$(".elem_id&quo ...

  3. 手把手教你 基础 整合最优雅SSM框架:SpringMVC + Spring

    我们看招聘信息的时候,经常会看到这一点,需要具备SSH框架的技能:而且在大部分教学课堂中,也会把SSH作为最核心的教学内容. 但是,我们在实际应用中发现,SpringMVC可以完全替代Struts,配 ...

  4. Win10安裝weblogic12C

    一.系统环境 Win10系统 Jdk1.8 64位 二.安装Weblogic      第一步:用系统管理员身份打开CMD命令提示符,用CMD方式进入"fmw_12.1.3.0.0_wls. ...

  5. Django 踩过的坑(一)

    平台:win10 工具:cmd python3 刚刚学习Django搭建环境,网站还木有发布,就直接来了个大麻烦. 一切按着<Django 学习笔记(二)>这篇文章来的,在最后cmd运行服 ...

  6. 不用EF框架,完成完美实体映射,且便于维护!(AutoMapper,petapoco)

    最近,需要搭建一个新项目,在需求分析时确定数据库中需要创建多个存储过程.所以如果还是用原来EF框架生成ADO.net实体模型的话,不利于修改. 主要是解决以下两个问题: 1.比如前端需要一个值,如果存 ...

  7. Elasticsearch学习随笔(二)-- Index 和 Doc 查询新建API总结

    本文着重总结Elasticsearch的常见API了,进行分析. Index API 初始化Index,设置shards和replica PUT http://localhost:9200/firew ...

  8. Vue--props

    组件实例的作用域是孤立的.这意味着不能 (也不应该) 在子组件的模板内直接引用父组件的数据.要让子组件使用父组件的数据,我们需要通过子组件的 props 选项. 字面量语法 vs 动态语法 初学者常犯 ...

  9. js实现图片旋转、模板文件查看图片大图之记录篇[二]

    一个小小的前端需求送给大家,使用js实现图片旋转,并且点击图片能够实现规定格式的大图. 主要使用的是jQuery的delegate()方法实现图片旋转,该方法主要的功能就是给某个组件绑定一个或一组事件 ...

  10. [CF486D]有效集合-树形dp

    Problem 有效集合 题目大意 给出一棵树,求出这棵树的不同联通子节点集合的数量,这些集合必须满足最大权值点减最小权值点小于等于d. Solution 再一次树d乱搞. 因为数据范围贼小,所以我们 ...