$ HDU4864 \ Task $ greedy

$ HDOJ $

 

$Description$

 

$Sol$

$ Yi <= 100 $, and proceeds to $ xi * 500 + yi * 2 $, described In any case, $ xi $ greater gains must be greater than the product produced smaller $ $ product XI. Permit casual under:

$ Xi = xj + 1, yi = 0, yj = 100 $ extremum this case are satisfied, it is so hot the OK $ $

We will follow the $ xi $ for the first keyword, $ yi $ keyword for the second descending order, for each product, to find work time is not less than the minimum level of $ xi $ and machines to complete it.

Consider correctness seems to just look so greedy will not cause reduction in the number of completed products.

! I do not suppose there are two products $ i, j $ discuss two cases:

1) $xi>xj,yi>yj$

$ I $ optional but the machine did not choose the machines on time must be completed $ j $, and since $ i $ chose the smallest degree, so the rest certainly can complete the $ j $ on the level. If there is no surplus lower, indicating that it can only have been the most complete $ i, j $ one, then obviously choose a larger income $ i $

2) $ xi> xj, yi <yj $ and almost above

$over!$

A pair of lower realization repeat, like after completing the above, you can immediately think of $ (nm) O $ large Violence $ ovo $, apparently could not pass. So we have to maintain an array, which kept the machine is greater than or equal $ x $ the current mandate of $ x $. (a pair of routine, the first row of sorting and collection in accordance with certain requirements to the candidates which joined elements, then maintain something else) and then found that as long to find the smallest $ y $ enough. so he used the row array like a barrel, subscripts $ Y $, ... is the number of

He said very messy because the class was over I want to go out to eat a $ qwq $.

 

$Code$

 

#include<bits/stdc++.h>
#define il inline
#define Rg register
#define go(i,a,b) for(Rg int i=a;i<=b;i++)
#define yes(i,a,b) for(Rg int i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define db double
#define inf 1e7
using namespace std;
il int read()
{
    int x=0,y=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    return x*y;
}
const int N=100010;
int n,m,as1,sum[110];ll as;
bool f[N];
struct node{int x,y;}a[N],b[N];
il bool cmp(node x,node y){if(x.x==y.x)return x.y>y.y;return x.x>y.x;}
int main()
{
    while(cin>>n>>m)
    {
        as=as1=0;mem(sum,0);
        go(i,1,n)a[i]=(node){read(),read()};
        go(i,1,m)b[i]=(node){read(),read()};
        sort(a+1,a+n+1,cmp);
        sort(b+1,b+m+1,cmp);
        Rg int j=1;
        go(i,1,m)
        {
            while(j<=n && a[j].x>=b[i].x)sum[a[j++].y]++;
            go(k,b[i].y,100)if(sum[k]){as1++;as+=b[i].x*500+b[i].y*2;sum[k]--;break;}
        }
        printf("%d %lld\n",as1,as);
    }
    return 0;
}
View Code

 

 

 

Guess you like

Origin www.cnblogs.com/forward777/p/11279538.html