zoukankan      html  css  js  c++  java
  • bzoj1572 [Usaco2009 Open]工作安排Job

    [Usaco2009 Open]工作安排Job

    Time Limit: 10 Sec Memory Limit: 64 MB

    Description

    Farmer John 有太多的工作要做啊!!!!!!!!为了让农场高效运转,他必须靠他的工作赚钱,每项工作花一个单位时间。 他的工作日从0时刻开始,有1000000000个单位时间(!)。在任一时刻,他都可以选择编号(1~N)(N(1 <= N <= 100000))项工作中的任意一项工作来完成。 因为他在每个单位时间里只能做一个工作,而每项工作又有一个截止日期,所以他很难有时间完成所有(N)个工作,虽然还是有可能。 对于第(i)个工作,有一个截止时间(D_i(1 <= D_i <= 1000000000)),如果他可以完成这个工作,那么他可以获利(P_i( 1<=P_i<=1000000000 )). 在给定的工作利润和截止时间下,FJ能够获得的利润最大为多少呢?答案可能会超过32位整型。

    Input

    第1行:一个整数N. 第2~N+1行:第i+1行有两个用空格分开的整数:(D_i)(P_i).

    Output

    输出一行,里面有一个整数,表示最大获利值。

    Sample Input

    3
    2 10
    1 5
    1 7

    Sample Output

    17

    HINT

    第1个单位时间完成第3个工作(1,7),然后在第2个单位时间完成第1个工作(2,10)以达到最大利润

    贪心,网上题解是正着的,所以我们倒着贪心。。。。。
    代码解释。

    
    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1e5 + 5;
    struct lpl{
    	int d;
    	long long p;
    	bool operator < (const lpl &a)const{
    		return a.d < d;
    	}
    }ini[maxn];
    priority_queue<long long> q;
    int n, tot = 1;
    long long ans = 0;
    
    inline void putit()
    {
    	scanf("%d", &n);
    	for(int i = 1; i <= n; ++i) scanf("%d%lld", &ini[i].d, &ini[i].p);
    }
    
    inline void workk()
    {
    	sort(ini + 1, ini + n + 1);
    	//for(int i = 1; i <= n; ++i) printf("%d%lld
    ", ini[i].d, ini[i].p);
    	for(int i = ini[1].d; i >= 1; --i){
    		while(ini[tot].d == i)
    		{q.push(ini[tot].p); tot++;}
    		if(!q.empty()) 
    		{ans += q.top(); q.pop();}
    	}
    	cout << ans;
    }
    
    int main()
    {
    	putit();	
    	workk();
    	return 0;
    }
    
    心如花木,向阳而生。
  • 相关阅读:
    Centos7 安装python3 pip3
    VMW14.x虚拟机安装Mac10.13系统教程
    ADB命令大全
    appium服务器参数
    虚拟机VM14.X安装Mac10.12启动出现问题的解决方法
    Centos7安装vscode
    jmeter接口测试多数据组合登陆场景
    appium环境安装
    mysql命令大全
    jmeter录制请求
  • 原文地址:https://www.cnblogs.com/LLppdd/p/8679235.html
Copyright © 2011-2022 走看看