随笔分类 - 算法初学
摘要:当你站在一个迷宫里的时候,往往会被错综复杂的道路弄得失去方向感,如果你能得到迷宫地图,事情就会变得非常简单。 假设你已经得到了一个n*m的迷宫的图纸,请你找出从起点到出口的最短路。
阅读全文
摘要:原文链接:https://blog.csdn.net/liquanhai/article/details/1759906 & 按位与 | 按位或 ^ 按位异或 1. 按位与运算 按位与运算符"&"是双目运算符。其功能是参与运算的两数各对应的二进位相与。只有对应的两个二进位均为1时,结果位才为1 ,否
阅读全文
摘要:有n个人,第i个人的重量为w[i],每艘船的最大载重量均为c,且最多只能乘两个人。用最少的船装载所有人。 思路:从最轻的开始考虑,让最轻的和最重的一条船,若超出重量则可判定最重的只能一人一条船 代码:
阅读全文
摘要:int length(long long n) { return (int)log10(n)+1; }
阅读全文
摘要:快速幂算法——可迅速求出a^b。其主要理论依据如下: 1,当b为偶数时,a^b可以转为a^2的b/2次方。 2,当b为奇数时,a^b可以转为a^2的b/2次方,再乘以a。 利用快速幂方法可以迅速求出一个数的任意次方。再结合a*b%m=(a%m)*(b%m)%m,就可得出下面计算代码:
阅读全文
摘要:证明过程:https://blog.csdn.net/lincifer/article/details/49391175 代码: 1)扩展欧几里得算法求ax+by=c时 2)求解模线性方程 ax = b(mod n) 同余方程 ax≡b (mod n)对于未知数 x 有解,当且仅当 gcd(a,n)
阅读全文
摘要:Bi-shoe and Phi-shoe Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1370 Bi-shoe and Phi-shoe Submi
阅读全文
摘要:欧拉函数详解 对一个正整数N,欧拉函数是小于N且与N互质的数的个数.。 例如φ(24)=8,因为1, 5, 7, 11, 13, 17, 19, 23均和 24 互质。 φ(n) = n*(1-1/p1)*(1-1/p2)*......(1-1/pn) 其中(p1.....pn)为N的素因子 欧拉函
阅读全文
摘要:题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1284
阅读全文
摘要:题目链接:https://vjudge.net/contest/215608#problem/A Dijkstra算法 1 #include <iostream> 2 #include <cstdio> 3 const int inf=0x3f3f3f3f; 4 const int maxn=1<<
阅读全文
摘要:邻接矩阵版 1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 const int maxn=1010; 6 const int INF=0x3f3f3f3f; 7 int n,m,s,G[maxn][maxn];//n为顶点数,m为边数,
阅读全文
摘要:题目链接:https://abc091.contest.atcoder.jp/tasks/abc091_b #include <iostream> #include <map> using namespace std; int n, m, mx; string s[105], t; map<stri
阅读全文
摘要:题目链接:https://vjudge.net/contest/215603#problem/M 其中三维数组dis将两个广搜合并到了一起
阅读全文
摘要:题目链接http://noi.openjudge.cn/ch0204/7622/ 该题只需先进行归并排序,因为如果a[p1]>a[p2]说明a[p2]比区间[p1,m]中的任何元素都小,且p1在p2之前,所以能得出m-p1+1个逆序对。所以在合并区间时加上tot+=mid-i+1; 即可 参考代码:
阅读全文
摘要:#include #include #define max 10000000 #define bool char //定以bool类型 #define true 1 #define false 0 //规定1为对0为错(c语言中没有bool函数) int prime[max]; bool is_prime[max]; int sieve(int n) { int...
阅读全文

浙公网安备 33010602011771号