【Gym - 100947G】Square Spiral Search】的更多相关文章

BUPT 2017 summer training (for 16) #1C 题意 A new computer scientist is trying to develop a new memory management system called "spiral memory management". The basic idea of this system is that it represents the memory as a 2D grid with a predefin…
[题目链接] http://poj.org/problem?id=1084 [算法] 迭代加深 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #inclu…
https://www.bnuoj.com/v3/contest_show.php?cid=9154#problem/J [题意] 给定n个木棍,问这些木棍能否围成一个正方形 [Accepted] #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<algorithm> #include<q…
Problem Link: https://oj.leetcode.com/problems/recover-binary-search-tree/ We know that the inorder traversal of a binary search tree should be a sorted array. Therefore, we can compare each node with its previous node in the inorder to find the two…
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. 题意: 一颗二叉搜索树中有2个结点的元素被误换了,要求恢复二叉搜索树的原状. 思路: 中序遍历BST,若发现一次逆序,说明是两个相连结点的误换,直接交换结点的值:若发现两次逆序,则为不相连的两个结点误换,交换错误的结点即可.用一个变量保存先前结点的状态,若发生逆序则记…
Recover Binary Search Tree Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. 互换二叉搜索树中两个位置错误的节点. 思路: 预设三个指针pre,p1,p2.p1用来指向第一个出错的节点,p2用来指向第二个出错的节点. 出错情况有两种,即p1和p2相邻,p1和p2不相邻. 中序遍历此二叉树,用…
Validate Binary Search Tree Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node c…
BUPT2017 wintertraining(15) #4H Gym - 101116K 题意 给定一个菜谱,大写的单词代表混合物,小写的代表基础原料.每个混合物由其它混合物或基础原料组成,不会间接或直接地需要自己.制备每个混合物必须先制备组成它的混合物.且混合物都要用一个碗装,当它作为原料去合成其它混合物后,碗就空出来了.求合成第一个混合物最少需要用几个碗. 题解 假设合成一个混合物需要dfs(i)个碗. 因为最后需要合成第一个混合物,所以我们以它为根进行dfs. 假设当前混合物的原料里有t…
BUPT2017 wintertraining(15) #4G Gym - 101124 E.Dance Party 题意 有c种颜色,每个颜色最多分配给两个人,有M个男士,F个女士,求至少一对男士同色的概率. \((1 \le C, M, F \le 10^9; M + F \le 2C)\) 题解 反面比较好求的,也就是不存在男男同色的概率. 假设每个男士依次选择剩下的颜色,第一个人有2C种选择,当前不同色的概率是1,第二个人有2C-1种选择,当前不同色的概率是(2C-2)/(2C-1),第…
BUPT2017 wintertraining(15) #4F Gym - 101124A 题意 给定画框宽度,画的四边和一个对角线长度,求画框外沿周长. 题解 过顶点做画框的垂线,每个角都得到两个全等直角三角形.然后用余弦公式求得四个角,再在直角三角形中计算出比内沿多出来的长度,加上画的四边长度即可. 代码 #include <cstdio> #include <cstring> #include <algorithm> #include <cmath>…