【题解】p1230 智力大冲浪

总结:

1.因为完成游戏的时间都是1分钟,所以不用考虑时间不同而带来的影响,这就是不用贪心的原因,所以可以用贪心

2.从每个游戏的最晚时间向前循环,是为了尽可能让后面游戏完成。

#include<bits/stdc++.h>
using namespace std;
int n, m, vis[505], sum;
struct node{
    int t, mon, flag;
}a[505];

bool cmp(node x, node y)
{
    return x.mon > y.mon;
}

int main()
{
    cin >> m >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i].t;
    for(int i = 1; i <= n; i++)
        cin >> a[i].mon;
    sort(a+1, a+1+n, cmp);
    for(int i = 1; i <= n; i++)
    {
        for(int j = a[i].t; j >= 1; j--)
        {
            if(vis[j] == 0)
            {
                vis[j] = 1;
                a[i].flag = 1;
                break;
            }
        }
    }
    for(int i = 1; i <= n; i++)
        if(!a[i].flag)    sum += a[i].mon;
    cout << m-sum;
    return 0;
} 

猜你喜欢

转载自www.cnblogs.com/lovezxy520/p/11361161.html