各处刷题
Vas_Sago
这个作者很懒,什么都没留下…
展开
-
(牛客)直方图内最大矩形
题意数学统计上常见的柱状图,找出图中矩形面积最大值。 动态规划。。感觉数据好水。宽度才500 Mycodeclass MaxInnerRec {public: int countArea(vector<int> A, int n) { // write code here int dp[n]; dp[0]=A[0]; in原创 2017-01-02 17:09:28 · 369 阅读 · 0 评论 -
(牛客网)栈的压入、弹出序列
输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应的一个弹出序列,但4,3,5,1,2就不可能是该压栈序列的弹出序列。(注意:这两个序列的长度是相等的)简单的数据结构知识,借用一个栈模拟一下压入弹出的操作,如果完成操作后这个栈是空的,那么就合法。code#原创 2017-06-08 14:34:57 · 276 阅读 · 0 评论 -
(牛客网)调整数组顺序使奇数位于偶数前面
输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变。class Solution {public: void reOrderArray(vector<int> &array) { vector<int> mid; vector<int>::原创 2017-06-03 13:24:29 · 207 阅读 · 0 评论 -
(牛客网)二维数组中的查找
在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。解题思路:拿target和二维数组右上角比较(因为数组右上角的数是同行最大的结束,是同列最小的开始)如果右上角小于target那么说明这一行都小于target所以可以排除这一行如果右上角大于target,则说明这一列都大于target可原创 2017-06-02 20:40:32 · 954 阅读 · 0 评论 -
(轴对称二叉树)Binary Tree
In the computer world, there are various interesting trees and forests. One of the most earthy tree is binary tree. Now Mosu has a problem, how to quickly judge a binary tree whether is symmetry. In原创 2017-05-31 18:47:30 · 625 阅读 · 0 评论 -
(codechef) Bytelandian gold coins
In Byteland they have a very strange monetary system. Each Bytelandian gold coin has an integer number written on it. A coin n can be exchanged in a bank into three coins: n/2, n/3 and n/4. But thes原创 2017-05-18 20:38:11 · 417 阅读 · 0 评论 -
(牛客网)跳台阶
一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。排列组合问题class Solution {public: int jumpFloor(int number) { int num=0,ans=0; while(number>=num){ ans+=cnm(number,num);原创 2017-05-28 17:06:11 · 237 阅读 · 0 评论 -
(牛客网)变态跳台阶
一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。 水~~( ̄o ̄) . z Z 比如n=5 : | | | | | 形象表示5个台阶。 你第一步条1个台阶,剩下就有4个台阶 你第一步条2个台阶,剩下就有3个台阶 你第一步条3个台阶,剩下就有2个台阶 你第一步条4个台阶,剩下就有1个台阶 你第一步条5个台阶,+1就行 即是说原创 2017-05-28 19:30:26 · 419 阅读 · 0 评论 -
(牛客网)丑数
把只包含因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含因子7。 习惯上我们把1当做是第一个丑数。求按从小到大的顺序的第N个丑数。要理解下面的算法需要注意: 1.每个丑数都是之前的丑数 *2 , *3 , *5 的结果2.一个丑数 * x (x=2,3,5) 的结果都要加入到答案序列中,但是每次只能加入最小的那个。一旦一个丑数 * x (x=2,3,原创 2017-05-28 16:28:55 · 391 阅读 · 0 评论 -
(牛客网)二叉树的深度
输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL)原创 2017-05-28 14:19:54 · 361 阅读 · 0 评论 -
(codechef)Prime Generator
Shridhar wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers. Input The first line contains t, the number of原创 2017-05-28 10:20:21 · 351 阅读 · 0 评论 -
(codechef)The Next Palindrome
A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more t原创 2017-05-27 18:34:02 · 261 阅读 · 0 评论 -
(牛客)拜访(动态规划)
左右中只能选一个方向,若选择左只能一直向左走。上下中只能选择一个方向,若选择下只能一直向下。 所以有2种情况 (1)二者位置在对角线上 (2)两者位置重合或处于同一行或同一列class Visit {public: int countPath(vector<vector<int> > map, int n, int m) { // write code here原创 2016-12-31 18:29:32 · 462 阅读 · 0 评论 -
(牛客)棋子翻转
Mycode:class Flip {public: vector<vector<int> > flipChess(vector<vector<int> > A, vector<vector<int> > f) { // write code here for(int i=0;i<3;i++){ //注意判断是否越界就行原创 2016-12-31 16:19:33 · 377 阅读 · 0 评论 -
(牛客)地下迷宫
小青蛙有一天不小心落入了一个地下迷宫,小青蛙希望用自己仅剩的体力值P跳出这个地下迷宫。为了让问题简单,假设这是一个n*m的格子迷宫,迷宫每个位置为0或者1,0代表这个位置有障碍物,小青蛙达到不了这个位置;1代表小青蛙可以达到的位置。小青蛙初始在(0,0)位置,地下迷宫的出口在(0,m-1)(保证这两个位置都是1,并且保证一定有起点到终点可达的路径),小青蛙在迷宫中水平移动一个单位距离需要消耗1点体力原创 2016-12-30 18:07:58 · 5223 阅读 · 0 评论 -
(牛客)最大差值(贪心)
Mycode:class LongestDistance {public: int getDis(vector<int> A, int n) { // write code here vector<int> :: iterator it; int ans=0,minx=9999999; for(it=A.begin();it<原创 2016-12-31 15:49:24 · 375 阅读 · 0 评论 -
(牛客)无判断max
class Max {public: int getMax(int a, int b) { // write code here //一时想不出来。。 switch(a/b){ case 0: return b; default : return a; } }};//高原创 2017-01-07 19:16:03 · 669 阅读 · 0 评论 -
(牛客)懂二进制
位运算: Mycodeclass Solution {public: /** * 获得两个整形二进制表达位数不同的数量 * * @param m 整数m * @param n 整数n * @return 整型 */ int countBitDiff(int m, int n) { int ans=m^n;原创 2017-01-07 18:57:51 · 388 阅读 · 0 评论 -
(牛客网)构建乘积数组
给定一个数组A[0,1,…,n-1],请构建一个数组B[0,1,…,n-1],其中B中的元素B[i]=A[0]A[1]…A[i-1]*A[i+1]…*A[n-1]。不能使用除法。 矩阵: ref:来自牛客网讨论class Solution {public: vector<int> multiply(const vector<int>& A) { vector<int原创 2017-06-10 20:39:29 · 243 阅读 · 0 评论