zoukankan      html  css  js  c++  java
  • 【贪心】赶作业

    题目描述

    小墨老师总是不及时做作业,所以他总有很多的作业要做。每个老师都给了他一个完成作业的最后期限,如果他超过期限交作业,老师就会在他的期末评价中扣分。假设做每一门作业总是要一天。小墨老师希望你能够帮助他安排做作业的一个顺序,以便能够被扣掉的分数最少。

    输入

    输入包含了多个测试用例。输入的第一行是一个整数T,代表测试用例的个数。接下来的就是T个测试用例的输入。每个测试用例都从一个正整数N(1≤N≤1000)开始,代表了作业的数目。接下来有2行。第一行包含N个整数,分别代表各个作业提交的最后期限;第二行也有N个整数,即对应于各个作业超过时间提交的扣分。

    输出

    对每一个测试用例,应该在一行中输出最小的扣分数。

    样例输入

    2
    3
    3 3 3
    10 5 1
    3
    1 3 1
    6 2 3

    样例输出

    0

    3

    #include <iostream>
    #include <string>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <map>
    #define range(i,a,b) for(int i=a;i<=b;++i)
    #define LL long long
    #define rerange(i,a,b) for(int i=a;i>=b;--i)
    #define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
    using namespace std;
    struct node{
        int date,score,sd;
    }sub[1005];
    bool vis[1005];
    bool cmp(node a,node b){
        return a.score>b.score||a.score==b.score&&a.date<b.date;
    }
    int t,n;
    void init(){
        cin>>t;
    }
    void solve(){
        while(t--){
            fill(vis,0);
            cin>>n;
            range(i,1,n)cin>>sub[i].date;
            range(i,1,n){
                cin>>sub[i].score;
                sub[i].sd=0;
            }
            sort(sub+1,sub+1+n,cmp);int ans=0;
            range(i,1,n) {
                rerange(j, sub[i].date, 1)
                    if (!vis[j]) {
                        vis[j] = true;
                        sub[i].sd = 1;
                        break;
                    }
                if(!sub[i].sd)ans+=sub[i].score;
            }
            cout<<ans<<endl;
        }
    }
    int main() {
        init();
        solve();
        return 0;
    }
    View Code
  • 相关阅读:
    Android酷炫实用的开源框架(UI框架)
    The official raywenderlich.com Objective-C style guide.
    mac os 利用ssh 搭建git server服务器详细教程,以及git基本用法
    创建者模式
    工厂模式之我见
    设计模式的学习
    MSSQL基础
    Ini文件帮助类
    Nuget的使用
    Oracle批量执行脚本文件
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9344701.html
Copyright © 2011-2022 走看看