南城做网站,浙江品牌网站建设,网站开发招聘要求,网站还没上线怎么做品牌推广题意#xff1a;有n个工作#xff0c;已知每个工作的开始时间和结束时间#xff0c;问最多能完成多少工作。 思路#xff1a;贪心。要想使得最后的结果最佳#xff0c;那么开始的晚的#xff0c;要在最后来做。在此基础上#xff0c;需要保证先做开始的早的#xff08;…
题意有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 bitsetusing namespace std;typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;const int INF0x3fffffff;
const int inf-INF;
const int N800010;
const int M100;
const int mod1000000007;
const double piacos(-1.0);#define cls(x,c) memset(x,c,sizeof(x))
#define fr(i,s,n) for (int is;in;i)struct node
{int q,d;
}v[N];
bool cmp(node a,node b)
{return a.db.d;
}
int n;
int sol()
{priority_queueintqu;int t0;fr(i,1,n){if (tv[i].qv[i].d){qu.push(v[i].q);tv[i].q;}else if (!qu.empty()){int tpqu.top();if (tpv[i].q){qu.pop();tt-tpv[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(v1,vn1,cmp);printf(%d\n,sol());if (T) puts();}
}