HDU-1789-Doing Homework again

链接:https://vjudge.net/problem/HDU-1789#author=Andy_acmer

题意:

交大校队刚从2018焦作站ACM/ICPC回来。现在他有很多作业要做。每个老师给他一个交作业的最后期限。
如果他们在最后期限后交作业,老师就会降低他的期末成绩。
现在我们假设每个人做作业都需要一天。
所以他们想到了要安排做作业的顺序,把降低的分数降到最低。
请帮助他们。

思路:

贪心。

优先选择减分较多的科目,从截至日期往前找,找到第一个没有用过的天。

如果找不到则讲其分数累加。

代码:

#include <iostream>
#include <memory.h>
#include <string>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>
#include <cstdio>
using namespace std;

typedef long long LL;

const int MAXN = 1000 + 10;

struct Node
{
    int _t;
    int _v;
    bool operator < (const Node & that) const
    {
        /*
        if (this->_t != that._t)
            return this->_t < that._t;
        */
        return this->_v > that._v;
    }
}node[MAXN];
int vis[MAXN];

int main()
{
    int t, n;
    cin >> t;
    while (t--)
    {
        memset(vis, 0, sizeof(vis));
        cin >> n;
        for (int i = 1;i <= n;i++)
            cin >> node[i]._t;
        for (int i = 1;i <= n;i++)
            cin >> node[i]._v;
        sort(node + 1, node + 1 + n);
        int res = 0;
        for (int i = 1;i <= n;i++)
        {
            int w = node[i]._t;
            while (vis[w] == 1 && w > 0)
                w--;
            if (w == 0)
                res += node[i]._v;
            else
                vis[w] = 1;
        }
        cout << res << endl;
    }

    return 0;
}

  

原文地址:https://www.cnblogs.com/YDDDD/p/10624819.html