随笔分类 - 基础算法
负进制
摘要:百度一波负进制数:和正进制一样,每次取的余数保证在0~m-1之间。(例如m=-16,则余数应该在0~15)就可以直接输出。所以用系统的“%”运算符的时候必须注意检查是不是在该范围(可能在m+1~0),否则就调整。调整的方法是:如果余数<0,那么:余数-=m;商++;
阅读全文
主元素问题
摘要:1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<algorithm> 6 #include<cmath> 7 using namespace std; 8 int n
阅读全文
PRIM
摘要:#include<iostream> #include<cstdlib> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int maxn=999999
阅读全文
DIJKSTRA 临接表
摘要:1 #include <iostream> 2 #include <algorithm> 3 #include <cmath> 4 #include <cstdio> 5 #include <cstring> 6 #include <cstdlib> 7 using namespace std; 8
阅读全文
BELLMEN-FORD普通
摘要:#include <iostream> using namespace std; int m, n, u[100010], v[100010], w[100010];int check;int dis[100010]; int main(){ cin >> n >> m; for(int i = 1
阅读全文
poj3373--Changing Digits(DFS+剪枝///记忆化)
摘要:题目链接:点击打开链接 题目大意:给出一个n和一个k 求m 要求1、m要和n相同的位数 要求2、m要整除k 要求3、如果1和2满足,那么m要和n有尽量少的不同位 要求4、如果1、2、3满足,要使m尽量的小 简单的一个深搜,但是直接被要求吓蒙,,,,, 要求1和2直接可以在搜索时判断,要求3可以在深搜
阅读全文
数组模拟链表
摘要:1 #include 2 3 using namespace std; 4 5 int a[100010], r[100010]; 6 int n, len, t; 7 8 int main(){ 9 cin >> n; 10 for(int i = 1; i > a[i]; 11 len = n; 12 for(int i = 1; i...
阅读全文
栈
摘要:1 #include 2 #include 3 4 using namespace std; 5 6 int n, top, mid, next; 7 char a[100010], s[100010]; 8 9 int main(){ 10 cin >> a; 11 n = strlen(a); 12 mid = n / 2 - 1; 13 ...
阅读全文
队列
摘要:1 #include <iostream> 2 3 using namespace std; 4 5 int n, a[100010], head, tail; 6 int v, c[100010]; 7 8 int main(){ 9 cin >> n; 10 for(int i = 1; i <
阅读全文
DIJKSTRA
摘要:1 #include <iostream> 2 3 using namespace std; 4 5 int n, m; 6 int minn; 7 int u; 8 int dis[100010], book[100010], t1, t2, t3, e[10010][10010]; 9 10 i
阅读全文
FLOYD
摘要:#include <iostream> #include <iomanip> using namespace std; int m, n; int e[10010][10010], u, v, w; int main(){ cin >> n >> m; for(int i = 1; i <= n;
阅读全文
KMP
摘要:看完一个叫“海子”的人讲KMP算法,决定自己也写一个关于KMP的博客(当然,有些代码是直接从网上改的,但大部分还是我自己写的) 什么是KMP算法: KMP是三位大牛:D.E.Knuth、J.H.Morris和V.R.Pratt同时发现的。其中第一位就是《计算机程序设计艺术》的作者!! KMP算法要解
阅读全文
noip200605能量项链
摘要:题解: 状态转移方程为:dp[i][j] = max{dp[i][k] + dp[k+1][j] + a[i]*a[k+1]*a[j+1]}, k=i, ..., j-1, i和j都从1开始。dp[i][j]表示 输入n个数,则表示有n-1个能量珠。由于题目中的项链是一个环,起点可能是任意一个位置,
阅读全文
骑士的移动
摘要:题意:骑士在一个8*8的棋盘上移动,1-8代表行号,a-h代表列号,给出骑士的初始位置和目的位置,求骑士最少的移动步数;题目隐含一层意思(骑士移动规则是中国象棋的“马”的走法) 输入:一串字符串,包含起始位置和目的位置; 输出:骑士的最少移动步数; 解题思路:看到最少,立马想到BFS,按层搜索,步数
阅读全文
城市里的间谍B901
摘要:城市里的间谍 城市里的间谍 难度级别:C; 运行时间限制:1000ms; 运行空间限制:51200KB; 代码长度限制:2000000B 试题描述 某城市的地铁是线性的,有 n(2 <= n <= 50)个车站,从左到右编号为 1 到 n。有 M1 辆列车从第 1 站开始往右开,还有 M2 辆列车从
阅读全文
浙公网安备 33010602011771号