
OJ
fzzjoy
Code Change World
展开
-
求解二叉树的深度(高度)_C语言
这是在阿里面试的一道题,刚难道感觉不是很难。于是按查找最大值和最小值的方法计算二叉树的深度。结果发现这俩个根本不是一回事。即使你不断遍历左子树,找到了最小值,但是其最小值节点依然可能会有右子树,这样深度也就会不断增加。也就是说最大值对应的节点并不等同于右子树的深度,最小值对应的节点并不等同于左子树的深度。面试结果也就可想而知了。其实拿到这道题,首先想到的应该是采用递归算法。递归算法就得原创 2015-05-24 21:10:13 · 27100 阅读 · 1 评论 -
最大公约数
求aVal和bVal的最大公约数/** 最大公约数的递归:* 1、若a可以整除b,则最大公约数是b* 2、如果1不成立,最大公约数便是b与a%b的最大公约数*/unsigned int gcd(int aVal, int bVal){return aVal%bVal ? gcd(bVal, aVal%bVal) : bVal;}参考链接:百度百科原创 2017-07-16 13:34:04 · 329 阅读 · 0 评论 -
最小公倍数
最小公倍数Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4374 Accepted Submission(s): 3084Problem Description给定原创 2015-12-06 15:13:30 · 399 阅读 · 0 评论 -
hihocoder#1014 : Trie树
时间限制:10000ms单点时限:1000ms内存限制:256MB描述小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程的学习道路上一同前进。这一天,他们遇到了一本词典,于是小Hi就向小Ho提出了那个经典的问题:“小Ho,你能不能对于每一个我给出的字符串,都在这个词典里面找到以这个字符串开头的所有单词呢?原创 2015-03-04 21:11:51 · 650 阅读 · 0 评论 -
hihocoder#1049 : 后序遍历
时间限制:10000ms单点时限:1000ms内存限制:256MB描述在参与过了美食节之后,小Hi和小Ho在别的地方又玩耍了一阵子,在这个过程中,小Ho得到了一个非常有意思的玩具——一棵由小球和木棍连接起来的二叉树!小Ho对这棵二叉树爱不释手,于是给它的每一个节点都标记了一个标号——一个属于A..Z的大写字母,并且没有任意两个节点的标号是一样的。小Hi也原创 2015-04-11 16:34:56 · 776 阅读 · 0 评论 -
As Easy As A+B
As Easy As A+BTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2882 Accepted Submission(s): 1357Problem Descript原创 2015-05-10 19:07:48 · 615 阅读 · 0 评论 -
Crixalis's Equipment
Crixalis's EquipmentTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3097 Accepted Submission(s): 922Problem Des原创 2015-05-10 18:38:21 · 488 阅读 · 0 评论 -
Wooden Sticks
Wooden SticksTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2471 Accepted Submission(s): 955 Problem Description原创 2015-04-23 20:10:32 · 548 阅读 · 0 评论 -
Phone List
Problem DescriptionGiven a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let’s say the phone catalogue listed these numbers:1. Emerge原创 2015-03-06 13:03:19 · 568 阅读 · 0 评论 -
ISBN号码
问题描述每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括9位数字、1位识别码和3位分隔符,其规定格式如“x-xxx-xxxxx-x”,其中符号“-”是分隔符(键盘上的减号),最后一位是识别码,例如0-670-82162-4就是一个标准的ISBN码。ISBN码的首位数字表示书籍的出版语言,例如0代表英语;第一个分隔符“-”之后的三位数字代表出版社,例如670代表维京出版社;第原创 2014-12-13 16:51:03 · 498 阅读 · 0 评论 -
hihocoder#1015 : KMP算法
时间限制:1000ms单点时限:1000ms内存限制:256MB描述小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程的学习道路上一同前进。这一天,他们遇到了一只河蟹,于是河蟹就向小Hi和小Ho提出了那个经典的问题:“小Hi和小Ho,你们能不能够判断一段文字(原串)里面是不是存在那么一些……特殊……的文字原创 2015-04-07 19:54:47 · 614 阅读 · 0 评论 -
Cake
CakeTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3137 Accepted Submission(s): 1520 Problem Description一次生日原创 2015-12-15 21:58:55 · 510 阅读 · 0 评论 -
A + B Problem II
A + B Problem IITime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3947 Accepted Submission(s): 1386Problem Descri原创 2017-11-15 22:09:58 · 282 阅读 · 0 评论 -
整数对
整数对Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3567 Accepted Submission(s): 1367Problem DescriptionGard原创 2017-11-04 23:14:01 · 928 阅读 · 0 评论 -
Fibonacci
FibonacciTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4554 Accepted Submission(s): 2056Problem Description原创 2017-11-04 21:50:40 · 289 阅读 · 0 评论 -
找新朋友
找新朋友Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4159 Accepted Submission(s): 1891Problem Description新年快原创 2017-07-16 14:22:11 · 303 阅读 · 0 评论 -
七夕节
七夕节Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5044 Accepted Submission(s): 1774Problem Description七夕节那原创 2015-12-24 16:45:04 · 413 阅读 · 0 评论 -
Largest prime factor
Largest prime factorTime Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5632 Accepted Submission(s): 1712Problem De原创 2015-12-24 15:56:08 · 401 阅读 · 0 评论 -
How many prime numbers
How many prime numbersTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9909 Accepted Submission(s): 3215Problem原创 2015-12-06 16:06:32 · 421 阅读 · 0 评论 -
出现次数最多的数
问题描述给定n个正整数,找出它们中出现次数最多的数。如果这样的数有多个,请输出其中最小的一个。输入格式输入的第一行只有一个正整数n(1 ≤ n ≤ 1000),表示数字的个数。输入的第二行有n个整数s1, s2, …, sn (1 ≤ si ≤ 10000, 1 ≤ i ≤ n)。相邻的数用空格分隔。输出格式输出这n个次数中出现次数最多的数。如果这样的数有多个,输出原创 2014-12-13 15:58:22 · 1087 阅读 · 0 评论 -
开门人和关门人
Problem Description每天第一个到机房的人要把门打开,最后一个离开的人要把门关好。现有一堆杂乱的机房签 到、签离记录,请根据记录找出当天开门和关门的人。 Input测试输入的第一行给出记录的总天数N ( > 0 )。下面列出了N天的记录。 每天的记录在第一行给出记录的条目数M ( > 0 ),下面是M行,每行的格式为原创 2014-12-12 16:44:23 · 709 阅读 · 0 评论 -
A+B for Input-Output Practice (VI)
Problem DescriptionYour task is to calculate the sum of some integers. InputInput contains multiple test cases, and one case one line. Each case starts with an integer N, and原创 2014-12-05 16:47:18 · 606 阅读 · 0 评论 -
Tian Ji -- The Horse Racing
Problem DescriptionHere is a famous story in Chinese history."That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse racing with the king原创 2014-12-05 16:39:29 · 452 阅读 · 0 评论 -
A+B for Input-Output Practice (V)
Problem DescriptionYour task is to calculate the sum of some integers. InputInput contains an integer N in the first line, and then N lines follow. Each line starts with a in原创 2014-12-05 16:44:50 · 901 阅读 · 0 评论 -
The Hardest Problem Ever
Problem DescriptionJulius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of原创 2014-12-03 15:28:34 · 367 阅读 · 0 评论 -
What Is Your Grade?
Problem Description“Point, point, life of student!”This is a ballad(歌谣)well known in colleges, and you must care about your score in this exam too. How many points can you get? Now, I told you t原创 2014-12-18 19:13:51 · 637 阅读 · 0 评论 -
A+B for Input-Output Practice (IV)
Problem DescriptionYour task is to Calculate the sum of some integers. InputInput contains multiple test cases. Each test case contains a integer N, and then N integers follo原创 2014-12-01 10:57:22 · 519 阅读 · 0 评论 -
A+B for Input-Output Practice (III)
Problem DescriptionYour task is to Calculate a + b. InputInput contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line.原创 2014-12-01 10:54:42 · 467 阅读 · 0 评论 -
A+B for Input-Output Practice (II)
Problem DescriptionYour task is to Calculate a + b. InputInput contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, sep原创 2014-12-01 10:53:47 · 4752 阅读 · 0 评论 -
Vowel Counting
Problem DescriptionThe "Vowel-Counting-Word"(VCW), complies with the following conditions.Each vowel in the word must be uppercase. Each consonant (the letters except the vowels) must be lower原创 2014-12-01 10:50:12 · 543 阅读 · 0 评论 -
A+B for Input-Output Practice (VII)
Problem DescriptionYour task is to Calculate a + b. InputThe input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.原创 2014-12-05 16:48:52 · 5427 阅读 · 0 评论 -
A+B for Input-Output Practice (VIII)
Problem DescriptionYour task is to calculate the sum of some integers. InputInput contains an integer N in the first line, and then N lines follow. Each line starts with a in原创 2014-12-05 16:50:38 · 463 阅读 · 0 评论 -
Specialized Four-Digit Numbers
Problem DescriptionFind and list all four-digit numbers in decimal notation that have the property that the sum of its four digits equals the sum of its digits when represented in hexadecimal (bas原创 2014-12-08 11:44:17 · 559 阅读 · 0 评论 -
ASCII
Problem DescriptionSince all we know the ASCII code, your job is simple: input numbers and output corresponding messages. InputThe first line contains one integer T (1The inp原创 2014-12-08 11:43:01 · 995 阅读 · 0 评论 -
Balloon Comes!
Problem DescriptionThe contest starts now! How excited it is to see balloons floating around. You, one of the best programmers in HDU, can get a very beautiful balloon if only you have solved the原创 2014-12-08 11:40:07 · 475 阅读 · 0 评论 -
Nasty Hacks
Problem DescriptionYou are the CEO of Nasty Hacks Inc., a company that creates small pieces of malicious software which teenagers may useto fool their friends. The company has just finished thei原创 2014-12-08 11:38:25 · 433 阅读 · 0 评论 -
Lowest Bit
Problem DescriptionGiven an positive integer A (1 For example, given A = 26, we can write A in binary form as 11010, so the lowest bit of A is 10, so the output should be 2.Another example原创 2014-12-08 11:41:36 · 488 阅读 · 0 评论 -
hide handkerchief
Problem DescriptionThe Children’s Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerchief with my friends原创 2014-12-08 11:36:49 · 560 阅读 · 0 评论 -
Text Reverse
Problem DescriptionIgnatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.原创 2014-12-08 11:35:32 · 631 阅读 · 0 评论 -
Fighting for HDU
Problem Description在上一回,我们让你猜测海东集团用地的形状,你猜对了吗?不管结果如何,都没关系,下面我继续向大家讲解海东集团的发展情况:在最初的两年里,HDU发展非常迅速,综合各种ACM算法生成的老鼠药效果奇好,据说该药专对老鼠有效,如果被人误食了,没有任何副作用,甚至有传闻说还有健胃的效果,不过这倒没有得到临床验证。所以,公司的销量逐年递增,利润也是节节攀升,作为原创 2014-12-23 13:20:49 · 531 阅读 · 0 评论