![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
算法解题笔记
leetcode、蓝桥杯、算法入门经典、etc
HUGG_dajingzi
这个作者很懒,什么都没留下…
展开
-
leetcode 204. 计数质数-厄拉多塞筛法(埃氏筛)、线性筛
统计所有小于非负整数n的质数的数量。示例 1:输入:n = 10输出:4解释:小于 10 的质数一共有 4 个, 它们是 2, 3, 5, 7 。示例 2:输入:n = 0输出:0示例 3:输入:n = 1输出:0提示:0 <= n <= 5 * 106遍历遍历判断[2,n]中所有整数是否为质数。判断每个数i(i<=n)是否为质数时,只需判断[2,sqrt(i)]中每个数是否为i的因数厄拉多塞筛法/埃氏筛所有合数都是质..原创 2020-12-10 16:12:01 · 228 阅读 · 0 评论 -
算法竞赛入门经典第十一章
例题11-4 电话圈 UVa247#include <bits/stdc++.h>using namespace std;/* run this program using the console pauser or add your own getch, system("pause") or input loop *//*5 6Ben Alexan...原创 2019-07-14 22:38:22 · 125 阅读 · 0 评论 -
过桥问题
过河问题 时间限制:1000 ms | 内存限制:65535 KB 难度:5描述 在漆黑的夜里,N位旅行者来到了一座狭窄而且没有护栏的桥边。如果不借助手电筒的话,大家是无论如何也不敢过桥去的。不幸的是,N个人一共只带了一只手电筒,而桥窄得只够让两个人同时过。如果各自单独过桥的话,N人所需要的时间已知;而如果两人同时过桥,所需要的时间就是走得比较慢的那个人单独行动时所需的时间...原创 2018-03-27 14:07:23 · 514 阅读 · 0 评论 -
蓝桥杯第八届省赛
第4题标题:方格分割6x6的方格,沿着格子的边线剪开成两部分。要求这两部分的形状完全相同。如图:p1.png, p2.png, p3.png 就是可行的分割法。试计算:包括这3种分法在内,一共有多少种不同的分割方法。注意:旋转对称的属于同一种分割法。请提交该整数,不要填写任何多余的内容或说明文字。图的dfs按照两部分分割开的线深度搜索vis[7][7]存放0/1...原创 2019-07-14 22:37:14 · 311 阅读 · 0 评论 -
蓝桥杯 计蒜客模拟赛
相信大家都知道什么是全排列,但是今天的全排列比你想象中的难一点。我们要找的是全排列中,排列结果互不相同的个数。比如:aab的全排列就只有三种,那就是aab,baa,aba。代码框中的代码是一种实现,请分析并填写缺失的代码。#include <cstdio>#include <cstdlib>#include <cstring>#include ...原创 2019-07-14 22:36:22 · 123 阅读 · 0 评论 -
算法竞赛入门经典第九章
例题9-1 城市里的间谍 UVa1025仿佛有固定终点的DP问题都是从终点开始,往起点规划的???#include<bits/stdc++.h>using namespace std;#define INF 0X3F3F3F3Fint main(){ int kase=0; int n,T,t[55],M1,r_begin,M2,l_begin; int t...原创 2019-07-14 22:37:59 · 165 阅读 · 0 评论 -
算法竞赛入门指南第八章
8.3 递归与分治棋盘覆盖问题#include <iostream>using namespace std;const int maxNum = 1 << 10;int chess[maxNum][maxNum]; // 棋盘int number; // L型牌放置顺序编号void chessBoard(int...2018-03-18 00:11:01 · 197 阅读 · 0 评论 -
算法竞赛入门指南第七章
例题7-6 带宽 UVa140刚开始已知看不懂题。。醉了题目中的相邻结点是针对图说的得到的排列不一定是按照八个结点画一条线依次经过的那种#include <bits/stdc++.h>using namespace std;/* run this program using the console pauser or add your own getch, system("pau...原创 2018-03-13 23:49:36 · 205 阅读 · 0 评论 -
算法竞赛入门经典第六章
习题6-1 平衡的括号#include <bits/stdc++.h>using namespace std;/* run this program using the console pauser or add your own getch, system("pause") or input loop *//*()[]([][]())*/int main(int arg...原创 2018-03-13 23:46:19 · 248 阅读 · 0 评论 -
算法竞赛入门经典第五章
习题5-1 代码对齐 UVa1593#include <bits/stdc++.h>using namespace std;/* run this program using the console pauser or add your own getch, system("pause") or input loop */const int maxn=1000+10;int s...2018-03-06 23:21:03 · 243 阅读 · 0 评论 -
算法竞赛入门经典第四章
例题4-3 救济金发放 UVa133#include <stdio.h>#include <stdlib.h>#define maxn 25int n,k,m,a[maxn];int go(int p,int d,int t){ while(t--){ do{ p=(p+d+n-1)%n+1; }while(a[p]==0); } retur...原创 2018-03-07 07:55:50 · 365 阅读 · 1 评论 -
算法经典入门第三章习题
习题3-1 得分#include <iostream>#include <bits/stdc++.h> #include <string.h> #define MAX 100/* run this program using the console pauser or add your own getch, system("pause") or ...2018-03-02 23:20:07 · 243 阅读 · 0 评论 -
算法竞赛入门经典第三章
例题3-4 猜数字的提示#include <stdio.h>#include <stdlib.h>/* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(int argc, char *argv[]...原创 2018-02-28 23:00:07 · 252 阅读 · 0 评论 -
算法竞赛经典入门第二章
2-4 子序列的和#include <stdio.h>#include <stdlib.h>/* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(int argc, char *argv[]) {...原创 2019-07-14 22:37:32 · 168 阅读 · 0 评论 -
面试题 46.把数字翻译成字符串(方法:动态规划、递归)
给定一个数字,我们按照如下规则把它翻译为字符串:0 翻译成 “a” ,1 翻译成 “b”,……,11 翻译成 “l”,……,25 翻译成 “z”。一个数字可能有多个翻译。请编程实现一个函数,用来计算一个数字有多少种不同的翻译方法。示例 1:输入: 12258输出: 5解释: 12258有5种不同的翻译,分别是"bccfi", "bwfi", "bczi", "mcfi"和"mzi"提示:$\{0}\le{num}<{2^31}$1.动态规划dp[i]:表示从..原创 2020-06-09 10:47:32 · 260 阅读 · 0 评论 -
leetcode 28.实现strStr()--KMP算法--字符串匹配
1.暴力 遍历class Solution {public: int strStr(string haystack, string needle) { if(needle.empty()) return 0; if(haystack.empty()) return -1; if(haystack.size()<needle.size()) return -1; ..原创 2020-06-09 09:01:41 · 183 阅读 · 0 评论