ACM 一些小知识

1.常用头文件:

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>

2.常用宏定义:

#define PI acos(-1.0)
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;

3.快读模版:

inline int read(){
	char ch = getchar();
	int x = 0, f = 1;
	while(ch < '0' || ch > '9'){
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while('0' <= ch && ch <= '9'){
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}
 
inline void write(int x){
	if (x < 0) x = ~x + 1, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}

4.威佐夫博弈


有两堆各若干个物品,两个人轮流从任意一堆中取出至少一个或者同时从两堆中取出同样多的物品,规定每次至少取一个,至多不限,最后取光者胜利。


奇异局势: (0,0),(1,2),(3,5),(4 ,7),(6,10),(8,13)
黄金比例 t = (sqrt(5.0) + 1) / 2.0;
假设差值为 k,必败态为: 【int(k * t),int(k*t) + k】

奇异局势先手输。

//hdu1527判断输赢
ll a,b;
double t = (sqrt(5.0) + 1) / 2.0;  
while(~scanf("%lld%lld",&a,&b)){
    if((ll)(fabs(a-b) * t) == min(a,b)) cout << 0 << endl;
    else cout << 1 << endl;
}

5.斯特林公式(n越大越准确)

求阶乘:
求阶乘
求阶乘位数

在这里插入图片描述

在这里插入图片描述

hdu1018求阶乘位数

#include<bits/stdc++.h>
#define PI acos(-1.0)

using namespace std;

int main(){
	int T;cin>>T;
    while(T--) {
        int x;cin>>x;
        int res = (int)((0.5*log(2*PI*x) + x*log(x) - x)/log(10));
        cout<<res+1<<endl;
    }
    return 0;
}

6.勾股数
当n > 2时:
当n为奇数时,另外两数为floor(nn/2),floor(nn/2)+1;
当n为偶数时,另外两数为nn/4-1,nn/4+1。

7.NIM博弈
有n堆石头,两个人依次对某一堆取石头,每次取石头最少为1块,谁先取完谁获胜。
计算n堆石头数目的异或和,判断是否为0即可。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值