C++学习注意点

1.cin,cout关同步再用,不然效率很糟cin,cout关同步再用,不然效率很糟cin,cout关同步再用,不然效率很糟。重要的事情说三遍。关同步代码:std::ios::sync_with_stdio(false);

2.判断相等是==是==是==。我就因为这个卡了好多次。

3.给数组整体赋初值:memset(a,0,sizeof(a)); 头文件为string.h或memory.h

4.文件操作 freopen("xx.in","r",stdin); freopen("xx.out","w",stdout); 头文件为cstdio

5.读入BT优化:

const int MAXN = 10000000;
const int MAXS = 60*1024*1024;

int numbers[MAXN];
char buf[MAXS];

void fread_analyse()
{
freopen("data.txt","rb",stdin);
int len = fread(buf,1,MAXS,stdin);
buf[len] = '/0';
analyse(buf,len);

}

6.STL中快排什么的定义">"或"<"号,其实都一样

bool cmp(int a,int b)

{

  return a>b;

}

7.关于带stable_的函数和不带的

   带有stable的函数可保证相等元素的原本相对次序在排序后保持不变

8.各种各样的头文件

 

#include <algorithm> //STL 通用算法
#include <bitset> //STL 位集容器
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex> //复数类
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque> //STL 双端队列容器
#include <exception> //异常处理类
#include <fstream>
#include <functional> //STL 定义运算函数(代替运算符)
#include <limits>
#include <list> //STL 线性列表容器
#include <map> //STL 映射容器
#include <iomanip>
#include <ios> //基本输入/输出支持
#include <iosfwd> //输入/输出系统使用的前置声明
#include <iostream>
#include <istream> //基本输入流
#include <ostream> //基本输出流
#include <queue> //STL 队列容器
#include <set> //STL 集合容器
#include <sstream> //基于字符串的流
#include <stack> //STL 堆栈容器
#include <stdexcept> //标准异常类
#include <streambuf> //底层输入/输出支持
#include <string> //字符串类
#include <utility> //STL 通用模板类
#include <vector> //STL 动态数组容器
#include <cwchar>
#include <cwctype>

posted @ 2016-01-19 10:36  Eggsy  阅读(241)  评论(0编辑  收藏  举报