小记

  • 求某年第一天是星期几
 int firstday(int year){     //求某一年第一天是星期几
     return ( (year-1)+(year-1)/4-(year-1)/100+(year-1)/400+1 )%7;
 }
  • 完全平方数性质

  若存在a=b^2,则a为完全平方数。完全平方数的任何一个质因子,都是偶次出现的--acwing3491

  • 异或运算交换两数(a,b的值可以相同,地址不能相同)

  a=a^b;

  b=a^b;

  a=a^b;

  • 求数字x的位数:log10(x)+1;以10为底
  • 提取某数二进制中最右边的1

  int rightOne=eor&(~eor+1);

 

  • 防止数据过大求a,b中点

  a + ( ( b - a ) >> 1 );

  // 二进制右移一位相当于除以二

 

  • heapInsert 是从下往上移动到合适位置.  父位置为 (i-1)/2;
  • 堆结构 比 堆排序  重要
  •  迭代器:for(set<int>::iterator i=all.begin();i!=all.end();i++)    cout<<*i<<endl;
  • vector,set,map,unordered_set,,unordered_map可以用迭代器    stack,queue不可以用迭代器,stack栈 只可以访问栈顶,queue只能访问队首,队尾.
  • std::ios::sync_with_stdio(false);     //可以取消cin于stdin的同步,加快其cin cout的速度,但之后避免使用scanf和printf
  • 哈希表 HashSet<Node> Node是自己定义的类型,那么将传递的时候,将是直接传递地址(HashSet.insert(NodeA)),而基础类型只是值传递   
  •  二叉搜索树定义:左树比根小,右树比根大  即(中序遍历的结果为从小到大有序的数组)
  • 比较器java

  //返回负数时,第一个传入的参数排在前面

  //返回正数时,第二个传入的参数排在前面

  //返回0时,谁在前面都无所谓

  例如:在自定义类型中

typedef struct Student{
    int point;
    string name;
}student;

int comparator(student s1,student s2)
{
    return s1.point-s2.point;  //即按point 由小到大排序
    //等价于
    /* if(s1.point>s2.point){
        return -1;
    }
        if(s2.point<s1.point){
            return 1;
        }
        return 0; //等于时 */
}
  • 重载运算符
  •  

  

posted @ 2023-03-21 21:37  osir  阅读(1)  评论(0编辑  收藏  举报