• 编程要点随记


    大小堆

    #include <vector>
    #include <list>
    #include <algorithm>

    make_heap(m.begin(), m.end(), less<int>());//创建大堆,最大的在第一个(greater是小堆)

    如果新push_back以后(或者一开始就是用push_back),那可以调用一下这句

    push_heap(m.begin(), m.end(), less<int>())

    如果要取出第一个:

    push_heap(m.begin(), m.end(), less<int>());//这样第一个就会被放到最后,再调用pop_back出来就好了

    c++转字符串

    <string>

    string=to_string(xxx)

    分治

      大问题分解成小问题

    递归

      注意递归边界条件

    字符串比较

      strcmp,一样为0

    排序函数调用,sort函数调用

      遇到容器用迭代器begin和end

    #include <algorithm>
    struct data{
        int a;
        int b;
        int val;
    };
    bool comp(data a,data b){
        return a.a*a.b>b.a*b.b;
    }
    sort(datas,datas+10,comp);
    

    内存初始化

    #include <cstring>
    memset(str, 0, sizeof(str));
    

    用数组当作队列简便使用

    二维字符串输入

    char s[N][N]
    for(int i=0;i<n;i++){
        cin>>s[i];      
    }
    

    方向数组

    int zan[4][2]={1,0,0,1,-1,0,0,-1};
    int go[2][8]={{-1,0,1,-1,1,-1,0,1},{-1,-1,-1,0,0,1,1,1}};

    map的使用

    #include<map>
    #include<iostream>
    #include <string>
    using namespace std;
    map<int,string>m;
    int main(){
    	m[1]="111";
    	m[2]="222";
    	map<int,string>::iterator m_i;
    	m_i=m.find(1);
    	if(m_i!=m.end()){
    		cout<<m_i->second<<endl;
    		cout<<m[1]<<endl;
    	}
    	m.erase(m_i);
    	m_i=m.find(1);
    	if(m_i==m.end()){
    		cout<<"没找到
    ";
    	}
    	
    	return 0;
    }
    

     快速求和

    #include <numeric.h>
    int sum = accumulate(vec.begin() , vec.end() , 0);
    

    大数

      long long型,__int64

      输出用lld

    负数二进制

      正数取反再加一  

    欧拉图

      对有向图,所有节点的入度等于出度

    排列组合关系计算

       排列可重复

        

       排列不可重复

      

    三角形面积计算

      待更新  

    点到线的距离计算

      待更新

  • 相关阅读:
    Get distinct count of rows in the DataSet
    单引号双引号的html转义符
    PETS Public English Test System
    Code 39 basics (39条形码原理)
    Index was outside the bounds of the array ,LocalReport.Render
    Thread was being aborted Errors
    Reportviewer Error: ASP.NET session has expired
    ReportDataSource 值不在预期的范围内
    .NET/FCL 2.0在Serialization方面的增强
    Perl像C一样强大,像awk、sed等脚本描述语言一样方便。
  • 原文地址:https://www.cnblogs.com/zhengyuqian/p/10509820.html
Copyright © 2020-2023  润新知