Schedule

Problem Description
There are N schedules, the i-th schedule has start time si and end time ei (1 <= i <= N). There are some machines. Each two overlapping schedules cannot be performed in the same machine. For each machine the working time is defined as the difference between timeend and timestart , where time_{end} is time to turn off the machine and timestart is time to turn on the machine. We assume that the machine cannot be turned off between the timestart and the timeend. 
Print the minimum number K of the machines for performing all schedules, and when only uses K machines, print the minimum sum of all working times.
 
Input
The first line contains an integer T (1 <= T <= 100), the number of test cases. Each case begins with a line containing one integer N (0 < N <= 100000). Each of the next N lines contains two integers si and ei (0<=si<ei<=1e9).
 
Output
For each test case, print the minimum possible number of machines and the minimum sum of all working times.
 
最近真的是愈发感觉自己很菜了   很伤感啊....
好不容易感觉有道签到题目可以写  结果写了两个小时  
WA了6发 T了2发  菜的一匹~~~
 
题意:工厂加工零件  问最少能用几个机器 和 机器所用的最少的时间
 
大概是不知道套路吧...等明天看别人的帖子  再学学新的套路
 
就是贪心  但是我只想到了 选择 间距最短的 用一个机器 这样能保证所用的时间最少  
 
但,但是我就是不会写  就很GG
 
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node
{
int st;//记录入点和出点
int flag;//如果是入点就+1,否则就-1
}s[*+]; int L[+],R[+];//记录机器的开始时间 和 结束时间 bool cmp(node a,node b)
{
if(a.st != b.st)
return a.st<b.st;//就是按照端点排序
else
return a.flag < b.flag;//因为区间结束的时候 和另一个区间开始的会重叠
//so 让区间先结束 然后在开始 这样子的吧
} void init()
{
memset(L,,sizeof(L));
memset(R,,sizeof(R));
}
int main ()
{
int t;
scanf("%d",&t);
while (t--)
{
init();
int n;
scanf("%d",&n);
int m=;
for(int i=;i<n;i++)
{
int st,e;
scanf("%d %d",&st,&e);
s[m].st = st,s[m++].flag=;//左端点+1
s[m].st = e,s[m++].flag=-;//右端点-1
}
sort(s,s+m,cmp);
int sum=,ans=;
for(int i=;i<m;i++)
{
sum+=s[i].flag;
if(sum>ans)
{
ans = sum;
L[sum] = s[i].st;
}
}
sum=,ans=;
for(int i=m-;i>=;i--)
{
sum-=s[i].flag;
if(sum>ans)
{
ans = sum;
R[sum] = s[i].st;
}
}
ll res=;
for(int i=;i<=ans;i++)
{
res += (R[i]-L[i]);
}//因为最后就是R-L 所以这里不用管 R[i]和L[i]是否对应
cout<<ans<<" "<<res<<endl;
}
}
 上面真的是 奇思妙想  
下面这个才是 真正模拟的吧   可惜 我贪心大概只会sort  会一丢丢priority_queue  没写过用set的题 果然见识太短
不好
 
#include<bits/stdc++.h>
using namespace std;
struct node{
int l,r;
bool operator <(const node a)const{
return l<a.l;
}
}seg[];
multiset<int>s;
multiset<int>::iterator it;
int main()
{
int t;
scanf("%d",&t);
while (t--)
{
s.clear();
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d %d",&seg[i].l,&seg[i].r);
}
int ans = ;//记录所用机器数量
long long res = ;//记录时间
sort(seg,seg+n);
for(int i=;i<n;i++)
{
it = s.upper_bound(seg[i].l);//寻找 >= seg[i].l 的r
if(it == s.begin())
{
ans++; //找不到 就重新开一个机器
res += seg[i].r - seg[i].l;
s.insert(seg[i].r);
continue;
}
it--;//这里就是离该i区间的起始点最近的 结束点
res += seg[i].r - *it;//把该i区间的结束点 接上上个结束点 这样就不用管 起始点在哪里了
s.erase(it);//把当前区间结束点删除
s.insert(seg[i].r);//重新更新
}
cout<<ans<<" "<<res<<endl;
}
}

