11.8 Imagine you are reading in a stream of integers. Periodically, you wish to be able to look up the rank of a number x (the number of values less than or equal tox). Implement the data structures and algorithms to support these operations.That is,…
18.1 Write a function that adds two numbers. You should not use + or any arithmetic operators. 这道题让我们实现两数相加,但是不能用加号或者其他什么数学运算符号,那么我们只能回归计算机运算的本质,位操作Bit Manipulation,我们在做加法运算的时候,每位相加之后可能会有进位Carry产生,然后在下一位计算时需要加上进位一起运算,那么我们能不能将两部分拆开呢,我们来看一个例子759+674 1.…
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18543    Accepted Submission(s): 11246 Problem Description The inversion number of a given number sequence a1, a2, ..., a…
11.3 Given a sorted array of n integers that has been rotated an unknown number of times, write code to find an element in the array. You may assume that the array was originally sorted in increasing order. EXAMPLE Input: find 5 in {15, 16, 19, 20, 2…
11.7 A circus is designing a tower routine consisting of people standing atop one another's shoulders. For practical and aesthetic reasons, each person must be both shorter and lighter than the person below him or her. Given the heights and weights o…
题意  假设一个正整数y满足  将随意正整数x放到y的左边得到的数z满足 z%y==0  那么这个数就是个Magic Number   给你一个范围  求这个范围内Magic Number的个数 令 l表示y的位数  ly=10^l  那么z=x*ly + y  要z%y==0   easy看出  仅仅需 x*ly%y==0 又由于x是随意的  所以一个Magic Number必须满足 ly%y==0 y<2^31  所以l最大为10 直接枚举l  找到全部符合的y即可了 当 ly%y==0  …
寻找并输出11~999之间的数m,它满足m.m2和m3均为回文数. 回文:各位数字左右对称的整数. 例如:11满足上述条件 112=121,113=1331 判断一个数是否是回文数的方法:求该数的反序数,若反序数和原数相等,则为回文数,否则不是回文数. 例如:121的反序数是121,所以121是回文数 123的反序数是321,所以123不是回文数 C++代码如下: #include<iostream> using namespace std; bool symm(int m) { int i…
11.1 You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted orde. LeetCode上的原题,请参见我之前的博客Merge Sorted Array 混合插入有序数组. class Solution { public: void merge(vector<int>…
11.2 Write a method to sort an array of strings so that all the anagrams are next to each other. 这道题让我们给一个字符串数组排序,让所有的变位词Anagrams排在一起,关于变位词,LeetCode里有两道相关的题目Anagrams 错位词和Valid Anagram 验证变位词.那么对于这道题,我们有两种方法可以实现,先来看第一种方法,来重写sort中的比较函数compare,参见代码如下: 解法…
11.4 Imagine you have a 20 GB file with one string per line. Explain how you would sort the file. 这道题说给了我们一个20GB大小的文件,每行有一个字符串,让我们给文件内容排序.那么既然强调了这么大的一个文件,肯定不想让我们直接进入内存中,那么我们可以把大文件分块,每块xMB,其中x的大小为我们可用的内存大小,我们对每块分别排序,然后把所有的有序块进行合并,这样我们就能得到一个有序的文件了.…
11.5 Given a sorted array of strings which is interspersed with empty strings, write a method to find the location of a given string. EXAMPLE Input: find "ball" in {"at", "", "", "", "ball", &quo…
11.6 Given an M x N matrix in which each row and each column is sorted in ascending order, write a method to find an element. LeetCode上的原题,请参见我之前的博客Search a 2D Matrix 搜索一个二维矩阵和Search a 2D Matrix II 搜索一个二维矩阵之二. class Solution { public: bool findElemen…
Chapter 1. Arrays and Strings 1.1 Unique Characters of a String 1.2 Reverse String 1.3 Permutation String 1.4 Replace Spaces 1.5 Compress String 1.6 Rotate Image 1.7 Set Matrix Zeroes 1.8 String Rotation Chapter 2. Linked Lists 2.1 Remove Duplicates…
Chapter 1. Arrays and Strings 1.1 Unique Characters of a String 1.2 Reverse String 1.3 Permutation String 1.4 Replace Spaces 1.5 Compress String 1.6 Rotate Image 1.7 Set Matrix Zeroes 1.8 String Rotation Chapter 2. Linked Lists 2.1 Remove Duplicates…
1.       前言 我们知道排序在非常多应用场景中属于一个非常核心的模块.最直接的应用就是搜索引擎.当用户提交一个query.搜索引擎会召回非常多文档,然后依据文档与query以及用户的相关程度对文档进行排序,这些文档怎样排序直接决定了搜索引擎的用户体验.其它重要的应用场景还有在线广告.协同过滤.多媒体检索等的排序. LambdaMART是Learning To Rank的当中一个算法,适用于很多排序场景. 它是微软Chris Burges大神的成果,近期几年很火,屡次现身于各种机器学习大赛…
Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16742    Accepted Submission(s): 7280 Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble numb…
1.Number.toExponential(fractionDigits) 把number转换成一个指数形式的字符串.可选参数控制其小数点后的数字位数.它必须在0~20之间. 例如: document.writeln(Math.PI.toExponential(0)); document.writeln(Math.PI.toExponential(2)); document.writeln(Math.PI.toExponential(7)); document.writeln(Math.PI.…
A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying two smaller natural numbers. Now lets define a number NN as the supreme number if and only if each number made up of an non-empty subsequence of all…
当一个数字,从左到右依次看过去数字没有出现先递增接着递减的"山峰"现象,就被称作 Valley Number.它可以递增,也可以递减,还可以先递减再递增.在递增或递减的过程中可以出现相等的情况. 比如,1,10,12,212,32122都是 Valley Number. 121,12331,21212则不是. 度度熊想知道不大于N的Valley Number数有多少. 注意,前导0是不合法的. 每组数据包含一个数N. ● 1≤T≤200 ● 1≤length(N)≤100 结果对\(1…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcode-cn.com/problems/confusing-number/ 题目描述 Given a number N, return true if and only if it is a confusing number, which satisfies the following condition…
P1206 [USACO1.2]回文平方数 Palindromic Squares 271通过 501提交 题目提供者该用户不存在 标签USACO 难度普及- 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 回文数是指从左向右念和从右向左念都一样的数.如12321就是一个典型的回文数. 给定一个进制B(2<=B<=20,由十进制表示),输出所有的大于等于1小于等于300(十进制下)且它的平方用B进制表示时是回文数的数.用’A’,’B’……表示10,11等等 输入输出格式 输入格式: 共…
A number system with moduli is defined by a vector of k moduli, [m1,m2, ···,mk]. The moduli must be pairwise co-prime, which means that, for any pair of moduli, the only common factor is 1. In such a system each number n is represented by a string "-x…
关键词:阿里双11技术十二讲直播丨雪人计划丨亚马逊AWS S3配置错误丨2018威胁预测丨MacOS漏洞丨智能风控平台MTEE3丨黑客窃取<权利的游戏>剧本|Android 8.1   本周资讯top3 [技术直播]承担双11万亿流量,阿里核心技术揭秘:12位大咖告诉你! 12月13日-14日,云栖社区联合阿里巴巴技术协会,共同举办<2017阿里双11技术十二讲>在线直播峰会,独家分享双11背后技术最佳实践,欢迎预约直播! 分享主题有:<阿里下一代技术架构:云化架构演进之路&…
如果一个数能够被组成它的各个非0数字整除,则称它是完美数.例如:1-9都是完美数,10,11,12,101都是完美数,但是13就不是完美数(因为13不能被数字3整除). 现在给定正整数x,y,求x和y之间(包含x和y的闭区间)共有多少完美数. Input 第1行:一个数T,表示后面用作输入测试的数的数量.(1 <= T <= 10000) 第2 - T + 1行:每行2个数,X, Y中间用空格分割.(1 <= X <= Y <= 10^18) Output 输出共T行,对应区…
P2045 方格取数加强版 题目描述 给出一个n*n的矩阵,每一格有一个非负整数Aij,(Aij <= 1000)现在从(1,1)出发,可以往右或者往下走,最后到达(n,n),每达到一格,把该格子的数取出来,该格子的数就变成0,这样一共走K次,现在要求K次所达到的方格的数的和最大 输入输出格式 输入格式: 第一行两个数n,k(1<=n<=50, 0<=k<=10) 接下来n行,每行n个数,分别表示矩阵的每个格子的数 输出格式: 一个数,为最大和 输入输出样例 输入样例#1:…
题目描述 给出一个n*n的矩阵,每一格有一个非负整数Aij,(Aij <= 1000)现在从(1,1)出发,可以往右或者往下走,最后到达(n,n),每达到一格,把该格子的数取出来,该格子的数就变成0,这样一共走K次,现在要求K次所达到的方格的数的和最大 输入输出格式 输入格式: 第一行两个数n,k(1<=n<=50, 0<=k<=10) 接下来n行,每行n个数,分别表示矩阵的每个格子的数 输出格式: 一个数,为最大和 输入输出样例 输入样例#1: 3 1 1 2 3 0 2…
该函数的功能就是对现有数据指标进行排名 示例:对产品进行销售总额的排名 首先要知道排名需要用到rank函数 number参数就是你要进行排名的数据 ref参数就是该指标需要在哪个区域内进行比较定位排名 order参数就是升序(0)还是降序(1) 确定即可.…
1.获取两个日期之间的月数.周数.天数语法 --1.获取两个日期之间的月数.周数.天数 --1.1)声明参数 ) ) --1.2)获取两个日期直接的月数 select DATEDIFF(MM,@startDate,@endDate) --1.3)获取两个日期直接的月数 select DATEDIFF(WW,@startDate,@endDate) --1.4)获取两个日期直接的月数 select DATEDIFF(DD,@startDate,@endDate) 2.测试用例 --2.测试用例 -…
一.题目链接:https://leetcode.com/problems/palindrome-number/ 二.题目大意: 给定一个整数,判断它是否为一个回文数.(例如-12,它就不是一个回文数:11它是一个回文数) 三.题解: 这道题目我一共用了两种解法: 方法1:将数字转化成字符串,然后首尾对应判断每个字符即可,代码如下: class Solution { public: bool isPalindrome(int x) { bool rs = true; stringstream ss…
1232 完美数 题目来源: 胡仁东 基准时间限制:2 秒 空间限制:131072 KB  如果一个数能够被组成它的各个非0数字整除,则称它是完美数.例如:1-9都是完美数,10,11,12,101都是完美数,但是13就不是完美数(因为13不能被数字3整除). 现在给定正整数x,y,求x和y之间(包含x和y的闭区间)共有多少完美数.   题目作者为:   Input 第1行:一个数T,表示后面用作输入测试的数的数量.(1 <= T <= 10000) 第2 - T + 1行:每行2个数,X, …