【链接】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;
}

【2017 Multi-University Training Contest - Team 10】Schedule的更多相关文章

  1. 【2017 Multi-University Training Contest - Team 10 】Monkeys

    [链接]点击打开链接 [题意] 给你一棵n节点的树,现在让你放k个猴子,可以删边,问最少可以剩余几条边,放k个猴子,满足任意一个猴 子至少与一只猴子相连.2<=k<=n<=1e5 [ ...

  2. 【2017 Multi-University Training Contest - Team 2】TrickGCD

    [Link]:http://acm.hdu.edu.cn/showproblem.php?pid=6053 [Description] 给你一个b数组,让你求一个a数组: 要求,该数组的每一位都小于等 ...

  3. 【2017 Multi-University Training Contest - Team 2】Maximum Sequence

    [Link]:http://acm.hdu.edu.cn/showproblem.php?pid=6047 [Description] 给你一个数列a和一个数列b; 只告诉你a的前n项各是什么; 然后 ...

  4. 【2017 Multi-University Training Contest - Team 2】 Regular polygon

    [Link]: [Description] 给你n个点整数点; 问你这n个点,能够组成多少个正多边形 [Solution] 整点只能构成正四边形. 则先把所有的边预处理出来; 枚举每某两条边为对角线的 ...

  5. 【2017 Multi-University Training Contest - Team 2】 Is Derek lying?

    [Link]: [Description] 两个人都做了完全一样的n道选择题,每道题都只有'A','B','C' 三个选项,,每道题答对的话得1分,答错不得分也不扣分,告诉你两个人全部n道题各自选的是 ...

  6. 【2017 Multi-University Training Contest - Team 4】Time To Get Up

    [Link]: [Description] [Solution] 把每个数字长什么样存到数组里就好;傻逼题. (直接输入每一行是什么样子更快,不要一个字符一个字符地输入) [NumberOf WA] ...

  7. 【2017 Multi-University Training Contest - Team 7】Hard challenge

    [Link]:http://acm.hdu.edu.cn/showproblem.php?pid=6127 [Description] 平面上有n个点,每个点有一个价值,每两个点之间都有一条线段,定义 ...

  8. 【2017 Multi-University Training Contest - Team 7】Kolakoski

    [Link]:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1011&cid=765 [Description] 有一种 ...

  9. 【2017 Multi-University Training Contest - Team 9】FFF at Valentine

    [链接]http://acm.hdu.edu.cn/showproblem.php?pid=6165 [题意] 一张有向图,n个点,m条边,保证没有重边和自环.询问任意两个点能否满足任何一方能够到达另 ...

随机推荐

  1. 如何在 Linux 上安装应用程序

    如何在 Linux 上安装应用程序 编译自:https://opensource.com/article/18/1/how-install-apps-linux作者: Seth Kenlon原创:LC ...

  2. nginx 实现跨域

    nginx 添加头部跨域. location / { add_header 'Access-Control-Allow-Origin' '*'; //允许的域 add_header 'Access-C ...

  3. chown---改变某个文件或目录的所有者和所属的组

    chown命令改变某个文件或目录的所有者和所属的组,该命令可以向某个用户授权,使该用户变成指定文件的所有者或者改变文件所属的组.用户可以是用户或者是用户D,用户组可以是组名或组id.文件名可以使由空格 ...

  4. Python socket doesn't close connection properly

    Python socket doesn't close connection properly The error information: [Errno 98] Address already in ...

  5. C# Arcgis Engine 捕捉功能实现

    namespace 捕捉 { public partial class Form1 : Form { private bool bCreateElement=true; ; ; private IEl ...

  6. Starting nagios:This account is currently not available.

    解决方式: 又一次安装php 再重新启动apache 再启动nagios 再訪问:http://ip/nagios 我的问题就是 解决的.

  7. mysql通过字段凝视查找字段名称

    有时候表的字段太多.仅仅是大致记得表的凝视,想通过字段凝视查找字段名称,能够用例如以下语句: SELECT COLUMN_NAME,column_comment FROM INFORMATION_SC ...

  8. BZOJ1835: [ZJOI2010]base 基站选址(线段树优化Dp)

    Description 有N个村庄坐落在一条直线上,第i(i>1)个村庄距离第1个村庄的距离为Di.需要在这些村庄中建立不超过K个通讯基站,在第i个村庄建立基站的费用为Ci.如果在距离第i个村庄 ...

  9. RLF。HRLF解释

  10. 03004_SQL语句

    1.SQL语法 (1)数据库是不认识JAVA语言的,但是我们同样要与数据库交互,这时需要使用到数据库认识的语言SQL语句,它是数据库的代码: (2)结构化查询语言(Structured Query L ...