Common Knowledge
2014-08-23 11:01:11
-6:四面体
(1)内切球半径:r = 3V / (S1+S2+S3+S4)
(2)体积:将四点组成三个向量AB,AC,AD,向量的混合积就是它们组成的平行六面体的体积,四面体体积是其体积的1/6。

-5:枚举一个集合(设为s)的所有超集,总共N个物品。(ts为集间差)
for(int f = s; f < ( << N); f = (f + ) | s){
int ts = s ^ f;
}
-4:枚举一个集合(设为s)的所有非空子集,总共N个物品。(ts为集间差),注意空集需要另外讨论。
for (int f = s; f > ; f = (f - ) & s) {
int ts = s ^ f;
}
-2:头文件便利贴(C++11)
#include <bits/stdc++.h>
using namespace std; #define getmid(l,r) ((l) + ((r) - (l)) / 2)
#define MEM(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define PB push_back typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-;
const int INF = ( << ) - ;
const int MAXN = ; int main(){ return ;
}
-3:头文件便利贴
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std; #define getmid(l,r) ((l) + ((r) - (l)) / 2)
#define MEM(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define PB push_back typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-;
const int INF = ( << ) - ;
-1:vim配置文件
set nu ci si ai mouse=a ts= sts= sw= cursorline
0:数论
(1)计算比m小,且与m互质的的正整数的和:phi(m)*m/2
(2)计算比m小,且与m不互质的正整数的和:(phi(m)+1)*m/2
(3)同余符号: ≡
(4)1和任何数都成倍数关系,但和任何数都互质。
1:运算符优先级

2:素数定理

