POJ 3614(贪心)

POJ 3614

1:奶牛的min和瓶子spx值从大到小排序

#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <vector>
//const int maxn = 1e5+5;
#define ll long long
#define MAX INT_MAX
#define FOR(i,a,b) for( int i = a;i <= b;++i)
using namespace std;
struct node
{
    int a,b;
}x[3000];
struct hhh
{
    int c,d;
}y[3000];
bool cmp1(node one,node two)
{
    return one.a>two.a;
}
bool cmp2(hhh one ,hhh two )
{
    return one.c>two.c;
}
int C,L,ans;
int main()
{
    cin>>C>>L;
    FOR(i,1,C)
    {
        cin>>x[i].a>>x[i].b;
    }
    FOR(i,1,L)
    {
        cin>>y[i].c>>y[i].d;
    }

    sort(x+1,x+1+C,cmp1);
    sort(y+1,y+1+L,cmp2);

    for(int i=1;i<=C;++i)
    {
        for(int j=1;j<=L;++j)
        {
            if(y[j].c<=x[i].b&&y[j].c>=x[i].a&&y[j].d>0)
            {
                y[j].d--;
                ans++;
                break;
            }
        }
    }
    cout<<ans<<endl;
}
one

2:奶牛的max和瓶子的spf从小到大排序

#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <vector>
//const int maxn = 1e5+5;
#define ll long long
#define MAX INT_MAX
#define FOR(i,a,b) for( int i = a;i <= b;++i)
using namespace std;
struct node
{
    int a,b;
}x[3000];
struct hhh
{
    int c,d;
}y[3000];
bool cmp1(node one,node two)
{
    return one.b<two.b;
}
bool cmp2(hhh one ,hhh two )
{
    return one.c<two.c;
}
int C,L,ans;
int main()
{
    cin>>C>>L;
    FOR(i,1,C)
    {
        cin>>x[i].a>>x[i].b;
    }
    FOR(i,1,L)
    {
        cin>>y[i].c>>y[i].d;
    }
    
    sort(x+1,x+1+C,cmp1);
    sort(y+1,y+1+L,cmp2);
    
    for(int i=1;i<=C;++i)
    {
        for(int j=1;j<=L;++j)
        {
            if(y[j].c<=x[i].b&&y[j].c>=x[i].a&&y[j].d>0)
            {
                y[j].d--;
                ans++;
                break;
            }
        }
    }
    cout<<ans<<endl;
}
2

 

posted @ 2019-03-03 12:09  阿斯水生产线  阅读(516)  评论(0编辑  收藏  举报