POJ 1769 Minimizing maximizer
来源:互联网 发布:mac重置管理员账户 编辑:程序博客网 时间:2024/05/22 12:36
Description
The company Chris Ltd. is preparing a new sorting hardware called Maximizer. Maximizer has n inputs numbered from 1 to n. Each input represents one integer. Maximizer has one output which represents the maximum value present on Maximizer's inputs.
Maximizer is implemented as a pipeline of sorters Sorter(i1, j1), ... , Sorter(ik, jk). Each sorter has n inputs and n outputs. Sorter(i, j) sorts values on inputs i, i+1,... , j in non-decreasing order and lets the other inputs pass through unchanged. The n-th output of the last sorter is the output of the Maximizer.
An intern (a former ACM contestant) observed that some sorters could be excluded from the pipeline and Maximizer would still produce the correct result. What is the length of the shortest subsequence of the given sequence of sorters in the pipeline still producing correct results for all possible combinations of input values?
Task
Write a program that:
reads a description of a Maximizer, i.e. the initial sequence of sorters in the pipeline,
computes the length of the shortest subsequence of the initial sequence of sorters still producing correct results for all possible input data,
writes the result.
Maximizer is implemented as a pipeline of sorters Sorter(i1, j1), ... , Sorter(ik, jk). Each sorter has n inputs and n outputs. Sorter(i, j) sorts values on inputs i, i+1,... , j in non-decreasing order and lets the other inputs pass through unchanged. The n-th output of the last sorter is the output of the Maximizer.
An intern (a former ACM contestant) observed that some sorters could be excluded from the pipeline and Maximizer would still produce the correct result. What is the length of the shortest subsequence of the given sequence of sorters in the pipeline still producing correct results for all possible combinations of input values?
Task
Write a program that:
reads a description of a Maximizer, i.e. the initial sequence of sorters in the pipeline,
computes the length of the shortest subsequence of the initial sequence of sorters still producing correct results for all possible input data,
writes the result.
Input
The first line of the input contains two integers n and m (2 <= n <= 50000, 1 <= m <= 500000) separated by a single space. Integer n is the number of inputs and integer m is the number of sorters in the pipeline. The initial sequence of sorters is described in the next m lines. The k-th of these lines contains the parameters of the k-th sorter: two integers ik and jk (1 <= ik < jk <= n) separated by a single space.
Output
The output consists of only one line containing an integer equal to the length of the shortest subsequence of the initial sequence of sorters still producing correct results for all possible data.
Sample Input
40 620 301 1010 2020 3015 2530 40
Sample Output
4
Hint
Huge input data, scanf is recommended.
题意:给你m条线段,让你按照顺序选择其中的一些线段,使得从左到右覆盖1-n,问至少选多少条线段。
题意:给你m条线段,让你按照顺序选择其中的一些线段,使得从左到右覆盖1-n,问至少选多少条线段。
#include<iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<algorithm>using namespace std;const int maxn=500000+10;const int INF=100000000;struct node{int l,r;int minn;node(){l=0;r=0;minn=INF;}};struct node tree[maxn];void create_tree(int h,int x,int y){tree[h].l=x;tree[h].r=y;if(x==y)return;int mid=(x+y)/2;create_tree(h*2,x,mid);create_tree(h*2+1,mid+1,y);}void update(int h,int pos,int date){if(tree[h].l==pos && tree[h].r==pos){tree[h].minn=min(tree[h].minn,date);return;}int mid=(tree[h].l+tree[h].r)/2;if(pos<=mid)update(h*2,pos,date);elseupdate(h*2+1,pos,date);tree[h].minn=min(tree[h*2].minn,tree[h*2+1].minn);}int dfs(int h,int x,int y){if(tree[h].r<x || tree[h].l>y)return INF;if(tree[h].l>=x && tree[h].r<=y)return tree[h].minn;return min(dfs(h*2,x,y),dfs(h*2+1,x,y));}int main(){int i,k,n,m,x,y;scanf("%d%d",&n,&m);create_tree(1,1,n);update(1,1,0);for(i=1;i<=m;i++){scanf("%d%d",&x,&y);k=dfs(1,x,y)+1;if(dfs(1,y,y)>k)update(1,y,k);}printf("%d\n",dfs(1,n,n));return 0;}
0 0
- POJ 1769 Minimizing maximizer
- POJ 1769 Minimizing maximizer
- POJ 1769 Minimizing maximizer
- POJ 1769 Minimizing maximizer
- POJ 1769 Minimizing maximizer 笔记
- poj 1769 Minimizing maximizer(线段树&dp)
- Minimizing maximizer - POJ 1769 dp+线段树
- poj 1769 Minimizing maximizer 线段树
- poj 1769 Minimizing maximizer 线段树优化的dp
- POJ 1769 Minimizing maximizer (dp + 线段树)
- poj 1769 Minimizing maximizer 单点更新线段树
- POJ 1769 Minimizing maximizer(最少区间覆盖dp + 线段树优化查询区间最小值)
- Minimizing Maximizer UVA
- POJ 1769_Minimizing maximizer
- zoj2451-Minimizing maximizer(线段树,超时)
- poj1769 Minimizing maximizer线段树优化dp
- #Poj1769#Minimizing maximizer(Dp+线段树优化)
- UVALive 2930 Minimizing Maximizer(最小区间覆盖数 DP + 线段树优化)
- DDL,DML,DCL,TCL四种语言的简介
- oracle取数字,替换字符,查询树形结构,(+)
- java String运算符+反编译
- HTML 拖拽效果
- 1912: 小火山的爱情密码 (尺取比二分果然更有优势)
- POJ 1769 Minimizing maximizer
- 总结系列-LayoutInflater的inflate函数用法详解
- 分布式任务调度中间件SchedulerX
- Cocos2d-x的学习 触碰事件老版本和新版本的对比 第二节
- Android实现通过浏览器点击链接打开本地应用(APP)并拿到浏览器传递的数据
- java大整数比大小
- 初学c/c++——提及文件操作
- yii 2.0 安装
- struts标签--logic总结