在 OS X 中安裝 GNU GCC 以及使用 bits/stdc++.h 头文件 Policy-Based Data Structure

本文介绍如何在OSX环境中使用bits/stdc++头文件快速引入C++标准库,并展示了Policy-Based Data Structure (PBDS) 的应用实例,特别是树结构实现STL map的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

系统环境

OS X:10.9

Homebrew: 0.9.5

Xcode : 5.0.2


#include <bits/std ++>相当于引入下面所有的标准函数库

#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>


程序快速编辑模板:

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

int main() { _

	return 0;
}
pb_ds: 全名[Policy-Based Data Structure]包含了各种容器,如tree 、hash table、heap以及list等结果
tree 实现STL map的范例
#include <iostream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


using namespace std;
using namespace __gnu_pbds;


typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> map_t;


int main() {
	int n;
	while (~scanf("%d", &n)) {
		map_t s;


		for (int i = 0; i < n; ++i) {
			int k, v;
			scanf("%d %d", &k, &v);
			s.insert(pair<int, int>(k, v));
		}


		for (int i = 0; i < n; ++i) {
			printf("%d: %d\n", s.find_by_order(i)->first, s.find_by_order(i)->second);
		}
	}
	return 0;
}
原博客地址:http://blog.kuoe0.tw/posts/2014/01/31/install-gnu-gcc-on-os-x-and-use-the-header-bits-stdcplusplus-h-and-policy-based-data-structure/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值