uva 1153—— Keep the Customer Satisfied
生活随笔
收集整理的這篇文章主要介紹了
uva 1153—— Keep the Customer Satisfied
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:有n個工作,已知每個工作的開始時間和結束時間,問最多能完成多少工作。
思路:貪心。要想使得最后的結果最佳,那么開始的晚的,要在最后來做。在此基礎上,需要保證先做開始的早的(需要用優先隊列來維護)。
code:
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <sstream> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <map> #include <set> #include <bitset>using namespace std;typedef long long ll; typedef unsigned long long ull; typedef long double ld;const int INF=0x3fffffff; const int inf=-INF; const int N=800010; const int M=100; const int mod=1000000007; const double pi=acos(-1.0);#define cls(x,c) memset(x,c,sizeof(x)) #define fr(i,s,n) for (int i=s;i<=n;i++)struct node {int q,d; }v[N]; bool cmp(node a,node b) {return a.d<b.d; } int n; int sol() {priority_queue<int>qu;int t=0;fr(i,1,n){if (t+v[i].q<=v[i].d){qu.push(v[i].q);t+=v[i].q;}else if (!qu.empty()){int tp=qu.top();if (tp>v[i].q){qu.pop();t=t-tp+v[i].q;qu.push(v[i].q);}}}return qu.size(); } int main() {int T;scanf("%d",&T);while (T--){scanf("%d",&n);fr(i,1,n) scanf("%d %d",&v[i].q,&v[i].d);sort(v+1,v+n+1,cmp);printf("%d\n",sol());if (T) puts("");} }總結
以上是生活随笔為你收集整理的uva 1153—— Keep the Customer Satisfied的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 察哈尔往事剧情介绍
- 下一篇: 成都大熊猫繁育研究基地残疾人免费吗