- 博客(216)
- 资源 (7)
- 收藏
- 关注
原创 新博客:http://tedhacker.top/
在github上开新博客啦,https://tedhacker.github.io/,新博客,新征途~
2016-08-08 20:13:38
1015
原创 LeetCode OJ : Reverse Words in a String
Reverse Words in a String 链接:https://leetcode.com/problems/reverse-words-in-a-string/题解:给你一个字符串"the sky is blue",把单词顺序置反,变成"blue is sky the"。提示:For C programmers: Try to solve it in-place
2015-03-21 14:38:21
1046
原创 LeetCode OJ : Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array 链接:https://leetcode.com/problems/remove-duplicates-from-sorted-array/题解:给一个有序数组,让你除去重复的数字和除去后的长度。比如A=[1,1,2],返回A=[1,2],长度为2。要求使用常数空间。维护两次指针a,b,a指向不重
2015-03-20 20:09:09
892
原创 LeetCode OJ : Median of Two Sorted Arrays
Median of Two Sorted Arrays 链接:https://leetcode.com/problems/median-of-two-sorted-arrays/题解:给两个有序数组A,B,求中位数,要求时间复杂度为O(log (m+n))。先求中位数的位置idx=(A.length+B.length)/2,分别比较两个数组的最小值哪个最小,弹出那个
2015-03-20 10:55:24
933
原创 LeetCode OJ : Maximum Gap
Maximum Gap链接:https://leetcode.com/problems/maximum-gap/题解:本题给你一个无序的数列,问在排序中相邻两数之差的最大值是多少,要求线性时间复杂度。因为通常的排序都O(nlog2n),所以这里有选一些独特的办法。观察可知,相邻两数之差最小是bucketLen=(max-min)/(len-1)[可以想象一个
2015-03-19 15:15:44
827
原创 LeetCode OJ : Gas Station
Roman to Integer链接:https://leetcode.com/problems/gas-station/题解:本题提供两个数组int[] gas, int[] cost,gas表示第i个点的汽油量,cost表示从i到i+1所需的汽油量,问能否以空车从任一点出发,驶过所有点(路径是环)。题解的思路大致是枚举,从0开始枚举能否从这个点出发走完全程,但是
2015-03-17 13:13:29
800
原创 LeetCode OJ : Roman to Integer
Roman to Integer链接:https://leetcode.com/problems/roman-to-integer/解答:这题主要要了解罗马数字的规则基本字符 相应的阿拉伯数字表示为I 1V 5X 10L
2015-03-15 20:43:00
746
原创 PAT Advanced Level (1081~1087)
PAT 1081 链接:http://www.patest.cn/contests/pat-a-practise/1077代码:
2014-11-24 21:53:58
1369
原创 PAT Advanced Level (1077~1080)
PAT 1026 程序运行时间链接::http://www.patest.cn/contests/pat-b-practise/1026代码:PAT 1026 程序运行时间链接::http://www.patest.cn/contests/pat-b-practise/1026代码:
2014-11-24 19:49:55
798
原创 PAT Basic Level (1026~1030)
PAT 1026地址:http://www.patest.cn/contests/pat-b-practise/1026
2014-11-23 22:14:41
1359
原创 Codeforces Round #260 (Div. 2)
第一题:Dice Tower题意:给你n个骰子,一个叠在一个上面,连接位置的两个面是两个不同的数字,问只告诉你最上面一个骰子的顶面和所有骰子面向你的两个面的数字,能否确定所有骰子每个面是什么数字?题解:代码:
2014-08-09 11:38:52
1000
4
原创 PAT 1072. Gas Station
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1072题解:对每个加油站进行迪杰斯特拉处理,求出最小距离和平均距离,再按题目要求排序输出。代码:#include#include#include#include#include#include#include#include#include#includeusin
2014-03-10 01:34:10
1342
1
原创 PAT 1066. Root of AVL Tree
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1066题解:考察数据结构;AVL树。重点就是四种情况的识别和处理。代码:#include#include#include#include#include#include#include#include#include#includeusing namespac
2014-03-09 18:58:32
1674
原创 PAT 1076. Forwards on Weibo
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1076题解:共有n个微博号,第i行表明有k个人关注i,问x再转发m层的范围内可以转发多少人的微博(同1个人的微博算1个)。依照输入建图。对每个账号进行BFS。代码:#include#include#include#include#include#include#i
2014-03-09 02:14:21
2877
原创 PAT 1068. Find More Coins
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1068题解:背包。代码:#include#include#include#include#include#include#include#include#include#includeusing namespace std;#define INF 0x6ffff
2014-03-09 00:35:14
1540
原创 PAT 1057. Stack
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1057题解:维护一个小于等于mid的,一个大于mid的两部分,保持小的的大小和大的的大小一致或者比大的多一个,这样mid即小的的最后一个数。代码:#include#include#include#include#include#include#include#inclu
2014-03-08 23:21:59
2701
原创 PAT 1053. Path of Equal Weight
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1053题解:给一棵树和各个树结点的权重,问哪些从根到叶子的权重和等于K。深搜枚举所有可能即可。代码:#include#include#include#include#include#include#include#include#includeusing nam
2014-03-08 22:13:07
1831
原创 PAT 1034. Head of a Gang
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1034题解:代码:#include#include#include#include#include#include#include#include#includeusing namespace std;#define INF 0x6fffffffmap weight
2014-03-08 17:33:57
1502
原创 PAT 1075. PAT Judge
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1075题解:提交时未通过的在排名输出时显示为0。需要在排名中显示的至少有一个通过的提交(即只有-1的不显示)。代码:#include#include#include#include#include#include#include#include#includeu
2014-03-07 23:59:38
1869
原创 PAT 1043. Is It a Binary Search Tree
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1043题解:1:通过输入构造二叉排序树2:先序遍历并与输入顺序比较3:如果比较不符合再构造镜像二叉排序树4:比较输出结果代码:#include#include#include#include#include#include#include#include#
2014-03-07 16:01:30
1283
1
原创 PAT 1055. The World's Richest
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1055题解:枚举查找符合条件的输出即可。代码:#include#include#include#include#include#include#include#include#includeusing namespace std;#define INF 0x6ff
2014-03-06 22:33:37
1302
原创 PAT 1037. Magic Coupon
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1037题解:有种优惠卷,使用后可以获得相应商品价格x的n倍的的金额,但n和x都可能为负数,乘积为负就要付出对应金额。解法就是把商品价格和优惠卷都按从小到大排序,正的和正的相乘,负的和负的相乘。代码:#include#include#include#include#incl
2014-03-06 21:16:07
1511
原创 PAT 1033. To Fill or Not to Fill
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1033题解:代码:#include#include#include#include#include#include#include#include#includeusing namespace std;#define INF 0x6fffffffstruct poi
2014-03-06 03:17:45
1240
原创 PAT 1052. Linked List Sorting
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1052题解:模拟链表按值排序注意:可能给多个链表,只要输出与头地址相连的部分 可能输入的长度为0代码:#include#include#include#include#include#include#include#include#inc
2014-03-05 02:15:08
1481
原创 PAT 1044. Shopping in Mars
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1044题解:在一个长度为n的序列中找长度为m的连续子序列,如果不存在,则找大于m的最小连续子序列长度。最后输出所有符合条件的连续子序列的两个端点。枚举加二分搜索。代码:#include#include#include#include#include#include
2014-03-05 01:12:02
890
原创 PAT 1017. Queueing at Bank
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1017题解:模拟题。代码:#include#include#include#include#include#include#include#include#includeusing namespace std;#define INF 0x6fffffffstru
2014-03-05 00:27:36
1116
原创 PAT 1016. Phone Bills
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1016题解:模拟题。给一份流水账,求各个用户改缴多少费用。注意:只有on-off匹配才需缴费代码:#include#include#include#include#include#include#include#include#includeusing na
2014-03-04 20:45:25
2119
原创 PAT 1014. Waiting in Line
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1014题解:模拟题。先把n*m个客户加入对应的n的窗口队列中,如果还有客户,枚举判断出n个窗口中最早处理完的队列,然后将用户加入此队列。最后将时间和时限进行比较,输出。代码:#include#include#include#include#include#inclu
2014-03-04 17:21:59
2675
1
原创 PAT 1074. Reversing Linked List
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1074题解:给一个n长度的链表存储的字符串,以k长度为单位置逆子串,输出置逆后的整个子串。写的时候死活最后一个case通不过。看了别人的题解才知道输入的竟然可能不是一个串。例如:00100 6 300000 4 9999900100 1 1230968237 6
2014-03-03 23:10:56
3198
2
原创 PAT 1024. 科学计数法
题目:http://pat.zju.edu.cn/contests/pat-b-practise/1024题解:将输入的科学计数法数字转换为正常的数字。分子分母至少有1位。按指数的正负分情况处理即可。代码:#include#include#include#include#include#include#include#includeusing namespa
2014-03-03 16:47:53
2681
2
原创 PAT 1045. Favorite Color Stripe
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1045题解:DP。转换成求最长递增子序列。代码:#include#include#include#include#include#include#include#include#include#includeusing namespace std;int dp[
2014-03-02 21:06:30
1517
原创 PAT 1059. Prime Factors
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1059题解:要点就是分解质因数。从小到大枚举即可。代码:#include#include#include#include#include#include#include#include#include#includeusing namespace std;boo
2014-03-02 19:05:49
1672
原创 PAT 1039. Course List for Student
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1039题解:最后一个Case用map会超时,就自己写个hash即可。代码:#include#include#include#include#include#include#include#include#include#includeusing namespace
2014-03-02 17:52:18
1026
原创 PAT 1047. Student List for Course
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1047题解:代码:#include#include#include#include#include#include#include#include#include#includeusing namespace std;vectormapx[2505];int ma
2014-03-02 17:03:32
1659
1
原创 PAT 1010. Radix
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1010题解:给两个数a,b和a的进制x,问b在哪个进制下和x进制的a相等。本来看题目只说明了[0-9][a-z]的意义,以为答案最高只有36进制,提交之后错一大片T^T。测试了下,发现要求的进制竟然很大很大,而且可能超过int的表示范围。如果从最小的进制开始往上枚举测试,最多只有两个
2014-03-02 16:14:20
4346
4
原创 PAT 1038. Recover the Smallest Number
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1038题解:代码:#include#include#include#include#include#include#include#includeusing namespace std;struct ch{ char s[15];}str[10005];b
2014-03-01 01:44:14
1144
原创 PAT 1040. Longest Symmetric String
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1040题解:代码:#include#include#include#include#include#include#include#includeusing namespace std;int main(){ char ch[1005]; gets(c
2014-03-01 01:12:45
1390
原创 PAT 1032. Sharing
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1032题解:给两个字符串的链表存储,如果两个字符有相同的后缀,其后缀会存放在相同内存块,问这两个字符串是否有相同的后缀,如果有相同的后缀求出最开始相同的字母的内存地址。先遍历一个字符串,标记出现过哪些地址,再遍历另一个字符串,出现相同地址的即所求解。注:竟然卡STLC中格式字符串
2014-03-01 00:10:36
1784
原创 PAT 1028. List Sorting
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1028题解:模拟题。写三个比较函数即可。代码:#include#include#include#include#include#include#includeusing namespace std;struct student{ char id[15];
2014-02-28 22:46:55
891
原创 PAT 1035. Password
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1035题解:模拟题。注意看清题目,那几个要修改的字母真的很容易看错。。。还是输出时候的单复数形式。。。代码:#include#include#include#include#include#include#includeusing namespace std;stru
2014-02-28 22:07:59
1036
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人