TRICK

· · 个人记录

[区间与除法](https://www.luogu.org/blog/sy2330/AFOI-cp-solution-for-T4)让我惊觉,这不就是初赛手算进制转换的过程吗! $\large\color{grey}{2.}$发现一个奇妙的东西"~i",只有在i=-1的时候才是0 ```cpp 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 ``` $\large\color{grey}{3.}$是矩形面积交的计算 ![](https://cdn.luogu.com.cn/upload/image_hosting/popxzj0k.png) $\large\color{grey}{4.}$long double要用**"%Lf"**输出,**不是"%llf"** $\large\color{grey}{5.}

double类型用memset会死,需要for循环赋初值

#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后会发现赋值赋成垃圾

![](https://cdn.luogu.com.cn/upload/image_hosting/g487bjfk.png) $\large\color{grey}{7.}$ 是我用的对拍板子 ```cpp #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; } ``` $\large\color{grey}{8.}$ rand()在不同系统下范围不同 ```cpp #include<cstdlib> //rand()在这里面 #include<ctime> //顺便,记得srand(time(0)); #ifdef unix key=rand();//linux下rand()最大2147483647 #else key = (rand()<<15)+rand();//windows下rand()最大32747 #endif ``` $\large\color{grey}{9.}$ 网络流要记得cnt赋初值为1 $\large\color{grey}{10.}$ lg[0]要记得赋初值为-1 $\large\color{grey}{11.}$priority_queue要写成 ```cpp struct cmp { inline bool operator()(int a,int b) const { return xxxxx } };//别忘了这个分号!!! std::priority_queue<int,std::vector<int>,cmp>q; ``` $\large\color{grey}{12.}$设Fibonacci 数列的前 n 项和为 S(n) ,那么S(n) = F(n+2) -1 $\large\color{grey}{13.}
memset(dis,0x3f,sizeof(dis));//dis的值是0x3f3f3f3f——四个3fqwq
long long ans=0x3f3f3f3f3f3f3f3f;
//long long范围内的无穷大,近似于(max long long/2)的大小——八个3f
```cpp 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()里面 ```cpp else if (exp(-Delta/t)*RAND_MAX>rand()) x=X,y=Y; //概率接受是写'>' ``` $\large\color{grey}{15.}$ 二进制集合枚举子集 ```cpp for (int i = s; i; i = (i - 1) &s) ``` i - 1使得末尾的0全部变成1,但是由于&s,原来是0的位无论如何也不会变成1,原来是1的位就形成了不断-1的模式。 不包含空集情况,还需要单独处理