【链接】http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1010&cid=767


【题意】


给一些区间,每台机器在这些区间中运行,但是,一台机器最多只能在一段区间内运行,(在相同的地方有多个区间则需要多个机器),并且,机器关掉不能再开,求:使用最少机器的情况下的最短运行时间。
运行时间是所有机器的运行时间的总和.

【题解】


因为优先的是最小的机器个数;
先将区间按左端点升序排一下.
然后按顺序枚举区间.
对于遇到的区间
要用哪一个机器来处理它呢?
当然是结束时间最晚且在这个区间的左边的机器.
这样的话,每次增加的时间就是最少的了;
而那些结束时间早的,就先尽量不用.
因为用那些的话,增加的时间更多.
如果没有机器可以用的话,那就只好用一台新的机器了
这样的过程可以保证用的机器是最少的
因为都尽量用了
写个multiset存一下每个机器结束的时间就好.
新加的机器,就假设它是在区间开始的时刻才开动就好.
注意机器是关闭了就不能开启了.所以得一直开着,就算中间没有在做事情。
千万不要用upper_bound(set.begin(),set.end(),a[i])这样的写法。
要这样写
set.upper_bound(a[i]);
不然会超时的!!!

【错的次数】


1

【反思】


1.set.upper_bound(a[i]);
2.要注意看题目

【代码】

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <set>
#include <cstdlib>
#include <cmath>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e5; multiset <int> myset;
pii a[N + 10];
int n;
LL ans = 0; int main() {
//Open();
//Close();
int T;
ri(T);
while (T--) {
ri(n);
rep1(i, 1, n)
ri(a[i].fi), ri(a[i].se);
sort(a + 1, a + 1 + n);
myset.clear();
LL ans = 0;
rep1(i, 1, n) {
auto temp = myset.upper_bound(a[i].fi);
//cout <<"i="<<i<<' ';cout << (*temp) << endl;
if (temp == myset.begin()) {
myset.insert(a[i].se);
ans = (ans + a[i].second - a[i].first);
continue;
}
temp--;
ans = (ans + a[i].second - *temp);
myset.erase(temp);
myset.insert(a[i].se);
}
oi((int)myset.size()); oc; ol(ans); puts("");
}
return 0;
}

最新文章

  1. svn import-纳入版本控制
  2. 十五天精通WCF——第二天 告别烦恼的config配置
  3. Sublime Text 2 快捷键 (windows)
  4. Backup: Array in Perl6
  5. BindingNavigator操作DatagridView的数据
  6. 在mac上安装pydev for eclipse时,在eclipse的Preferences中无法显示出来的解决方法
  7. js获取时间
  8. 百度编辑器ueditor 在vs2008中的使用方法
  9. 体验安装金蝶K/3 Wise 13.0(图像)
  10. 用virtualenv建立多个Python独立开发环境
  11. sublime Text 常用插件
  12. D1——初读《Head First Java》
  13. 前端 ---BOM的介绍
  14. mysql 不区分大小写的解决
  15. android 通过页面上关键字快速定位代码
  16. highcharts图表组件通过设置tooltip属性自定义数据提示信息
  17. C++模式学习------模板模式
  18. Android 能够暂停的录音功能
  19. [Windows Powershell]-学习笔记(4)
  20. tcp/ip学习笔记-TCP

热门文章

  1. [Chromium文档转载,第001章] Mojo Migration Guide
  2. JS 引擎基础之 Shapes and Inline Caches
  3. 【Uva 242】Stamps and Envelope Size
  4. [Python] Create a Log for your Python application
  5. 零基础学python-7.6 字符串格式化表达式
  6. iOS 平台上常见的安装包有三种,deb、ipa 和 pxl
  7. J2SE基础:2.对象的创建与使用
  8. js---16原型链
  9. 洛谷P1976 鸡蛋饼
  10. vuejs实现表格分页