
递归
SYaoJun
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
94. 二叉树的中序遍历
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...原创 2019-08-23 08:41:36 · 242 阅读 · 0 评论 -
772. 基本计算器 III
题目难度:困难类型:递归 栈class Solution {public: int calculate(string s) { int j = 0; for(int i = 0; i < s.size(); ){ while(i < s.size() && s[i]==' ') i++; ...原创 2020-03-29 09:43:22 · 780 阅读 · 0 评论 -
227. 基本计算器 II
题目类型:双栈难度:中等class Solution {public: int calculate(string s) { //yxc 2020.3.29 //乘除法先算 stack<char> op; stack<int> num; s +="+0"; //处理边界 ...原创 2020-03-29 09:42:10 · 228 阅读 · 0 评论 -
224. 基本计算器
题目难度:困难类型:递归 栈class Solution {public: int calculate(string s) { //递归 2020.3.29 先把空格搞定 int j = 0; for(int i = 0; i < s.size(); ){ while(i < s.size() &a...原创 2020-03-29 09:40:57 · 199 阅读 · 0 评论 -
7-4 Cartesian Tree (30分)
A Cartesian tree is a binary tree constructed from a sequence of distinct numbers. The tree is heap-ordered, and an inorder traversal returns the original sequence. For example, given the sequence { 8...原创 2019-12-08 08:25:56 · 384 阅读 · 0 评论 -
分糖果
#include <unordered_map>#include <iostream>#include <vector> #include <bitset>#include <algorithm>int res = 0;int f(int apple, int plate){ if(plate > apple) ret...原创 2019-09-05 07:45:29 · 192 阅读 · 0 评论 -
51nod 2067 n 皇后问题
题目链接#include <iostream>#include <vector>#include <cstring>using namespace std;int n, res = 0;int pos[11];void dfs(int k){ //前0~k-1个皇后已经摆好了,现在摆第k个 if(k == n){ res++; re...原创 2019-09-02 09:21:20 · 450 阅读 · 1 评论 -
八皇后【北京大学】
题目描述会下国际象棋的人都很清楚:皇后可以在横、竖、斜线上不限步数地吃掉其他棋子。如何将8个皇后放在棋盘上(有8 * 8个方格),使它们谁也不能被吃掉!这就是著名的八皇后问题。 对于某个满足要求的8皇后的摆放方法,定义一个皇后串a与之对应,即a=b1b2…b8,其中bi为相应摆法中第i行皇后所处的列数。已经知道8皇后问题一共有92组解(即92个不同的皇后串)。 给出一个数b,要求输出第b个串。...原创 2019-07-31 10:02:30 · 139 阅读 · 0 评论 -
逆波兰表达式
中国MOOC课程题目主要思想是递归#include<bits/stdc++.h>using namespace std;double exp(){ char s[20]; cin>>s; switch(s[0]){ case '+': return exp()+exp(); case '-': return exp()-exp(); case '*...原创 2019-05-17 10:18:39 · 207 阅读 · 0 评论 -
1128. N Queens Puzzle (20)
https://www.patest.cn/contests/pat-a-practise/1128解题思路:重点掌握n皇后的判断,注意这道题是按列给出的数据,所以只用判断是否在同行或者同一对角线,同行的话就是纵坐标相等,对角线的话就是tan为正负1,但是直接除的话会出现向下取整,所以把分母上的数乘到右边,比较两者是相等还是,呈相反数。#include#define N 1005int原创 2018-01-30 16:10:34 · 311 阅读 · 0 评论 -
放苹果——北京大学复试上机
题目描述 把 M 个同样的苹果放在 N 个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法? 注意:5、1、1 和 1、5、1 是同一种分法,即顺序无关。 输入描述: 输入包含多组数据。每组数据包含两个正整数 m和n(1≤m, n≤20)。 输出描述: 对应每组数据,输出一个整数k,表示有k种不同的分法。 示例1 输入 7 3 输出 8解题思路:可以看成递归原创 2018-01-15 15:57:55 · 364 阅读 · 0 评论