程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> HDU 4864(多校)1004 Task

HDU 4864(多校)1004 Task

編輯:C++入門知識

HDU 4864(多校)1004 Task


Problem Description Today the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile, this task has a difficulty level yi. The machine whose level below this task’s level yi cannot complete this task. If the company completes this task, they will get (500*xi+2*yi) dollars.
The company has n machines. Each machine has a maximum working time and a level. If the time for the task is more than the maximum working time of the machine, the machine can not complete this task. Each machine can only complete a task one day. Each task can only be completed by one machine.
The company hopes to maximize the number of the tasks which they can complete today. If there are multiple solutions, they hopes to make the money maximum.
Input The input contains several test cases.
The first line contains two integers N and M. N is the number of the machines.M is the number of tasks(1 < =N <= 100000,1<=M<=100000).
The following N lines each contains two integers xi(0 The following M lines each contains two integers xi(0 Output For each test case, output two integers, the maximum number of the tasks which the company can complete today and the money they will get.
Sample Input
1 2
100 3
100 2
100 1

Sample Output
1 50004

Source 2014 Multi-University Training Contest 1 我的渣代碼就是過不了,看了大神 點擊打開鏈接 的,開始覺得有BUG,後來想了想 這種方法真好,值得我去學習=-=
#include
#include
#include
#include
using namespace std;
const int maxn=1e5+10;
int n,m;
int h[maxn];
struct node{
    int x,y;
}e[maxn],f[maxn];
int cmp(node l1,node l2)
{
     if(l1.x==l2.x)
         return l1.y>l2.y;
     return l1.x>l2.x;
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        memset(h,0,sizeof(h));
        for(int i=0;i=f[i].x)//由於對e,f,都排了序所以找出大於f[i].x所有的e[j],將e[j].y儲存起來;
            {
                h[e[j].y]++;
                j++;
            }
            for(int k=f[i].y;k<=100;k++)//從找到的e[j].y中選擇最小的
            {
                if(h[k])//判斷是否存在
                {
                    h[k]--;
                    num++;
                    ans+=f[i].x*500+f[i].y*2;
                    break;
                }
            }
        }
        printf("%d %I64d\n",num,ans);
    }
    return 0;
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved