zoukankan      html  css  js  c++  java
  • [HDU4864]Task (贪心)

    此图和上一篇博客的图一起看有奇效

    题意

    https://vjudge.net/problem/HDU-4864

    思路

    贪心

    代码

    by lyd

    我实在是敲不来

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <ctime>
    #include <algorithm>
    #include <cmath>
    #include <queue>
    #include <vector>
    using namespace std;
     
    #define LL __int64
    const int maxn=1e5+10;
    struct node{
        int x,y;
    }e[maxn],f[maxn];
    int c[101];
    int cmp(node a,node b)
    {
        if(a.x==b.x)return a.y>b.y;
        return a.x>b.x;
    }
    int main()
    {
        //freopen("C:\Documents and Settings\Administrator\×ÀÃæ\in.txt","r",stdin);
        //freopen("C:\Documents and Settings\Administrator\×ÀÃæ\out.txt","w",stdout);
        //double a = clock();
        int n,m;
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            int i,j,k,num=0;
            LL ans=0;
            for(i=0;i<n;i++)
                scanf("%d%d",&e[i].x,&e[i].y);
            for(i=0;i<m;i++)
                scanf("%d%d",&f[i].x,&f[i].y);
            sort(e,e+n,cmp);
            sort(f,f+m,cmp);
            memset(c,0,sizeof(c));
            for(i=0,j=0;i<m;i++)
            {
                while(j<n&&e[j].x>=f[i].x)
                {
                    c[e[j].y]++;
                    j++;
                }
                for(k=f[i].y;k<=100;k++)
                {
                    if(c[k])
                    {
                        num++;
                        c[k]--;
                        ans=ans+500*f[i].x+2*f[i].y;
                        break;
                    }
                }
            }
            printf("%d %I64d
    ",num,ans);
        }
        //double b = clock();
        //printf("%lf
    ", (b - a) / CLOCKS_PER_SEC);
        return 0;
    }
  • 相关阅读:
    主成分分析法
    K-means算法
    高斯混合模型
    data structure test
    八皇后问题求解
    商品管理系统课程设计
    哈佛商学院20部必看电影
    usaco1.1
    Visual Studio 2012 出现关于ActivityLog.xml错误的解决方案
    2012蓝桥杯决赛题
  • 原文地址:https://www.cnblogs.com/lincold/p/10162341.html
Copyright © 2011-2022 走看看