UVA1316- Supermarket

点击打开链接

题意:有N个物品,每个物品在都有一个截止日期,如果在截止日期之前(包括截止日期)卖出将会获得相应的利润,卖出物品需要一个单位时间,问最多能获得多少利润?

思路:将利润从大到小排序,尽量在该物单位时间出售利润大的物品,这样就能使得从利润达到最大。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXN = 10005;

struct product{
    int money, t;
}p[MAXN];

int n, vis[MAXN];

int cmp(product a, product b) {
    return a.money > b.money;
}

int main() {
    while (scanf("%d", &n) == 1) {
        for (int i = 0; i < n; i++)
            scanf("%d%d", &p[i].money, &p[i].t); 

        sort(p, p + n, cmp);
        memset(vis, 0, sizeof(vis));
        long long ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = p[i].t; j >= 1; j--) {
                if (vis[j] == 0) {
                    ans += p[i].money;
                    vis[j] = 1;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

UVA1316- Supermarket

时间: 2025-01-17 07:50:39

UVA1316- Supermarket的相关文章

POJ 1456 Supermarket 区间问题并查集||贪心

F - Supermarket Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1456 Appoint description:  System Crawler  (2015-11-30) Description A supermarket has a set Prod of products on sale. It earns a p

BNUOJ 1575 Supermarket

Supermarket Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 145664-bit integer IO format: %lld      Java class name: Main A supermarket has a set Prod of products on sale. It earns a profit px for each produc

poj 1456 Supermarket (贪心+并查集)

# include <stdio.h> # include <algorithm> # include <string.h> using namespace std; int fa[10010]; struct node { int p; int d; }; struct node a[10010]; bool cmp(node a1,node a2)//利润从大到小 { return a1.p>a2.p; } int find(int x) { if(fa[x]

Supermarket poj 1456 贪心+并查集优化

Language: Default Supermarket Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9512   Accepted: 4096 Description A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is

Supermarket

Supermarket Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured a

【POJ 1456】Supermarket

Supermarket Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9560   Accepted: 4116 Description A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an int

POJ 1456——Supermarket——————【贪心+并查集优化】

Supermarket Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1456 Description A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx

POJ 1456 Supermarket(贪心+并查集)

Description A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment the sale begins. Each product takes precise

Codeforces Round #419 (Div. 2) E. Karen and Supermarket(树形DP)

题目链接:Codeforces Round #419 (Div. 2) E. Karen and Supermarket 题意: 有n件物品,每个物品有一个价格,和一个使用优惠券的价格,不过这个优惠券有一个限制,必须要在第x个使用后才可以使用.现在有m的钱,问最多能买多少个物品. 题解: 每个优惠券都只与一个券有关,所以根据这个关系就可以构成一棵树. 考虑树形dp,dp[i][j][k(0|1)]表示第i个节点所构成的子树中买了j个物品,使用优惠券和不使用优惠券的最少钱. 转移方程看代码详细解释

POJ1456 Supermarket (!easy)

Description A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment the sale begins. Each product takes precise