3:反素数表
1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260,1680,2520,5040,7560,10080,15120,20160,25200,27720,45360,50400,55440,83160,110880,166320,221760,277200,332640,498960,554400
4:点旋转坐标公式:
任意点(x,y),绕一个坐标点(rx0,ry0)逆时针旋转a角度后的新的坐标设为(x0, y0),有公式:
x0= (x - rx0)*cos(a) - (y - ry0)*sin(a) + rx0 ;
y0= (x - rx0)*sin(a) + (y - ry0)*cos(a) + ry0 ;
5:快速读入:
inline int Read(){
int x = ,f = ;char ch = getchar();
while(ch < '' || ch > ''){if(ch == '-')f = -;ch = getchar();}
while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
return x * f;
}
6:关闭C++读入同步
ios::sync_with_stdio(false);
7:快速输出:
void Write(int v){
if(v>) Write(v/);
putchar(v%+'');
}
8:正无穷
(1)int型边界:const int INF = ~0U >> 1;
9:简洁的组合数打表(from wjmzbmr):
for (int i = ; i < ; ++i) {
for (int j = ; j <= i; ++j) {
comb[i][j] =
(i == || j == ) ?
: (comb[i - ][j] + comb[i - ][j - ]);
}
}
10:循环版求gcd(from tourist)
int gcd(int a, int b) {
while (a > && b > )
if (a > b) a %= b;
else b %= a;
return a + b;
}
11:atoi 和 itoa 函数 参考:博文
● atoi():将字符串转换为整型值。
● atol():将字符串转换为长整型值。
● itoa():将整型值转换为字符串。
● ltoa():将长整型值转换为字符串。
12:卡哈希
参考bzoj题目
13:unique函数的一些注意点:
数组下标从0开始:int sz = unique(a,a + n) - a;
数组下标从1开始:int sz = unique(a + 1,a + n + 1) - a - 1;
14:生成 long long 范围 内的随机数:(不确定是否正确)
val = ((ll)rand() << ) + ((ll)rand() << ) + ;
15:快速预处理阶乘逆元
先求出 (MAXN - 1)! 的逆元,然后倒序依次求出:(MAXN - 2)! ~ 1! 的逆元
注意:如果MAXN - 1 >= mod,那么不能直接这么用。因为 fac[mod] % mod = 0
int fac[MAXN],afac[MAXN];
int Q_pow(int x,int y){
int res = ;
while(y){
if(y & ) res = 1ll * res * x % mod;
x = 1ll * x * x % mod;
y >>= ;
}
return res % mod; //小心模数为1的情况
}
void Pre(){
fac[] = afac[] = ;
for(int i = ; i < MAXN; ++i) fac[i] = 1ll * fac[i - ] * i % mod;
afac[MAXN - ] = Q_pow(fac[MAXN - ],mod - );
for(int i = MAXN - ; i > ; --i) afac[i - ] = 1ll * afac[i] * i % mod;
}
16:内联汇编快速乘法
inline ll mulmod(ll x, ll y, ll mod)
{
ll ret = ;
__asm__("movq %1,%%rax\n imulq %2\n idivq %3\n":"=d"(ret):"m"(x),"m"(y),"m"(mod):"%rax");
return ret;
}
17:扩栈命令
#pragma comment(linker, "/STACK:102400000,102400000")
18:fread 快速读入黑科技
const int BUFSIZE=<<; //根据题目数据而定
char Buf[BUFSIZE+],*buf=Buf;
template<class T>
inline void scan(T&a){
for (a=;*buf<''||*buf>'';buf++);
while (*buf>=''&&*buf<=''){a=a*+(*buf-'');buf++; }
} fread(Buf,,BUFSIZE,stdin); //加到main函数第一行
19:根据日期算星期(基姆拉尔森公式),1~6对应星期一~星期六,0对应星期日
int Cal(int d,int m,int y){
if(m <= ) m += ,y--;
return (d + + * m + * (m + ) / + y + y / - y / + y / ) % ;
}
20:卡特兰数
数列:1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796
h(n)=h(n-1)*(4*n-2)/(n+1);
h(n)=C(2n,n)/(n+1) (n=0,1,2,...)
21:默慈金数
数列:1, 2, 4, 9, 21, 51, 127, 323, 835, 2188, 5798
与卡特兰数的联系:
Common Knowledge的更多相关文章
- Common Knowledge_快速幂
问题 I: Common Knowledge 时间限制: 1 Sec 内存限制: 64 MB提交: 9 解决: 8[提交][状态][讨论版] 题目描述 Alice and Bob play som ...
- sentence patterns
第四部分 推理题 1.世界上每个角落的每个人都有立场,都有背景,都有推理性,能推理出一个人语言的真意,才成就了真正的推理能力: 2.换言之,如果你能通过一个人的说话推理出其身份职业,你的推理能 ...
- jQuery Mobile 脚本加载问题
刚开始使用jQuery Mobile,发现很多问题需要重新考虑,比如脚本加载问题. 在普通html中,如果a.html中有链接到b.html,b.html中有类似代码: $(document).rea ...
- hihocoder 1154 Spring Outing
传送门 #1154 : Spring Outing 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 You class are planning for a spring ...
- debugging books
https://blogs.msdn.microsoft.com/debuggingtoolbox/2007/06/08/recommended-books-how-to-acquire-or-imp ...
- Creating an API-Centric Web Application[转]
Creating an API-Centric Web Application 转自 http://hub.tutsplus.com/tutorials/creating-an-api-centric ...
- How to Analyze Java Thread Dumps--reference
原文地址:http://architects.dzone.com/articles/how-analyze-java-thread-dumps The Performance Zone is pres ...
- Improving Lock Performance in Java--reference
After we introduced locked thread detection to Plumbr couple of months ago, we have started to recei ...
- python 词云学习
词云入门 三步曲 数据获取:使用爬虫在相关网站上获取文本内容 数据清洗:按一定格式对文本数据进行清洗和提取(文本分类,贴标签) 数据呈现:多维度呈现和解读数据(计算,做表,画图) 一 模块的安装 pi ...
随机推荐
- complex()
complex() 用于将一个对象转换为复数 In [1]: complex(123) # 将整数转换为复数 Out[1]: (123+0j) In [2]: complex(') # 将纯数字的字符 ...
- php学习十三:其他关键字
在php中,其实不止在php中,在其他语言中我们也会常常接触到一些关键字,整理了一下php当中的一下关键字,可能有些不全,希望大家指出来,多多交流,一起进步. 1.final 特性:1.使用final ...
- php学习七:时间和日期
在学习php中的时间和日期的时候,必须要了解什么是时间戳,那么什么是时间戳呢,请看一下的定义 时间戳:从 Unix 纪元(格林威治时间 1970 年 1 月 1 日 00:00:00)到当前时间的秒数 ...
- C++异常 异常机制
C++异常是丢程序运行过程中发生的异常情况(例如被0除)的一种响应.异常提供了将控制权从程序的一个部分传递到另一部分的途径.对异常的处理有3个组成部分:* 引发异常:* 使用处理程序捕获异常:* 使用 ...
- http://www.xuexi111.com/
http://www.xuexi111.com/ http://www.minxue.net/ 拼吾爱
- 170705、springboot编程之自定义properties
spring boot使用application.properties默认了很多配置.但需要自己添加一些配置的时候,可以这样用,如下! 在application.properties文件中增加信息 1 ...
- SaltStack生产案例-服务部署(redis,mysql,apache+php,haproxy+keepalived)
顺序代码资料链接 课上资料.zip 接上篇:SaltStack生产案例-系统初始化 1,redis 主从 2,mysql 主从 2.1 mysql-install.sls (安装 初始化) 2.2 ...
- pta 习题集5-6 堆栈操作合法性
假设以S和X分别表示入栈和出栈操作.如果根据一个仅由S和X构成的序列,对一个空堆栈进行操作,相应操作均可行(如没有出现删除时栈空)且最后状态也是栈空,则称该序列是合法的堆栈操作序列.请编写程序,输入S ...
- Excel 26机制转换
[问题描述] 在Excel中,列的名称是这样一个递增序列:A.B.C.….Z.AA.AB.AC.….AZ.BA.BB.BC.….BZ.CA.….ZZ.AAA.AAB….我们需要将上述列名序列和以下自然 ...
- Wormholes---poj3259(最短路 spfa 判断负环 模板)
题目链接:http://poj.org/problem?id=3259 题意是问是否能通过虫洞回到过去: 虫洞是一条单向路,不但会把你传送到目的地,而且时间会倒退Ts. 我们把虫洞看成是一条负权路,问 ...