lightoj1301Monitoring Processes
来源:互联网 发布:奥尼尔vs奥拉朱旺 数据 编辑:程序博客网 时间:2024/06/05 14:32
思路:有n个进程,开始时间s[i],结束时间t[i],我们要用监视器来监视这些进程,但是每个监视器同一时间只能监视一个进程,只有当这个监视器监视的进程结束后才能监视下一个,问需最少要多少个监视器才能监视完所有进程。
这题也是贪心,n个进程有2n个时间点,一个时间点要么是一个进程的开始,要么是一个进程的结束,开始的话就需要派监视器来监管,这个监视器有两个来源,一是前面已经监视完别的进程而空下来的,再就是额外添加的,所以我们需要一个pre来记录到目前为止需要多少个,ans表示到目前为止添加了多少个。存在同个时间是某些进程的开始,也是某些进程的结束,由于同一时间不能监视两个,所以要先算开始的,再算结束的。开始就需要的++,结束的就需要的--,再与已有的进行大小比较取最大就好了。
// #pragma comment(linker, "/STACK:1024000000,1024000000")#include <iostream>#include <algorithm>#include <iomanip>#include <sstream>#include <string>#include <stack>#include <queue>#include <deque>#include <vector>#include <map>#include <set>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <climits>using namespace std;// #define DEBUG#ifdef DEBUG#define debug(...) printf( __VA_ARGS__ )#else#define debug(...)#endif#define CLR(x) memset(x, 0,sizeof x)#define MEM(x,y) memset(x, y,sizeof x)#define pk push_backtemplate<class T> inline T Get_Max(const T&a,const T&b){return a < b?b:a;}template<class T> inline T Get_Min(const T&a,const T&b){return a < b?a:b;}typedef long long LL;typedef unsigned long long ULL;typedef pair<int,int> ii;const double eps = 1e-10;const int inf = 1 << 30;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;ii A[100010];int main(){freopen("in.txt","r",stdin);// freopen("out.txt","w",stdout);int t, n, icase = 0;scanf("%d",&t);while(t--){scanf("%d",&n);int top = 0;for (int i = 1, x, y;i <= n;++i){scanf("%d%d",&x,&y);A[top++] = ii(x,-1);A[top++] = ii(y, 1);}sort(A,A+top);int ans = 0, pre = 0;for (int i = 0;i < top;++i){pre -= A[i].second;if (pre > ans) ans = pre;}printf("Case %d: %d\n", ++icase, ans);}return 0;}
0 0
- lightoj1301Monitoring Processes
- Processes
- Processes
- Unkillable Processes
- Software Processes
- Multiple Processes
- processes参数设置
- Spawning Processes
- 11 Processes
- 3.1. Processes, Lightweight Processes, and Threads
- Modules, Processes, Threads
- [转贴]Enumerating Windows Processes
- Processes and Threads Sample
- Processes and Threads
- 9.1. Blocking Processes
- Chapter 3. Processes
- Requirements Engineering Processes
- Enumerating Windows Processes
- cocos2dx中lua注册事件函数详解
- UITextView使用
- 深入分析JavaWeb Item11 -- session会话管理
- c++11多线程入门实例
- 网页设计大赛总结
- lightoj1301Monitoring Processes
- Xcode7 —https适配问题
- redhat linux 设置yum
- HDU 5558 2015ICPC合肥站G题
- leetcode -- Reorder List -- 重点,很适合作为面试题
- linux下history(历史)命令用法详解
- OC-022.OC的构造方法-03.类方法的构造
- c++
- Android Java(2015-6-18 15:28、2016-1-30 21:18、2016-5-31 11:20)