题目描述: 省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可)。现得到城镇道路统计表,表中列出了任意两城镇间修建道路的费用,以及该道路是否已经修通的状态。现请你编写程序,计算出全省畅通需要的最低成本。 输入: 测试输入包含若干测试用例。每个测试用例的第1行给出村庄数目N ( 1< N < 100 );随后的 N(N-1)/2 行对应村庄间道路的成本及修建状态,每行给4个正整数,分别是两个村庄的编号(从1编号到N),此两村庄间道路的成本,以及修建状态:1表示已建,0表示未建。
九度oj 题目1202:排序 提交网址: http://ac.jobdu.com/problem.php?pid=1202 时间限制:1秒 内存限制:32兆 特殊判题:否 提交:25316
题目描述: 给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到终点的最短距离及其花费,如果最短距离有多条路线,则输出花费最少的。 输入: 输入n,m,点的编号是1~n,然后是m行,每行4个数 a,b,d,p,表示a和b之间有一条边,且其长度为d,花费为p。最后一行是两个数 s,t;起点s,终点t。n和m为0时输入结束。 (n>1,n<=1000,m>0, m<100000, s != t) 输出: 输出 一行有两个数, 最短距离及其花费。 样例输入: 3 2 1 2 5 6 2 3 4 5 1 3 0 0 样例输出: 9 11
题目描述: 用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。 输入: 每个输入文件包含一个测试样例。 对于每个测试样例,第一行输入一个n(1<=n<=100000),代表队列操作的个数。 接下来的n行,每行输入一个队列操作: 1. PUSH X 向队列中push一个整数x(x>=0) 2. POP 从队列中pop一个数。 输出: 对应每个测试案例,打印所有pop操作中从队列pop中的数字。如果执行pop操作时,队列为空,则打印-1 样例输入: 3 PUSH 10 POP
题目描述: 二叉树的前序、中序、后序遍历的定义: 前序遍历:对任一子树,先访问跟,然后遍历其左子树,最后遍历其右子树; 中序遍历:对任一子树,先遍历其左子树,然后访问根,最后遍历其右子树; 后序遍历:对任一子树,先遍历其左子树,然后遍历其右子树,最后访问根。 给定一棵二叉树的前序遍历和中序遍历,求其后序遍历(提示:给定前序遍历与中序遍历能够唯一确定后序遍历)。 输入: 两个字符串,其长度n均小于等于26。 第一行为前序遍历,第二行为中序遍历。 二叉树中的结点名称以大写字母表示:A,B,C….最多26个结点。 输出: 输入样例可能有多组,对于每组测试样例, 输出一行,为后序遍历的字符串。 样例输入: ABC BAC FDXEAG XDEFAG 样例输出: BCA XEDGAF
题目描述: 在一个果园里,小明已经将所有的水果打了下来,并按水果的不同种类分成了若干堆,小明决定把所有的水果合成一堆。每一次合并,小明可以把两堆水果合并到一起,消耗的体力等于两堆水果的重量之和。当然经过 n‐1 次合并之后,就变成一堆了。小明在合并水果时总共消耗的体力等于每次合并所耗体力之和。 假定每个水果重量都为 1,并且已知水果的种类数和每种水果的数目,你的任务是设计出合并的次序方案,使小明耗费的体力最少,并输出这个最小的体力耗费值。例如有 3 种水果,数目依次为 1,2,9。可以先将 1,2 堆合并,新堆数目为3,耗费体力为 3。然后将新堆与原先的第三堆合并得到新的堆,耗费体力为 12。所以小明总共耗费体力=3+12=15,可以证明 15 为最小的体力耗费值。 输入: 每组数据输入包括两行,第一行是一个整数 n(1<=n<=10000),表示水果的种类数,如果 n 等于 0 表示输入结束,且不用处理。第二行包含 n 个整数,用空格分隔,第 i 个整数(1<=ai<=1000)是第 i 种水果的数目。 输出: 对于每组输入,输出一个整数并换行,这个值也就是最小的体力耗费值。输入数据保证这个值小于 2^31。 样例输入: 3 9 1 2 0 样例输出: 15
题目描述: 有一棵树,输出某一深度的所有节点,有则输出这些节点,无则输出EMPTY。该树是完全二叉树。 输入: 输入有多组数据。 每组输入一个n(1<=n<=1000),然后将树中的这n个节点依次输入,再输入一个d代表深度。 输出: 输出该树中第d层得所有节点,节点间用空格隔开,最后一个节点后没有空格。 样例输入: 4 1 2 3 4 2 样例输出: 2 3
第一次用Java提交Oj题目,发现比C++麻烦不少,C++ 写完放在OJ上大多数都能够直接跑,但Java甚至出现了编译错误这种情况,因此,需要对自己的程序做不少的修改。
题目描述: 输入一个链表,反转链表后,输出链表的所有元素。 (hint : 请务必使用链表) 输入: 输入可能包含多个测试样例,输入以EOF结束。 对于每个测试案例,输入的第一行为一个整数n(0<=n<=1000):代表将要输入的链表的个数。 输入的第二行包含n个整数t(0<=t<=1000000):代表链表元素。 输出: 对应每个测试案例, 以此输出链表反转后的元素,如没有元素则输出NULL。 样例输入: 5 1 2 3 4 5 0 样例输出: 5 4 3 2 1 NULL 解题思路: 我们考虑到,如
我知道对于一个新手来说,可能配运行环境要比上手写代码要难受的多。所以我就抽时间整了一些在线编程测试的网站,虽然推荐了这些网站,但是还是推荐大家平时写代码的时候在本地用IDE写。
题目描述: In an episode of the Dick Van Dyke show, little Richie connects the freckles on his Dad’s back to form a picture of the Liberty Bell. Alas, one of the freckles turns out to be a scar, so his Ripley’s engagement falls through. Consider Dick’s back to be a plane with freckles at various (x,y) locations. Your job is to tell Richie how to connect the dots so as to minimize the amount of ink used. Richie connects the dots by drawing straight lines between pairs, possibly lifting the pen between lines. When Richie is done there must be a sequence of connected lines from any freckle to any other freckle. 输入: The first line contains 0 < n <= 100, the number of freckles on Dick’s back. For each freckle, a line follows; each following line contains two real numbers indicating the (x,y) coordinates of the freckle. 输出: Your program prints a single real number to two decimal places: the minimum total length of ink lines that can connect all the freckles. 样例输入: 3 1.0 1.0 2.0 2.0 2.0 4.0 样例输出: 3.41
题目描述: 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离。省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可),并要求铺设的公路总长度为最小。请计算最小的公路总长度。 输入: 测试输入包含若干测试用例。每个测试用例的第1行给出村庄数目N ( < 100 );随后的N(N-1)/2行对应村庄间的距离,每行给出一对正整数,分别是两个村庄的编号,以及此两村庄间的距离。为简单起见,村庄从1到N编号。 当N为0时,输入结束,该用例不被处理。 输出: 对每个测试用例,在1行里输出最小的公路总长度。 样例输入: 3 1 2 1 1 3 2 2 3 4 4 1 2 1 1 3 4 1 4 1 2 3 3 2 4 2 3 4 5 0 样例输出: 3 5
题目描述: 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路? 输入: 测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目N ( < 1000 )和道路数目M;随后的M行对应M条道路,每行给出一对正整数,分别是该条道路直接连通的两个城镇的编号。为简单起见,城镇从1到N编号。 注意:两个城市之间可以有多条道路相通,也就是说 3 3 1 2 1 2 2 1 这种输入也是合法的 当N为0时,输入结束,该用例不被处理。 输出: 对每个测试用例,在1行里输出最少还需要建设的道路数目。 样例输入: 4 2 1 3 4 3 3 3 1 2 1 3 2 3 5 2 1 2 3 5 999 0 0 样例输出: 1 0 2 998
题目描述: 哈夫曼树,第一行输入一个数n,表示叶结点的个数。需要用这些叶结点生成哈夫曼树,根据哈夫曼树的概念,这些结点有权值,即weight,题目需要输出所有结点的值与权值的乘积之和。 输入: 输入有多组数据。 每组第一行输入一个数n,接着输入n个叶节点(叶节点权值不超过100,2<=n<=1000)。 输出: 输出权值。 样例输入: 5 1 2 2 5 9 样例输出: 37
题目描述: 今天的上机考试虽然有实时的Ranklist,但上面的排名只是根据完成的题数排序,没有考虑每题的分值,所以并不是最后的排名。给定录取分数线,请你写程序找出最后通过分数线的考生,并将他们的成绩按降序打印。 输入: 测试输入包含若干场考试的信息。每场考试信息的第1行给出考生人数N ( 0 < N < 1000 )、考题数M ( 0 < M < = 10 )、分数线(正整数)G;第2行排序给出第1题至第M题的正整数分值;以下N行,每行给出一名考生的准考证号(长度不超过20的字符串)、该生解决的题目总数m、以及这m道题的题号(题目号由1到M)。 当读入的考生人数为0时,输入结束,该场考试不予处理。 输出: 对每场考试,首先在第1行输出不低于分数线的考生人数n,随后n行按分数从高到低输出上线考生的考号与分数,其间用1空格分隔。若有多名考生分数相同,则按他们考号的升序输出。 样例输入: 4 5 25 10 10 12 13 15 CS004 3 5 1 3 CS003 5 2 4 1 3 5 CS002 2 1 2 CS001 3 2 3 5 1 2 40 10 30 CS001 1 2 2 3 20 10 10 10 CS000000000000000001 0 CS000000000000000002 2 1 2 0 样例输出: 3 CS003 60 CS001 37 CS004 37 0 1 CS000000000000000002 20
题目描述: Excel可以对一组纪录按任意指定列排序。现请你编写程序实现类似功能。 对每个测试用例,首先输出1行“Case i:”,其中 i 是测试用例的编号(从1开始)。随后在 N 行中输出按要求排序后的结果,即:当 C=1 时,按学号递增排序;当 C=2时,按姓名的非递减字典序排序;当 C=3 时,按成绩的非递减排序。当若干学生具有相同姓名或者相同成绩时,则按他们的学号递增排序。 输入: 测试输入包含若干测试用例。每个测试用例的第1行包含两个整数 N (N<=100000) 和 C,其中 N 是纪录的条数,C 是指定排序的列号。以下有N行,每行包含一条学生纪录。每条学生纪录由学号(6位数字,同组测试中没有重复的学号)、姓名(不超过8位且不包含空格的字符串)、成绩(闭区间[0, 100]内的整数)组成,每个项目间用1个空格隔开。当读到 N=0 时,全部输入结束,相应的结果不要输出。 输出: 对每个测试用例,首先输出1行“Case i:”,其中 i 是测试用例的编号(从1开始)。随后在 N 行中输出按要求排序后的结果,即:当 C=1 时,按学号递增排序;当 C=2时,按姓名的非递减字典序排序;当 C=3 时,按成绩的非递减排序。当若干学生具有相同姓名或者相同成绩时,则按他们的学号递增排序。 样例输入: 3 1 000007 James 85 000010 Amy 90 000001 Zoe 60 4 2 000007 James 85 000010 Amy 90 000001 Zoe 60 000002 James 98 4 3 000007 James 85 000010 Amy 90 000001 Zoe 60 000002 James 90 0 0 样例输出: Case 1: 000001 Zoe 60 000007 James 85 000010 Amy 90 Case 2: 000010 Amy 90 000002 James 98 000007 James 85 000001 Zoe 60 Case 3: 000001 Zoe 60 000007 James 85 000002 James 90 000010 Amy 90
用户可以在线提交多种程序代码(比如:C、C++、Java、Python等),系统对源代码进行编译和执行,并通过预先设计的测试用例来检验程序源代码的正确性。现广泛应用于世界各地高校学生程序设计的训练、作业的自动提交判断,以及各种竞赛(比如ACM)等。
剑指Offer 面试题12:打印1到最大的N位数 九度OJ 1515 提交网址: http://ac.jobdu.com/submitpage.php?pid=1515&sid=1539822 牛客
题目描述: 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt。但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗? 输入: 输入包括多组数据。每组数据第一行是两个整数N、M(N<=100,M<=10000),N表示成都的大街上有几个路口,标号为1的路口是商店所在地,标号为N的路口是赛场所在地,M则表示在成都有几条路。N=M=0表示输入结束。接下来M行,每行包括3个整数A,B,C(1<=A,B<=N,1<=C<=1000),表示在路口A与路口B之间有一条路,我们的工作人员需要C分钟的时间走过这条路。输入保证至少存在1条商店到赛场的路线。 当输入为两个0时,输入结束。 输出: 对于每组输入,输出一行,表示工作人员从商店走到赛场的最短时间。 样例输入: 2 1 1 2 3 3 3 1 2 5 2 3 5 3 1 2 0 0 样例输出: 3 2
题目描述: 省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可)。经过调查评估,得到的统计表中列出了有可能建设公路的若干条道路的成本。现请你编写程序,计算出全省畅通需要的最低成本。 输入: 测试输入包含若干测试用例。每个测试用例的第1行给出评估的道路条数 N、村庄数目M (N, M < =100 );随后的 N 行对应村庄间道路的成本,每行给出一对正整数,分别是两个村庄的编号,以及此两村庄间道路的成本(也是正整数
The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too expensive to maintain. The Council of Elders must choose to stop maintaining some roads. The map above on the left shows all the roads in use now and the cost in aacms per month to maintain them. Of course there needs to be some way to get between all the villages on maintained roads, even if the route is not as short as before. The Chief Elder would like to tell the Council of Elders what would be the smallest amount they could spend in aacms per month to maintain roads that would connect all the villages. The villages are labeled A through I in the maps above. The map on the right shows the roads that could be maintained most cheaply, for 216 aacms per month. Your task is to write a program that will solve such problems. 输入: The input consists of one to 100 data sets, followed by a final line containing only 0. Each data set starts with a line containing only a number n, which is the number of villages, 1 < n < 27, and the villages are labeled with the first n letters of the alphabet, capitalized. Each data set is completed with n-1 lines that start with village labels in alphabetical order. There is no line for the last village. Each line for a village starts with the village label followed by a number, k, of roads from this village to villages with labels later in the alphabet. If k is greater than 0, the line continues with data for each of the k roads. The data for each road is the village label for the other end of the road followed by the monthly maintenance cost in aacms for the road. Maintenance costs will be positive integers less than 100. All data fields in the row are separated by single blanks. The road network will always allow travel between all the villages. The network will never have more than 75 roads. No village will have more than 15 roads going to othe
题目描述: One way that the police finds the head of a gang is to check people’s phone calls. If there is a phone call between A and B, we say that A and B is related. The weight of a relation is defined to be the total time length of all the phone calls made between the two persons. A “Gang” is a cluster of more than 2 persons who are related to each other with total relation weight being greater than a given threthold K. In each gang, the one with maximum total weight is the head. Now given a list of phone calls, you are supposed to find the gangs and the heads. 输入: For each case, the first line contains two positive numbers N and K (both less than or equal to 1000), the number of phone calls and the weight threthold, respectively. Then N lines follow, each in the following format: Name1 Name2 Time where Name1 and Name2 are the names of people at the two ends of the call, and Time is the length of the call. A name is a string of three capital letters chosen from A-Z. A time length is a positive integer which is no more than 1000 minutes. 输出: For each test case, first print in a line the total number of gangs. Then for each gang, print in a line the name of the head and the total number of the members. It is guaranteed that the head is unique for each gang. The output must be sorted according to the alphabetical order of the names of the heads. 样例输入: 8 59 AAA BBB 10 BBB AAA 20 AAA CCC 40 DDD EEE 5 EEE DDD 70 FFF GGG 30 GGG HHH 20 HHH FFF 10 8 70 AAA BBB 10 BBB AAA 20 AAA CCC 40 DDD EEE 5 EEE DDD 70 FFF GGG 30 GGG HHH 20 HHH FFF 10 样例输出: 2 AAA 3 GGG 3 0
题目描述: 按要求,给国家进行排名。 输入: 有多组数据。 第一行给出国家数N,要求排名的国家数M,国家号从0到N-1。 第二行开始的N行给定国家或地区的奥运金牌数,奖牌数,人口数(百万)。 接下来一行给出M个国家号。 输出: 排序有4种方式: 金牌总数 奖牌总数 金牌人口比例 奖牌人口比例 对每个国家给出最佳排名排名方式 和 最终排名 格式为: 排名:排名方式 如果有相同的最终排名,则输出排名方式最小的那种排名,对于排名方式,金牌总数 < 奖牌总数 < 金牌人口比例 < 奖牌人口比例 如果有并列排名的情况,即如果出现金牌总数为 100,90,90,80.则排名为1,2,2,4. 每组数据后加一个空行。 样例输入: 4 4 4 8 1 6 6 2 4 8 2 2 12 4 0 1 2 3 4 2 8 10 1 8 11 2 8 12 3 8 13 4 0 3 样例输出: 1:3 1:1 2:1 1:2
思路: 首先考虑单个砝码在天枰的位置,可以得到C个状态,对应的平衡度为:G[0] * C[i],记录这些初始平衡度的个数。这样当放入第二个砝码时,可以遍历这些平衡度,从而得到一个新的平衡度。此时,不同位置,不同质量的砝码可能拥有相同平衡度,个数直接顺延给下一平衡度状态:当前平衡度+G[1]∗C[i] for i∈[−15,15]当前平衡度+G[1]∗C[i] for i∈[−15,15]当前平衡度+ G[1] * C[i] \space for \space i \in [-15, 15]
题目描述: 把只包含因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含因子7。 习惯上我们把1当做是第一个丑数。求按从小到大的顺序的第N个丑数。 输入: 输入包括一个整数N(1<=N<=1500)。 输出: 可能有多组测试数据,对于每组数据, 输出第N个丑数。 样例输入: 3 样例输出: 3 解题思路: 最简单的思路是,从1到大数,每个数都检测一遍是否是丑数,检测方法可以考虑 int ugly(int number){ if(number%2 =
这里只以Ubuntu16.04为例(官方推荐系统,稳定+运行流畅),其他安装方式请查阅:github
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2935 Accepted Submission(s): 889
本文讨论了使用图论中的强连通分量算法,用于分析给定网络中各个强连通分量的大小和数量,并使用K-means算法对它们进行聚类。首先,介绍了图论的基本概念和强连通分量的定义。然后,详细描述了如何使用K-means算法对强连通分量进行聚类。最后,通过实验验证了该方法的有效性,并分析了算法的时间复杂度。
apt-get install mysql-server mysql-client
1、某二叉树共有 399 个结点,其中有 199 个度为 2 的结点,则该二叉树中的叶子结点数为( ) A.不存在这样的二叉树 B.200 C.198 D.199 解析:选B,根据n0=n2+1的结论(这个结论不清楚的看博主的关于二叉树概念的文章有证明),就是度为0的节点始终比度为2的节点多一个,所以这题就很显然选B了!!
题目描述: 在一个字符串(1<=字符串长度<=10000,全部由大写字母组成)中找到第一个只出现一次的字符。 输入: 输入有多组数据 每一组输入一个字符串。 输出: 输出第一个只出现一次的字符下标,没有只出现一次的字符则输出-1。 样例输入: ABACCDEFF AA 样例输出: 1 -1 解题思路: 首先考虑到时间复杂度,对字符串进行排序或者双层扫描都会到达O(nlong)---O(n^2)的地步。 所以我们考虑额外使用一个数组进行计数,线性时间扫描数组,然后再按照原来的顺序扫描数组找到次数为1的
题目描述: 给定一个无向图和其中的所有边,判断这个图是否所有顶点都是连通的。 输入: 每组数据的第一行是两个整数 n 和 m(0<=n<=1000)。n 表示图的顶点数目,m 表示图中边的数目。如果 n 为 0 表示输入结束。随后有 m 行数据,每行有两个值 x 和 y(x<=n)(y <=n),表示顶点 x 和 y 相连,顶点的编号从 1 开始计算。输入不保证这些边是否重复。 输出: 对于每组输入数据,如果所有顶点都是连通的,输出”YES”,否则输出”NO”。 样例输入: 4 3 1 2 2 3 3 2 3 2 1 2 2 3 0 0 样例输出: NO YES
本文介绍了凸包问题的一种解决方案,通过计算每个点与对角线的距离来排序点,从而找到凸包。同时介绍了基于排序的凸包算法,通过排序三次即可找到凸包。
题目:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个已从小到大排好序的数组的一个旋转,输出旋转数组的最小元素。例如数组{3, 4, 5, 1, 2}为{1, 2, 3, 4, 5}的一个旋转,该数组的最小值为1。(要求不能直接遍历数组来求解.)
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014688145/article/details/78976235
这是一个算法题目合集,题目是我从网络和书籍之中整理而来,部分题目已经做了思路整理。问题分类包括:
题目描述: 输入一个链表,输出该链表中倒数第k个结点。 (hint: 请务必使用链表。) 输入: 输入可能包含多个测试样例,输入以EOF结束。 对于每个测试案例,输入的第一行为两个整数n和k(0<=n<=1000, 0<=k<=1000):n代表将要输入的链表元素的个数,k代表要查询倒数第几个的元素。 输入的第二行包括n个数t(1<=t<=1000000):代表链表中的元素。 输出: 对应每个测试案例, 若有结果,输出相应的查找结果。否则,输出NULL。 样例输入: 5 2 1 2 3 4 5 1 0 5
摘要总结:本文主要介绍了如何通过算法判断两个字符串是否互为变位词,并提供了常见算法和优化算法的思路。
什么要刷LeetCode 大家都知道,很多对算法要求高一点的软件公司,比如美国的FLAGM (Facebook、LinkedIn、Amazon/Apple、Google、Microsoft),或国内大厂BAT、TMD、华为,以及国内新兴的 AI 公司等等,都对算法水平有所要求。据悉知名游戏公司的算法岗收入很高,相应的对算法要求也比较高。而这些公司,大多数会以 LeetCode 中的题目或基于 LeetCode 改进后的自家算法题库来考察候选人。
挑战程序竞赛系列(90):3.6凸包(1) 传送门:POJ 2187: Beauty Contest 题意: 平面上有N个牧场。i号牧场的位置在格点(xi,yi)(x_i, y_i),所有牧场的位置
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
题目描述: 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 输入: 输入可能包含多个测试样例,对于每个测试案例, 输入包括一个整数n(1<=n<=70),其中n为偶数。 输出: 对应每个测试案例, 输出用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有的方法数。 样例输入: 4 样例输出: 5 解题思路: 观察题目中的矩形,2*n的,是个长条形。本来脑中想象的是复杂的华容道,但是既然只是简单的长条形,那么依然逆向分析。
题目描述: 一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。 输入: 输入可能包含多个测试样例,对于每个测试案例, 输入包括一个整数n(1<=n<=70)。 输出: 对应每个测试案例, 输出该青蛙跳上一个n级的台阶总共有多少种跳法。 样例输入: 5 样例输出: 8 题目分析: 这道题很明显正向分析是不行的,也就是说,最后面的一个台阶,要依赖于前面台阶的。所以,最后一个台阶的方法数目可以由前面计算出来。那么,仔细想一下,一个青蛙只能跳1-2步,也就是说,最后一个台阶肯
题目描述: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素。例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。 输入: 输入可能包含多个测试样例,对于每个测试案例, 输入的第一行为一个整数n(1<= n<=1000000):代表旋转数组的元素个数。 输入的第二行包括n个整数,其中每个整数a的范围是(1<=a<=10000000)。 输出: 对应每个测试案例, 输出旋转数组中最小的元素。 样例输
循环输入输出处理常见问题 1、为什么需要循环输入输出:通常来说OJ对于每道题里面有.in和.out文件,分别表示测试数据的输入和输出。如果某些编程题的所有数据都只做在一个.in和一个.out中,这样就会变成多组测试了,所以需要提交的代码中循环处理。 2、处理方法:其实这个问题可以避免,就是编程题后台每个样例做一组对应的.in和.out文件,这样就变成单组测试,代码就不需要循环处理,但是平时练习的题目质量不一,这个问题都会出现。 代码里面循环处理了即使是单组测试也会完全没问题,所以为了偷懒,可以全写成循环处理
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014688145/article/details/77587840
摘要总结:本文介绍了一种用于字符串比较的评分算法,该算法基于Levenshtein距离,可以用于比较字符串的相似度。该算法通过动态规划求解,并利用一个数组来存储累计的编辑距离,最后返回比较结果。
http://blog.csdn.net/jdplus/article/details/20203641
江湖人尽皆知的站点,全球知名的编程平台!总部在美国旧金山的硅谷,创办与2011年,2018年进入中国,并推出付费服务,19年推出力扣App。力扣为全球程序员提供了专业的IT技术职业化提升平台,有效帮助程序员实现快速进步和长期成长(度说)。
领取专属 10元无门槛券
手把手带您无忧上云