日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Keep the Customer Satisfied

發布時間:2025/7/14 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Keep the Customer Satisfied 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:

n個訂單,每個訂單有完成需要的天數,和限制的天數,求最多能完成多少訂單

分析:

先按限制日期升序排列,若當前訂單不能完成,和上面已選中的訂單中需要天數中最大的比較,若比它小,則替換他。

#include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <string> #include <cctype> #include <complex> #include <cassert> #include <utility> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> using namespace std; typedef pair<int,int> PII; typedef long long ll; #define lson l,m,rt<<1 #define pi acos(-1.0) #define rson m+1,r,rt<<11 #define All 1,N,1 #define read freopen("in.txt", "r", stdin) const ll INFll = 0x3f3f3f3f3f3f3f3fLL; const int INF= 0x7ffffff; const int mod = 1000000007; struct node{int q,d; }a[800010]; int n; bool cmp(node x,node y){return x.d<y.d; } void solve(){sort(a,a+n,cmp);int sum=0,num=0;priority_queue<int>que;for(int i=0;i<n;++i){if(sum+a[i].q>a[i].d){if(que.empty())continue;int tmp=que.top();if(tmp>a[i].q){sum=sum+a[i].q-tmp;que.pop();que.push(a[i].q);}}else{num++;que.push(a[i].q);sum+=a[i].q;}}printf("%d\n",num); } int main() {int t,ca=0;scanf("%d",&t);while(t--){if(ca++)printf("\n");scanf("%d",&n);for(int i=0;i<n;++i)scanf("%d%d",&a[i].q,&a[i].d);solve();} return 0; }

?

轉載于:https://www.cnblogs.com/zsf123/p/4869951.html

總結

以上是生活随笔為你收集整理的Keep the Customer Satisfied的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。