zoukankan      html  css  js  c++  java
  • A1155 Heap Paths [堆的dfs]

    在这里插入图片描述

    #include<iostream>
    #include<vector>
    #include<map>
    #include<string>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    #include<set>
    #include<queue>
    #include<unordered_map>
    #include<cmath>
    using namespace std;
    const int maxn = 1001;
    int n; vector<int>v;int a[maxn];
    void dfs(int index)
    {
    	if (index * 2 > n&& index * 2 + 1 > n)
    	{
    		if (index <= n)
    		{
    			for (int i = 0; i < v.size(); i++)
    			{
    				cout << v[i];
    				if (i != v.size() - 1) cout << " ";
    				else cout << endl;
    			}
    		}
    	}
    	else
    	{
    		v.push_back(a[index * 2 + 1]);	
    		dfs(index * 2 + 1);
    		v.pop_back();
    		v.push_back(a[index * 2]);
    		dfs(index * 2);
    		v.pop_back();
    	}
    }
    int main()
    {	
    	cin >> n;
    	for (int i = 1; i <= n; i++)
    	{
    		cin >> a[i];
    	}
    	int maxh = 1, minh = 1;
    	for (int i = 2; i <= n; i++)
    	{
    		if (a[i] > a[i / 2]) maxh = 0;
    		if (a[i] < a[i / 2])  minh = 0;
    	}
    	v.push_back(a[1]);
    	dfs(1);
    	if (maxh)
    	{
    		cout << "Max Heap";
    	}
    	else if (minh)
    	{
    		cout << "Min Heap";
    	}
    	else
    	{
    		cout << "Not Heap";
    	}
    }
    
  • 相关阅读:
    微服务配合docker使用
    基于docker部署使用ELK+FileBeat日志管理平台
    Ubuntu开发用新机安装流程
    http 直接从body里传输数据
    005
    003
    004
    001
    002
    谷歌查看、管理cookie
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13811944.html
Copyright © 2011-2022 走看看