堆的判断(1098)
来源:互联网 发布:软件设计师资格证书 编辑:程序博客网 时间:2024/05/16 18:52
编写程序判断以下给出的整数序列是否为最小堆。
Description:
第一行是元素的个数n,第二行是n个整数序列。
Input
如果是小根堆,输出Yes,否者输出No。
Output
Sample Input
1 No
代码
#include<iostream> #include<algorithm> #include<cmath> #include<cstring> using namespace std; bool Judge(int a[],int n) { int i; for (i = 1; i < ceil(n / 2);i++) if ((a[i]>a[i * 2] && 2 * i<n) || (a[i]>a[i * 2 + 1] && (2 * i + 1) < n)) return false; return true; } int main() { int i, n, a[100]; cin >> n; for(i = 1; i <= n; i++) cin >> a[i]; if (Judge(a, n)) cout << "Yes"; else cout << "No"; }
阅读全文
0 0
- 堆的判断(1098)
- 关于堆的判断
- 关于堆的判断 (堆+map)
- 【数据结构_堆_1098】堆的判断
- codevs 2879 堆的判断
- 堆判断
- PAT L2-012. 关于堆的判断(最小堆调整)
- PAT L2-012. 关于堆的判断(堆)
- L2-012. 关于堆的判断 (堆操作)
- GPLT L2-012. 关于堆的判断【建堆】
- C4top-关于堆的判断 (最小堆)
- 如何判断栈、堆的增长方向?
- L2-012. 关于堆的判断
- CCCC初赛 关于堆的判断
- 关于堆的判断 (25分)
- 关于堆的判断 (小顶堆)
- L2-012. 关于堆的判断
- L2-012. 关于堆的判断
- 服务器配置
- Matlab图形绘制经典案例 (2)
- <NOIP> 20 . P1598 垂直柱状图
- tp3.2中三表联查(join和 left join)
- 只包含因子2 3 5的数 51nod1010
- 堆的判断(1098)
- nio3
- netty之Future和ChannelFuture
- C++下的Date类编写
- 58. Length of Last Word
- 10. 电池曲线
- iOS 手势
- GO语言多值返回
- PagingAndSortingRepository