zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    《最小割模型在信息学竞赛中的应用》最大权闭合图
    《最小割模型在信息学竞赛中的应用》最优标号
    《最小割模型在信息学竞赛中的应用》网络战争
    P3254 圆桌问题
    P2766 最长不下降子序列问题
    P2754 星际转移问题
    洛谷P2756 飞行员配对方案问题
    状态压缩dp 炮兵阵地
    状态压缩—玉米田
    CCF 202006-2 稀疏向量
  • 原文地址:https://www.cnblogs.com/jrfr/p/10464609.html
Copyright © 2011-2022 走看看