驼峰数
来源:互联网 发布:小米6 4g网络 编辑:程序博客网 时间:2024/04/30 11:53
/**
* The problem:
* 从一列数中筛除尽可能少的数使得从左往右看,这些数是从小到大再从大到小的
*
#include <stdio.h>
#define MAX_NUM (1U<<31)
int
main()
{
int i, n, low, high, mid, max;
printf("Input how many numbers there are: ");
scanf("%d/n", &n);
/* a[] holds the numbers, b[i] holds the number of increasing numbers
* from a[0] to a[i], c[i] holds the number of increasing numbers
* from a[n-1] to a[i]
* inc[] holds the increasing numbers
* VLA needs c99 features, compile with -stc=c99
*/
double a[n], b[n], c[n], inc[n];
printf("Please input the numbers:/n");
for (i = 0; i < n; ++i) scanf("%lf", &a[i]);
// update array b from left to right
for (i = 0; i < n; ++i) inc[i] = (unsigned) MAX_NUM;
//b[0] = 0;
for (i = 0; i < n; ++i) {
low = 0; high = i;
while (low < high) {
mid = low + (high-low)*0.5;
if (inc[mid] < a[i]) low = mid + 1;
else high = mid;
}
b[i] = low + 1;
inc[low] = a[i];
}
// update array c from right to left
for (i = 0; i < n; ++i) inc[i] = (unsigned) MAX_NUM;
//c[0] = 0;
for (i = n-1; i >= 0; --i) {
low = 0; high = i;
while (low < high) {
mid = low + (high-low)*0.5;
if (inc[mid] < a[i]) low = mid + 1;
else high = mid;
}
c[i] = low + 1;
inc[low] = a[i];
}
max = 0;
for (i = 0; i < n; ++i )
if (b[i]+c[i] > max) max = b[i] + c[i];
printf("%d number(s) should be erased at least./n", n+1-max);
return 0;
}
0 0
- 驼峰数
- Python实现一些简单的算法(4)—将一个字符串转成驼峰数
- 驼峰字符串
- java驼峰转下划线,下划线转驼峰
- 驼峰拼写法(CamelCase)
- 驼峰命名法(camelCase)
- Java 驼峰式命名!
- 驼峰法命名
- 驼峰命名法
- 驼峰字符串删除
- 驼峰式命名法则
- 驼峰命名法总结
- 驼峰式命名法
- 下划线和驼峰转换
- java驼峰转下划线
- 驼峰式命名法
- JSON 驼峰转下划线
- 驼峰命名法
- Awesome Chrome 插件集锦
- Day 12-02 表单的重复提交&验证码重复提交
- 研究生总结
- react native的hello world项目
- Hibernate框架利用inverse属性提高系统性能
- 驼峰数
- ajax(五)
- 阶乘之和
- nodejs开发——express框架学习
- Object类学习之equals方法重写
- MongoDB介绍
- [leetcode]137. Single Number II
- leecode 解题总结:22. Generate Parentheses
- 简单的snake小游戏