![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
杂项
文章平均质量分 52
1.02^365的成长裂变
每天比别人努力一点,坚持下去就是裂变的威力~
展开
-
[Interview Street] Track 1 - Bot saves princess
[Problem]Princess Peach is trapped in one of the four corners of a square grid. You are in the center of the grid and can move one step at a time in any of the four directions. Can you rescue the pr原创 2017-09-10 20:46:00 · 3740 阅读 · 0 评论 -
[WikiOI] 2.3.2 最大公约数
[Problem]求两个数A和B的最大公约数。 1[Solution]#include using namespace std;void swap(int &a, int &b){ a ^= b; b ^= a; a ^= b;}int main(){ int a, b; while(cin >> a >> b){原创 2017-09-10 20:46:57 · 3649 阅读 · 0 评论 -
[WikiOI] 2.3.3 素数判定
[Problem]质数又称素数。指在一个大于1的自然数中,除了1和此整数自身外,不能被其他自然数整除的数。素数在数论中有着很重要的地位。比1大但不是素数的数称为合数。1和0既非素数也非合数。质数是与合数相对立的两个概念,二者构成了数论当中最基础的定义之一。基于质数定义的基础之上而建立的问题有很多世界级的难题,如哥德巴赫猜想等。算术基本定理证明每个大于1的正整数都可以写成素数的乘原创 2017-09-10 20:47:00 · 3674 阅读 · 0 评论 -
[WikiOI] 2.4.1 十进制转m进制
[Problem]将十进制数n转换成m进制数 mn[Solution]#include #include using namespace std;char table[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};int m原创 2017-09-10 20:47:02 · 3598 阅读 · 0 评论 -
[WikiOI] 2.4.2 m进制转十进制
[Problem]将m进制数n转化成一个十进制数 m题目保证转换后的十进制数[Solution]#include #include #include using namespace std;#define MAX_LEN 101char table[256];int main(){ int m; char n[MAX_LEN]; t原创 2017-09-10 20:47:05 · 3647 阅读 · 0 评论 -
[WikiOI] 2.5.1 数的计算
[Problem]我们要求找出具有下列性质数的个数(包含输入的自然数n):先输入一个自然数n(n1. 不作任何处理;2. 在它的左边加上一个自然数,但该自然数不能超过原数的一半;3. 加上数后,继续按此规则进行处理,直到不能再加自然数为止.[Solution]#include #incl原创 2017-09-10 20:47:08 · 3597 阅读 · 0 评论 -
[WikiOI] 2.5.2 Fibonacci数列
[Problem]斐波纳契数列是这样的数列:f1 = 1f2 = 1f3 = 2f4 = 3....fn = fn-1 + fn-2 输入一个整数n求fn[Solution]#include using namespace std;int main(){ int array[41];原创 2017-09-10 20:47:11 · 3598 阅读 · 0 评论 -
[WikiOI] 2.6.1 二叉树最大宽度和高度
[Problem]给出一个二叉树,输出它的最大宽度和高度。[Solution]#includeusing namespace std;int n;int l[20], r[20], w[20], deep;void dfs(int x, int y){ w[y]++; if(y > deep) deep = y; if(l[x]) dfs(l[原创 2017-09-10 20:47:14 · 3649 阅读 · 0 评论 -
[WikiOI] 2.6.2 递归第一次
[Problem]同学们在做题时常遇到这种函数f(x)=5 (x>=0)f(x)=f(x+1)+f(x+2)+1 (x下面就以这个函数为题做一个递归程序吧[Solution]#include using namespace std;int array[31];int main(){ int n; while(cin >>原创 2017-09-10 20:47:16 · 3610 阅读 · 0 评论 -
[WikiOI] 2.6.3 3n+1问题
[Problem]3n+1问题是一个简单有趣而又没有解决的数学问题。这个问题是由L. Collatz在1937年提出的。克拉兹问题(Collatz problem)也被叫做hailstone问题、3n+1问题、Hasse算法问题、Kakutani算法问题、Thwaites猜想或者Ulam问题。问题如下:(1)输入一个正整数n;(2)如果n=1则结束;(3)如果n原创 2017-09-10 20:47:19 · 3628 阅读 · 0 评论 -
[WikiOI] 2.6.4 二叉树的序遍历
[Problem]求一棵二叉树的前序遍历,中序遍历和后序遍历[Solution]#include using namespace std;int n;int tree[20][2];/** * pre-order */void preOrder(int x){ if(x == 0){ return; } cout << x原创 2017-09-10 20:47:22 · 3610 阅读 · 0 评论 -
[WikiOI] 2.6.5 汉诺塔游戏
[Problem]汉诺塔问题(又称为河内塔问题),是一个大家熟知的问题。在A,B,C三根柱子上,有n个不同大小的圆盘(假设半径分别为1-n吧),一开始他们都叠在我A上(如图所示),你的目标是在最少的合法移动步数内将所有盘子从A塔移动到C塔。游戏中的每一步规则如下:1. 每一步只允许移动一个盘子(从一根柱子最上方到另一个柱子的最上方)2. 移动的过程中,你必须保证大的原创 2017-09-10 20:47:25 · 3694 阅读 · 0 评论 -
博客简介
简介好记性不如烂笔头,工作、学习和生活过程中的点点滴滴、关键知识点都需要记录,并不时拿出来阅读和总结,对过往知识的回顾和总结,为今后工作提供能量。本博客主要记录工作中解决的技术难题、日常系统性复习过程中的相关笔记等。互联网行业技术更新太快,很多技术每天都需要接触,经常进行系统性的学习、复习与总结,能够从更高的角度对整个技术栈有更好的掌握。博客中涉及到的系统性知识包括:C/C++、J原创 2017-09-20 13:44:18 · 4205 阅读 · 0 评论 -
[WikiOI] 2.3.1 最大公约数和最小公倍数
[Problem]输入二个正整数x0,y0(2条件: 1.P,Q是正整数2.要求P,Q以x0为最大公约数,以y0为最小公倍数.试求:满足条件的所有可能的两个正整数的个数.[Solution]#include #include using namespace std;/** * swap */void swap(int &原创 2017-09-10 20:46:54 · 3799 阅读 · 0 评论 -
[WikiOI] 2.2.2 蛇形矩阵
[Problem]小明玩一个数字游戏,取个n行n列数字矩阵(其中n为不超过100的奇数),数字的填补方法为:在矩阵中心从1开始以逆时针方向绕行,逐圈扩大,直到n行n列填满数字,请输出该n行n列正方形矩阵以及其的对角线数字之和.[Solution]#include using namespace std;int direct[4][2] = {{0, 1}, {-1,原创 2017-09-10 20:46:51 · 3662 阅读 · 0 评论 -
[WikiOI] 2.2.1 Cantor表
[Problem]现代数学的著名证明之一是Georg Cantor证明了有理数是可枚举的。他是用下面这一张表来证明这一命题的: 1/1 1/2 1/3 1/4 1/5 … 2/1 2/2 2/3 2/4 … 3/1 3/2 3/3 … 4/1 4/2 … 5/1 … … 我们以Z字形给上表的每一项编号。第一项是1/1,然后是1/2,2/1,3/1,2/2,…[Solut原创 2017-09-10 20:46:48 · 3688 阅读 · 0 评论 -
[Interview Street] Track 1 - Bot saves princess - 2
[Problem]In this version of “Bot saves princess”, Princess Peach and bot’s position are randomly set. Can you save the princess?TaskComplete the function nextMove which takes in 4 parameters - a原创 2017-09-10 20:46:03 · 3741 阅读 · 0 评论 -
[Cracking the Coding Interview] Chapter 1 - Arrays and Strings
1.1 Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?/* solution for question 1.1 */bool solution_1(string str){ // ini原创 2017-09-10 20:46:06 · 3632 阅读 · 0 评论 -
[Cracking the Coding Interview] Chapter 2 - Linked Lists
2.1 Write code to remove duplicates from an unsorted linked list. How would you solve this problem if a temporary bufer is not allowed?/* definition for Node */struct Node{ int val; Node *next;原创 2017-09-10 20:46:09 · 3627 阅读 · 0 评论 -
[Cracking the Coding Interview] Chapter 3 - Stacks and Queues
3.1 Describe how you could use a single array to implement three stacks./* solution for question 3.1 */templateclass TriStack{private: T *data; int size; int begin[3], end[3];public: /* con原创 2017-09-10 20:46:11 · 3673 阅读 · 0 评论 -
[WikiOI] 1.1.1 最小数和最大数
[Problem]输入n个数,n[Solution]#include using namespace std;int main(){ // definition int n, max, min, data; // get data cin >> n; for(int i = 0; i n; ++i){原创 2017-09-10 20:46:25 · 3604 阅读 · 0 评论 -
[WikiOI] 1.1.2 求和
[Problem]求n个数的和[Solution]#include using namespace std;int main(){ // definition int n, sum = 0, data; cin >> n; for(int i = 0; i n; ++i){ cin >> data; sum原创 2017-09-10 20:46:28 · 3624 阅读 · 0 评论 -
[WikiOI] 1.2.1 判断浮点数是否相等
[Problem]给出两个浮点数,请你判断这两个浮点数是否相等[Solution]#include #include using namespace std;#define eps 0.000000001int main(){ double a, b; cin >> a >> b; if(fabs(a - b) eps){原创 2017-09-10 20:46:31 · 3620 阅读 · 0 评论 -
[WikiOI] 1.2.2 保留两位小数
[Problem]保留两位小数输出一个浮点数。[Solution]#include int main(){ double a; scanf("%lf", &a); printf("%.2lf\n", a); return 0;}原创 2017-09-10 20:46:34 · 3653 阅读 · 0 评论 -
[WikiOI] 1.3.1 寻找子串位置
[Problem]给出字符串a和字符串b,保证b是a的一个子串,请你输出b在a中第一次出现的位置。[Solution]#include #include #define MAX_LEN 101int main(){ char a[MAX_LEN], b[MAX_LEN]; scanf("%s%s", a, b); printf("%d\n",原创 2017-09-10 20:46:37 · 3767 阅读 · 2 评论 -
[WikiOI] 1.3.2 单词翻转
[Problem]给出一个英语句子,希望你把句子里的单词顺序都翻转过来[Analysis]为保证额外的空间开销,在原字符串上处理:首先将整个句子翻转一遍,然后从头到尾遍历一次,翻转每一个单词。[Solution]#include #include #define MAX_LEN 10001int main(){ // input data原创 2017-09-10 20:46:40 · 3614 阅读 · 0 评论 -
[WikiOI] 2.1.1 明明的随机数
[Problem]明明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤100),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着不同的学生的学号。然后再把这些数从小到大排序,按照排好的顺序去找同学做调查。请你协助明明完成“去重”与“排序”的工作。[Analysis]用map存储输入数据,key为分数,value为是否原创 2017-09-10 20:46:42 · 3595 阅读 · 0 评论 -
[WikiOI] 2.1.2 排序
[Problem]给出n和n个整数,希望你从小到大给他们排序[Solution]#include #include #include using namespace std;int main(){ int n, a; vectorint> data; // get data cin >> n; while(n--)原创 2017-09-10 20:46:45 · 3623 阅读 · 0 评论 -
[博弈论] 三个枪手
彼此痛恨的甲、乙、丙三个枪手准备决斗。甲枪法最好,十发八中;乙枪法次之,十发六中;丙枪法最差,十发四中。先提第一个问题:如果三人同时开枪,并且每人只发一枪;第一轮枪战后,谁活下来的机会大一些?一般人认为甲的枪法好,活下来的可能性大一些。但合乎推理的结论是,枪法最糟糕的丙活下来的几率最大。我们来分析一下各个枪手的策略。枪手甲一定要对枪手乙先开枪。因为乙对甲的威胁要比丙对甲的威胁更大,甲应该首...转载 2018-09-01 23:30:52 · 67187 阅读 · 0 评论