跳到正文

个人记录

TRICK

我太强了约 6 分钟
原文
文章信息与版本

文章信息

发布
2019年11月10日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 6 分钟

版本

  1. v1当前

1.\large\color{grey}{1.}将一个数除以 d 并向下取整的本质就是去掉这个数在 d 进制下的最后一位

区间与除法让我惊觉,这不就是初赛手算进制转换的过程吗!

2.\large\color{grey}{2.}发现一个奇妙的东西”~i”,只有在i=-1的时候才是0

C++
for(int i=-3;i<=3;i++) printf("%d %d\n",i,~i);
    -3 2
    -2 1
    -1 0
    0 -1
    1 -2
    2 -3
    3 -4  

3.\large\color{grey}{3.}是矩形面积交的计算

4.\large\color{grey}{4.}long double要用**“%Lf”**输出,不是”%llf”

5.\large\color{grey}{5.} double类型用memset会死,需要for循环赋初值

C++
#include<bits/stdc++.h>
#define o 2005
using namespace std;
double dp[o];
signed main() 
{ 
	memset(dp,0x3f,sizeof(dp)); 
	cout<<dp[1]<<endl;
	printf("%lf\n\n",dp[2]);
	
	memset(dp,0x7f,sizeof(dp));
	cout<<dp[1]<<endl;
	printf("%lf\n\n",dp[2]);
	
	memset(dp,0,sizeof(dp));
	cout<<dp[1]<<endl;
	printf("%lf\n\n",dp[2]);
	
	memset(dp,-1,sizeof(dp));
	cout<<dp[1]<<endl;
	printf("%lf\n\n",dp[2]);
	return 0;
} 

ctrl+C ctrl+V F11后会发现赋值赋成垃圾

6.\large\color{grey}{6.} 树上大度数枚举的优化

7.\large\color{grey}{7.} 是我用的对拍板子

C++
#include<iostream>
#include<windows.h>
using namespace std;
int main()
{
  int t=200;
  while(1)
  {
      t--;
      system("data.exe > data.txt");
      system("mine.exe < data.txt > mine.txt");
       system("test.exe < data.txt > test.txt");
      if(system("fc test.txt mine.txt"))  
  	{ 
  		system("data.txt > error.txt");
  		break;
  	} 
  }
  if(t==0) cout<<"no error"<<endl;
  else cout<<"error"<<endl;
  system("pause");
  return 0;
}

8.\large\color{grey}{8.} rand()在不同系统下范围不同

C++
#include<cstdlib> //rand()在这里面
#include<ctime> //顺便,记得srand(time(0));
#ifdef unix
	key=rand();//linux下rand()最大2147483647 
#else
	key = (rand()<<15)+rand();//windows下rand()最大32747 
#endif

9.\large\color{grey}{9.} 网络流要记得cnt赋初值为1

10.\large\color{grey}{10.} lg[0]要记得赋初值为-1

11.\large\color{grey}{11.}priority_queue要写成

C++
struct cmp
{ 
  inline bool operator()(int a,int b) const
  { 
  	return xxxxx
  } 
};//别忘了这个分号!!!
std::priority_queue<int,std::vector<int>,cmp>q;

12.\large\color{grey}{12.}设Fibonacci 数列的前 n 项和为 S(n) ,那么S(n) = F(n+2) -1

13.\large\color{grey}{13.}

C++
memset(dis,0x3f,sizeof(dis));//dis的值是0x3f3f3f3f——四个3fqwq
C++
long long ans=0x3f3f3f3f3f3f3f3f;
//long long范围内的无穷大,近似于(max long long/2)的大小——八个3f

14.\large\color{grey}{14.}避免模拟退火超时

C++
signed main() 
{ 
	int tim=clock();
	//sddshsdahdssdihsisdahdsad......
	while(tim-time()<=CLOCKS_PER_SEC*0.8) sa();
    //或者while ((double)clock()/CLOCKS_PER_SEC<MAX_TIME) SA();max_time自定义
	return 0;
} 

而sa()里面

C++
else if (exp(-Delta/t)*RAND_MAX>rand()) x=X,y=Y; //概率接受是写'>'

15.\large\color{grey}{15.} 二进制集合枚举子集

C++
for (int i = s; i; i = (i - 1) &s)

i - 1使得末尾的0全部变成1,但是由于&s,原来是0的位无论如何也不会变成1,原来是1的位就形成了不断-1的模式。 不包含空集情况,还需要单独处理

原文