Intervals of Monotonicity
来源:互联网 发布:unity3d 间隔重复执行 编辑:程序博客网 时间:2024/06/05 10:17
1346. Intervals of Monotonicity
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
It’s well known that a domain of any continuous function may be divided into intervals where the function would increase monotonically or decrease monotonically. A number of intervals of such a partition we will call a complexity of the partition. A complexity of a continuous function is the minimal possible complexity of partition in the domain into the monotonicity intervals.
The notion of complexity may be defined not only for continuous functions. In particular, it is applicable to the functions specified on a grid.
Input
The input contains a description of a function F, specified on a grid. The first line contains two numbers A and B — the first and the last point of the integer grid with step 1 (0 ≤ A < B ≤ 100 000). The second line contains the values table of the function F. The table consists of the integers F(A), F(A+1), …, F(B) separated with a space and/or linefeeds. All the values of the function F are in diapason from –100 000 to 100 000.
Output
Output the only number — the complexity of the function F.
Sample
1 101 2 3 4 2 1 -1 3 6 7
3
/**贪心**/#include <cstdio>#include <cstring>#define MAX 100010int a,b,n,pre,m[MAX],dp[MAX];int main(){ while(scanf("%d%d",&a,&b)!=EOF) { n=b-a+1; int i,j; scanf("%d",&m[1]); pre=m[1]; for(i=2,j=2; i<=n; i++)//一开始在这里总是错,原来是严格单调,不能有重复数字 { scanf("%d",&m[j]); if(m[j]!=pre) { pre=m[j]; j++; } } n=j-1; dp[1]=dp[2]=1; for(i=3; i<=n;) { if((m[i]>=m[i-1]&&m[i-1]>=m[i-2]) || (m[i]<=m[i-1]&&m[i-1]<=m[i-2]))//一次判断三个,就可以判断单调性 { dp[i]=dp[i-1]; i++; } else { dp[i]=dp[i-1]+1; dp[i+1]=dp[i]; i+=2; } } printf("%d\n",dp[n]); } return 0;}
- Intervals of Monotonicity
- Timus 1346. Intervals of Monotonicity
- hust Intervals of Monotonicity【条理清晰】
- timus 1346. Intervals of Monotonicity URAL 解题报告 DP 小水题,阅读理解
- BZOJ2090/2089 [Poi2010]Monotonicity 2/Monotonicity
- Intervals
- Intervals
- Intervals
- Intervals
- Intervals
- BZOJ2090 POI2010 Monotonicity
- Poi2010 Monotonicity 2
- [Poi2010]Monotonicity 2
- [Poi2010]Monotonicity 2
- BZOJ2089&2090: [Poi2010]Monotonicity 2
- [Poi2010]Monotonicity 2 线段树
- 最大重叠区间数目 Maximum number of overlapping intervals
- 线段树优化DP [Poi2010]Monotonicity 2
- 重装系统后如何恢复mysql数据
- NYOJ 400题 I'll play a trick on you
- linux下拷贝MySql数据库文件备份数据库
- Can't read proguard.ClassPathEntry@1a0c10f (No such file or directory)
- 如何解决wordpress的更新版本 下载超时的问题
- Intervals of Monotonicity
- Mercurial(hg)
- JS正则表达式详解
- HDU4596 Yet another end of the world(数学公式推演+数论定理--2013南京邀请赛)
- ExpressJs上传文件
- 数据库的连接
- ubuntu 下FTP设置及常用命令
- 磁盘管理——RAID 10
- 跳转(2)-cscope