POJ-1456 Supermarket

Source: Internet
Author: User
Tags comparison

Test instructions:
The store sells n items, everything has a deadline, can be bought before the cut-off time, the store sells only one item per day. Ask for maximum profit.
Solution:
Use greed to do, my practice is to sort out the best value of the goods, and then put in Vis[j], said in the first day of sales of this commodity, and then traverse each item,
If one item is found to be higher than the value of a product sold on J days, move the value down to the previous day, and if the previous day is higher than the value of this low value commodity, continue to place a comparison on the front side, so repeat.
10000*10000, up to 1 seconds of multipoint time complexity, so no TL.

#include <stdio.h> #include <string.h> #include <algorithm> using namespace std;
const int maxn=1e4+7; struct node {int p,d;}
A[MAXN];
int VIS[MAXN];
    BOOL CMP (node B,node c) {return b.p>c.p;} int main () {int n;
        while (~SCANF ("%d", &n)) {memset (vis,0,sizeof (VIS));
        int max=0; 
            for (int i=0;i<n;i++) {scanf ("%d%d", &AMP;A[I].P,&AMP;A[I].D);
        if (A[i].d>max) max=a[i].d;
        } sort (a,a+n,cmp);
            for (int i=0;i<n;i++) {int x=a[i].p; for (int j=a[i].d;j>=1;j--) {if (x>vis[j]) {int T=vi
                    S[J];
                    Vis[j]=x;
                x=t;
        }}} int sum=0;
        for (int i=1;i<=max;i++) sum+=vis[i];
    printf ("%d\n", sum); }}//* My approach is to sort the product that finds the maximum value and then put it in vis[j], which means selling the item in the J Day and then traversing each item, if one item is found to be sold in J days.The value of the commodity is also high, the value of the move to the previous day, if the day before the value of the commodity is higher than the value of the above, continue to place a comparison, so repeatedly.  
10000*10000, up to 1 seconds of multi-point time complexity, so no TL.  */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.