hdu 6180 Schedule的更多相关文章

  1. 2017多校第10场 HDU 6180 Schedule 贪心,multiset

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并 ...

  2. HDU - 6180:Schedule(简单贪心)

    There are N schedules, the i-th schedule has start time s i  si and end time e i  ei (1 <= i < ...

  3. Schedule HDU - 6180 (multiset , 贪心)

    There are N schedules, the i-th schedule has start time si and end time ei (1 <= i <= N). Ther ...

  4. hdu 1534 Schedule Problem (差分约束)

    Schedule Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. hdu 6180贪心

    题意:有m个工程,一台机器在同一时间只能运行一个工程,告诉你每个工程的起始时间和结束时间,求出最少要多少个机器以及最小的机器总运行时间(机器开始了就不能停了,直到用完该台机器才停止). 题解:由于这里 ...

  6. HDU 3572 Task Schedule(拆点+最大流dinic)

    Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  8. hdu 3572 Task Schedule 网络流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3572 Our geometry princess XMM has stoped her study i ...

  9. hdu 1150 Machine Schedule 最少点覆盖

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

随机推荐

  1. webpack笔记二——entry

    entry是输入目录文件,有三种形式 1.对象键值对形式 entry: { main: './src/script/main.js', b: './src/script/b.js' }, 注意的是输出 ...

  2. 【Pyton】【小甲鱼】爬虫

    一.什么是爬虫? 可以理解为一只蜘蛛,在不同的网页上爬来爬去,获取我们需要的资源 二.Python如何访问互联网 urllib(一个包)=url(网页地址)+lib() 第一部分:protocol:/ ...

  3. CentOS工作内容(三)配置网络IP地址

    CentOS工作内容(三)配置网络IP地址 用到的快捷键 tab 自动补齐(有不知道的吗) ctrl+a 移动到当前行的开头(a ahead) ctrl+u 删除(剪切)此处至开始所有内容 vim 末 ...

  4. 如何修改WordPress网站默认登录地址wp-admin

    使用过WordPress程序建网站的学员都知道,我们使用Wordpress建好的网站,它的网站登录后台就是“网站域名/wp-admin”.如下图: 为了网站安全,如何修改Wordpress网站默认登录 ...

  5. 跟我学Makefile(七)

    定义模式规则 使用模式规则来定义一个隐含规则.一个模式规则就好像一个一般的规则,只是在规则中,目标的定义需要有“%”字符.“%”的意思是表示一个或多个任意字符.在依赖目标中同样可以使用“%”,只是依赖 ...

  6. Python中使用中文正则表达式匹配指定的中文字符串

    业务场景: 从中文字句中匹配出指定的中文子字符串 .这样的情况我在工作中遇到非常多, 特梳理总结如下. 难点: 处理GBK和utf8之类的字符编码, 同时正则匹配Pattern中包含汉字,要汉字正常发 ...

  7. 【Cocos2dx 3.3 Lua】导出Cocos2dx API文档

    一.Doxygen导出Cocos2dx html doc              1.1 打开Doxygen软件,选择 File-->Open打开Cocos2dx docs目录下的doxyge ...

  8. memset函数使用方法

    将s所指向的某一块内存中的每个字节的内容全部设置为ch指定的ASCII值, 块的大小由第三个参数指定,这个函数通常为新申请的内存做初始化工作, 其返回值为指向S的指针. 需要的头文件 在C中 < ...

  9. 【剑指Offer学习】【面试题3 :二维数组中的查找】

    package 二维数组查找; public class Test03 { /** * 在一个二维数组中,每一行都按 package 二维数组查找; public class Test03 { /** ...

  10. Shell篇(三)TC Shell

    Shell脚本的首行一般写为"#!+路径"来告诉系统,以路径所指定的程序来解释此脚本. 可以写为 #! /bin/tcsh -f (-f表示快速启动,不启动~/.tcshrc) S ...