- 博客(15)
- 收藏
- 关注
原创 LeetCode 134 - gas station
【思路】加油问题,暴力不可取( O(n^2) ),我们举个栗子gas = [7, 5, 6, 0, 6]cost = [3, 0, 0, 18, 2]对应求差得到dec = [7-3, 5-0, 6-0, 0-18, 6-2] = [4, 5, 6, -18, 4]那么我们按照dec这个列表从头到尾遍历一遍,油量初始化为0i = 0, dec[i] = 4油
2016-05-12 15:56:54 309
原创 Leetcode 260 - Single Number III
【思路】从一系列的数字中找出两个只出现过一次的数,其它数字只出现过两次,这里我们可以得出结论,所有的数字求位运算异或操作之后所得的结果跟这两个数字的异或结果必定相同,由于这两个数字是不同的,它们的异或结果肯定不为0,例如以下:[1,5,5,3,4,6,1,4]1 xor 5 xor 5 xor 3 xor 4 xor 6 xor 1 xor 4 = 3 xor 6 = 5 = 101
2016-05-08 13:02:10 239
原创 UVa 11234 - Expressions
【题译】通常两个操作数之间写入一个操作符可以组成算术表达式(又称中缀表达)。例如 (x+y)*(z-w) 就是一个基于中缀表达的表达式。然而,在编程方面,用后缀表达的表达式求值起来则要容易得多(又称逆波兰式)。在后缀表达上,一个表达式中的操作符往往被写在操作数的后面。例如, xy+zw-* 就是刚才的算术表达式用后缀表达的结果。值得注意的是,后缀表达不含括号。为了求出一个后缀表达式的值,栈
2014-12-02 20:53:27 456
原创 UVa 705 - Slash Maze
【简略译文】通过字符'\'和'/',你可以生成一个小巧的迷宫。迷宫中的路径不会有分叉,因此迷宫中的路径可以形成环,也可以通往迷宫的入口和出口。我们只对环感兴趣。给你指定一个编程任务,找出迷宫中环的个数,以及所有环当中最长路径的长度。长度通过原文图中所示的灰色方块个数统计求得,在该例子中,最长环的长度为16,共有2个环。【思路】由于是倾斜的迷宫(不知道这么说对不对),不能用往常的迷宫
2014-11-26 20:22:24 534
原创 UVa 101 The Blocks Problem
【题目链接】http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=37【解题思路】本题题意biaojiao
2014-09-05 12:06:36 394
原创 UVa 107 The Cat in the Hat
【题目链接】http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=43【解题思路】
2014-08-25 22:15:45 384
转载 UVa 375 Inscribed Circles and Isosceles Triangles
Given two real numbersBthe width of the base of an isosceles triangle in inchesHthe altitude of the same isosceles triangle in inchesCompute to six significant decimal places
2014-08-25 21:30:38 335
原创 UVa 10025 The ? 1 ? 2 ? ... ? n = k problem
【解题思路】若直接用枚举搜索,所遍历的可能性将会超过10^40000,肯定会超时,需要从中找寻规律。从最简单的开始:数字序列 1 能够生成的非负整数为 +1=1,集合为{1}数字序列 1 2 能够生成的非负整数为 +1+2=3,-1+2=1,集合为{1,3}数字序列 1 2 3 能够生成的非负整数为 +1+2+3=6,-1+2+3=4,+1-2+3=2,+1+2-3=0,-1-
2014-08-08 10:22:40 285
原创 UVa 465 Overflow
【题目链接】http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=406【解题思路】kan
2014-08-05 20:37:04 329
原创 UVa 340 Master-Mind Hints
【题目链接】http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=276【解题思路】本题题意比较晦涩,主要核心部分为下面一段话:这两段话定义了强弱match的条件和两个match之间的独立性成立条件。大致的题意是,对于给定的一串数字s,
2014-07-31 09:00:23 313
原创 UVa 10106 Product
【题目链接】http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1047
2014-07-26 15:46:32 458
原创 HDU 1017 A Mathematical Curiosity
【题目链接】http://acm.hdu.edu.cn/showproblem.php?pid=1017
2014-07-17 11:30:10 376
原创 UVa 490 Rotating sentences
【题目链接】http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=431【解题思路】 这道题目的样例输出格式着实一坑,需要注意输出时要在根据字符串的最大长度进行空格补位。以下是另补的样例输入输出,用字符‘*’代表空格,空
2014-07-13 15:03:49 403
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人