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;
    }
  • 相关阅读:
    io工具类
    并发高级知识
    HashMap相关源码阅读
    ArrayList和LinkedList部分源码分析性能差异
    我自己的JdbcTemplate
    mysql5.7.20靠谱安装步骤
    NG 转发配置
    SQLite总结
    算是不常用的东西,java中的ResultSet转List
    不常用的技能-【手动编译java类】
  • 原文地址:https://www.cnblogs.com/lincold/p/10162341.html
Copyright © 2011-2022 走看看