Address: hdu4864
This question is regarded as the minimum charge stream, but there are too many sides. It is true that after the round-robin, it keeps fighting .. I have not optimized it twice... Sad ..
After reading the problem, I found it greedy... Greedy and hard to think about. The general idea is very good, that is, sorting by time first, then traversing the task and finding matching from the machine, and find the matching with the matching level as small as possible. The breakthrough point for me is that we can find matching machines instead of finding them again every time, but directly using the ones we found previously. This avoids the complexity of N ^ 2. In this way, the time complexity is only M * 100, and obviously it will not time out.
The Code is as follows:
#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include<algorithm>using namespace std;int _hash[110];struct node{ int time, lv;} task[110000], mac[110000];int cmp(node x, node y){ if(x.time==y.time) return x.lv>y.lv; return x.time > y.time;}int main(){ int n, m, i, j, num; __int64 ans; while(scanf("%d%d",&n,&m)!=EOF) { num=0; ans=0; for(i=0; i<n; i++) { scanf("%d%d",&mac[i].time,&mac[i].lv); } for(i=0; i<m; i++) { scanf("%d%d",&task[i].time,&task[i].lv); } sort(mac,mac+n,cmp); sort(task,task+m,cmp); j=0; memset(_hash,0,sizeof(_hash)); for(i=0; i<m; i++) { while(j<n&&mac[j].time>=task[i].time) { _hash[mac[j].lv]++; j++; } for(int k=task[i].lv; k<=100; k++) { if(_hash[k]) { _hash[k]--; num++; ans+=500*task[i].time+2*task[i].lv; break; } } } printf("%d %I64d\n",num,ans); } return 0;}
HDU 4864 task (Multi-school joint training 1) (Greedy)