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:卡哈希

  参考codeforces博文

  参考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的更多相关文章

  1. Common Knowledge_快速幂

    问题 I: Common Knowledge 时间限制: 1 Sec  内存限制: 64 MB提交: 9  解决: 8[提交][状态][讨论版] 题目描述 Alice and Bob play som ...

  2. sentence patterns

    第四部分     推理题 1.世界上每个角落的每个人都有立场,都有背景,都有推理性,能推理出一个人语言的真意,才成就了真正的推理能力: 2.换言之,如果你能通过一个人的说话推理出其身份职业,你的推理能 ...

  3. jQuery Mobile 脚本加载问题

    刚开始使用jQuery Mobile,发现很多问题需要重新考虑,比如脚本加载问题. 在普通html中,如果a.html中有链接到b.html,b.html中有类似代码: $(document).rea ...

  4. hihocoder 1154 Spring Outing

    传送门 #1154 : Spring Outing 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 You class are planning for a spring ...

  5. debugging books

    https://blogs.msdn.microsoft.com/debuggingtoolbox/2007/06/08/recommended-books-how-to-acquire-or-imp ...

  6. Creating an API-Centric Web Application[转]

    Creating an API-Centric Web Application 转自 http://hub.tutsplus.com/tutorials/creating-an-api-centric ...

  7. How to Analyze Java Thread Dumps--reference

    原文地址:http://architects.dzone.com/articles/how-analyze-java-thread-dumps The Performance Zone is pres ...

  8. Improving Lock Performance in Java--reference

    After we introduced locked thread detection to Plumbr couple of months ago, we have started to recei ...

  9. python 词云学习

    词云入门 三步曲 数据获取:使用爬虫在相关网站上获取文本内容 数据清洗:按一定格式对文本数据进行清洗和提取(文本分类,贴标签) 数据呈现:多维度呈现和解读数据(计算,做表,画图) 一 模块的安装 pi ...

随机推荐

  1. 当singleton Bean依赖propotype Bean,可以使用在配置Bean添加look-method来解决

    在Spring里面,当一个singleton bean依赖一个prototype bean,因为singleton bean是单例的,因此prototype bean在singleton bean里面 ...

  2. 计算时间:一个C++运算符重载示例

    Time类是一个用于计算时间的类,其原型如下:程序清单11.1 mytime0.h // mytime0.h -- Time class before operator overloading #if ...

  3. 剑指offer练习

    1.题目描述 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数.  public c ...

  4. $.post和jquerySubmit返回json数据获取的区别

    $.post("/patrol/patrolDataContent!deleteContent.action",{"ids":ids},function(dat ...

  5. AndroidのListView之滑动列表项(点击事件和滑动事件共存)

    这里正好在项目有这么一个bt的需求,如下图ListView的item可以响应点击事件也可以响应item的左右滑动事件,两个事件可以相互独立互不影响. 听说iphone的list选项就有这样bt的功能, ...

  6. 关于Activity的getReferrer():如何在Activity中获取调用者?

    http://blog.csdn.net/u013553529/article/details/53856800 关于Activity的getReferrer()之一:如何在Activity中获取调用 ...

  7. c# 给button添加不规则的图片以及用pictureBox替代button响应点击事件

    1.Flat button 用这个方法,前提是要把button的type设置为Flat button1.TabStop = false;button1.FlatAppearance.BorderSiz ...

  8. java设计模式----外观模式(门面模式)

    外观模式主要应用场景在于为复杂的子系统提供一个简单的接口,提高子系统的独立性. 创建DrawerOne类: package facade; public class DrawerOne { publi ...

  9. Iterator 和 Iterable 区别和联系

    首先预览下Java源码中的Iterator和Iterable: Iterable接口: public interface Iterable<T> {//这里只摘录接口中的抽象方法 /** ...

  10. Java.lang的研究(分析包含的重要类和接口)

    Java.lang包是Java中使用最广泛的一个包,它包含很多定义的类和接口. java.lang包包括以下这些类: Boolean Byte Character Class ClassLoader ...