WOJ1072-Order
来源:互联网 发布:淘宝客佣金查询插件 编辑:程序博客网 时间:2024/05/18 02:55
Knuthocean is a coach of WHUACM team now. One day, he wants to have a meeting with the team members, so he should order a classroom
for the meeting. Classrooms in WHU are lacking, so the administrator must accept some orders and refuse the others to optimize
the classroom's use efficency. If one order is accepted, the time between the start time and the finish time of this order becomes active.
There can be at most one order during each time slice. Because of your capacity in programming, the administator asks you to
find a method to maximize the total active time. Your task is like that:read the orders and calculate the maximal length of the active time.
输入格式
Standard input will contain multiple test cases. For each test case, the first line is a number N,(N<=10000) followed by N lines.
Each line contains two integers, p and k.(1<=p<=k<=300000), where p is the start time and k is the finish time of an order.
输出格式
For each test case, you should output one line containing the maximal length of the active time.
样例输入
41 23 51 44 5
样例输出
5
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define MAX 10001int N,p,k;int dp[MAX];int T[MAX];typedef struct nt {int start,end,length;bool operator < (const nt a)const {if(start == a.start)return a.end > end;elsereturn start < a.start;}} TS;TS node[MAX];int main() {while(scanf("%d", &N) != EOF) {for(int i = 0; i < N; i ++) {scanf("%d %d",&node[i].start, &node[i].end);node[i].length = node[i].end - node[i].start + 1;}stable_sort(node,node+N);memset(dp,0,sizeof(dp));dp[0] = node[0].length;T[0] = node[0].length;for(int i = 1; i < N; i ++) {int s = i - 1;T[i] = node[i].length;int dT = 0;for(; s >=0; s --) {if(node[i].start > node[s].end)dT = max(dT ,T[s]);}T[i] += dT;dp[i] = max(dp[i-1],T[i]);}printf("%d\n",dp[N - 1]) ;}return 0;}
- WOJ1072-Order
- order
- ORDER
- Order
- FS5-Order
- Order Overfill
- Purchase Order
- Sales Order
- Byte order
- Byte order
- order by
- Order Array
- ORDER BY
- Order By
- order by
- Byte Order
- Checking order
- Backlog Order
- Java小代码
- 在创建的物体上播放动画
- PHP 特殊方法 __set()、__get()、__isset() 与 __unset()
- cogs 2079Asm_def的三角形解题报告
- 全局安装cnpm
- WOJ1072-Order
- 字节序(大小端)详解从高低地址和高低位开始理解(转)
- mui:使用js在移动端进行精准定位改进版,以及坐标转换
- C++ 图论-深度与广度遍历
- javaWeb--分页查询
- 【Hibernate】二级缓存(Hibernate默认使用的二级缓存)
- Windows下如何安装Docker
- 集合第二节
- 梦之旅