线性筛素数
for(ll i = 2; i <= n; ++i)
{
if(!Bol[i])
{
prim[++t] = i;
Bol[i] = 1;
}
for(ll j = 1; prim[j] * i <= n && j <= t; ++j)
Bol[i * prim[j]] = 1;
}
快读
inline ll read()
{
ll x = 0, r = 1; char c = getchar();
while(c < '0' || c > '9'){if(c == '-')r = -1;c = getchar();}
while('0' <= c && c <= '9')x = x * 10 + c - 48, c = getchar();
return x * r;
}
快输
void write(ll k)
{if(k > 9)write(k / 10); putchar(k % 10 + '0');}
快速幂
int power(int a,int b)
{
int Ans = 1;
a = a % mod;
while(b)
{
if(b & 1) Ans = (ll) Ans * a % mod;
a = (ll)a * a % mod;
b >>= 1;
}
return Ans;
}
随机(初始化)
#include<ctime>
srand(time(0));
对拍
#include<windows.h>
#include<cstdio>
#include<ctime>
void dp()
{
while(1)
{
system("dat.exe");
double st1=clock(); system("A.exe"); double ed1=clock();
double st2=clock(); system("T1.exe");double ed2=clock();
if(system("fc T1.txt 1.txt"))
{
printf("WA");
return;
}
else printf("AC time1:%0.2lf ms time2:%0.2lf ms\n",ed1-st1, ed2 - st2);
if(ed1 - st1 >= 1000 || ed2 - st2 >= 1000)
{printf("TLE\n"); return;}
}
}
int main()
{
dp();
}
q u e u e queue queue
主要是想记录一下大、小根堆的写法
库
#include<queue>
定义
priority_queue<int> p;//大根堆
priority_queue<int,deque<int>,greater<int> > q;//小根堆
结构体堆
struct wh
{
int end, num;
bool const operator <(const wh i)const
{
return i.end < end;
}
};
m a p map map
本蒟蒻可能会有讲错的
望各位 d a l a o dalao dalao谅解
库
#include<map>
一般用法
实质跟数组差不多
定义
map<string,string>A;
第一个变量为下标变量
比如
i
n
t
int
int
那就是
A
[
1
]
A[1]
A[1]、
A
[
2
]
A[2]
A[2]等
s
t
r
i
n
g
string
string
那就是
A
[
"
M
a
p
l
e
"
]
A["Maple"]
A["Maple"]、
A
[
"
M
"
]
A["M"]
A["M"]等
第一个变量为此数组的类型
比如
<
i
n
t
,
i
n
t
>
<int,int>
<int,int>
那就是
A
[
1
]
=
1
A[1]=1
A[1]=1、
A
[
2
]
=
2
A[2]=2
A[2]=2等
<
s
t
r
i
n
g
,
s
t
r
i
n
g
>
<string,string>
<string,string>
那就是
A
[
"
M
a
p
l
e
"
]
=
"
M
a
p
l
e
"
A["Maple"]="Maple"
A["Maple"]="Maple"、
A
[
"
M
"
]
=
"
M
"
A["M"]="M"
A["M"]="M"等
当你放一个下标上去
如果它检测到没有过就开一个
且内容为空