- 博客(47)
- 收藏
- 关注
原创 Summing Pieces[HackerRank]
题意 有N(1≤N≤1e6)N(1\le N \le 1e6)个数,分隔成数个子序列,总共有2N−12^{N-1}种分隔方法,求所有分隔中的每个数加起来乘以长度的和的和,比如B=[(1,2,4),(5,1),(2)]=>(1+2+4)×3+(5+1)×2+(2)×1=35B=[(1,2,4),(5,1),(2)]=>(1+2+4)\times 3+(5+1)\times 2+(2)\times 1
2016-09-27 14:53:35
730
原创 [HackerRank]Week Of Code 23
又是玩得比较爽的一场 HackerRank Week of Code 23部分题解Gears of War题意: N(N≥3)N(N \ge 3)个齿轮围成一圈问是否正常工作解法:一眼看出来奇数不行,偶数可行Lighthouse题意:点为可放井号不可,问能放多大的那种图形,如图欧几里得距离固定的”圆”解法:二分暴力,因为边长最大50,不二分不知道能不能过(问号脸)Treasure Hu
2016-09-20 17:51:21
526
原创 Short Palindrome[HackerRank]
Short Palindrome题目大意: 给字符串S(1<=length(S)<=1e6)S(1<=length(S)<=1e6),全由小宝字母组成,求出有多少对(a,b,c,d)(a<b<c<d)(a,b,c,d)(a<b<c<d)满足Sa==SdandSb==ScS_a==S_d and S_b==S_c.解法: 由于只有26种字母,并不多,我们可以枚举字母来处理,假设现在枚举Sa==
2016-07-26 23:03:01
744
原创 World CodeSprint #4[HackerRank]
World CodeSprint #4部分题解。Minimum Distances题目大意 给N个数,找距离最近的两个数的距离解法 N只有1e31e3,O(N2)O(N^2)暴力就好了#include <bits/stdc++.h>const int N = 1e5 + 10;int a[N];int main() { int n; scanf("%d", &n); for
2016-06-28 23:47:44
612
原创 Hdu5696 区间的价值(花式水)
欢迎使用Markdown编辑器写博客本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦:Markdown和扩展Markdown简洁的语法代码块高亮图片链接和图片上传LaTex数学公式UML序列图和流程图离线写博客导入导出Markdown文件丰富的快捷键快捷键加粗 Ctrl + B 斜体 Ctrl + I 引用 Ctrl
2016-05-22 18:09:34
1149
原创 [LeetCode]Easy合集I
Merge Sorted Array题意:给长度为m数组1和长度为n的数组2,都是有序的,要求合成一个数组而且是有序的。(数组1的长度大于等于n+m)解法:倒着过来存比较好处理,枚举数组1的值x,把数组2大于等于x的值加到数组1的后面,然后再把x加到后面。CodeSame Tree题意:给两棵二叉数,判断是不是完全一样的.解法:暴力即可,递归下去看节点如果都为空返回true
2015-12-27 18:39:05
542
原创 [LeetCode]Add Binary&Climbing Stairs&Remove Duplicates from Sorted List
今天写得蛮快的,来个三连发。Add Binary Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100".题意:二进制加法.解法:把两个串都倒过来(低位先加).然后模拟一下就好了.注意最后也要进位就好.
2015-11-18 13:33:55
421
原创 [LeetCode]Length of Last Word&Plus One
发现还早,并没有睡意,再看了一眼后面的Easy,发现很快,so,写了吧,为了节约能源,把两题合在一起Length of Last Word Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the str
2015-11-17 13:31:12
367
原创 [LeetCode] Count and Say
Count and Say The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ... 1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21.
2015-11-17 13:13:59
329
原创 [LeetCode] Valid Sudoku
Valid Sudoku Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’.
2015-11-16 19:59:52
383
原创 [LeetCode] Implement strStr()[字符串hash]
题目:Implement strStr() Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.题意:实现strStr,给两个串A和B,总B是不是A的子串,如果是,返回第一个子串的起始位置,
2015-11-14 13:43:51
425
原创 [LeetCode] Remove Duplicates from Sorted Array & Remove Element
Remove Duplicates from Sorted ArrayRemove Element发现这两题性质差不多,于是就一起写了吧.Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such that each element appear only once a
2015-11-12 13:24:52
368
原创 [LeetCode] Merge Two Sorted Lists
Merge Two Sorted Lists这貌似也一个常见的面试题.合并两个有序链表.尽量的占用空间少。 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.解法:
2015-11-11 13:13:43
365
原创 [LeetCode] Valid Parentheses
Valid ParenthesesLeetCode20 Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. The brackets must close in the correct order, “
2015-11-10 13:29:38
333
原创 [LeetCode] Remove Nth Node From End of List
Remove Nth Node From End of List写完最长前缀,看了一眼下一个easy,发现是个几行代码的题。so,写了吧。 题目: Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked
2015-11-09 13:46:38
361
原创 [LeetCode] Longest Common Prefix
[LeetCode] Longest Common Prefix上一个easy的是那个罗马数字转int。我还百度了一下规则,感觉太恶心了这种模拟题,跳过好了..今天写了最长公共前缀 Write a function to find the longest common prefix string amongst an array of strings.*解法:如果为空的话,肯定是返回空串了。如
2015-11-09 13:20:12
328
原创 [LeetCode]:String to Integer (atoi)
按Easy顺序刷..刚开始就遇见了面试最常见的一个题了,去年我记得也遇到过,当初答得发水的,今天都又被坑了好几发.Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, plea
2015-11-06 13:34:12
339
原创 [LeetCode]:Reverse Integer(Only两类解法)
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321题目大意比较简单,就是把一个整数反转,这个比较容易,但需要注意的是,返转过后,有可能溢出,所以这题的坑就是在溢出这里。解法一:先把result定义成long long直接翻转,最
2015-11-05 13:13:25
521
原创 [LeetCode]:ZigZag Conversion
今天开始写下LeetCode.然后按顺序搬到这里和github吧,旨在更短,更效率,同时要便于理解.[ZigZag Conversion]The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to disp
2015-11-04 13:38:41
392
原创 这两三个人的微软笔试面试题
下次的应届生招聘,要叫学弟学妹们早点参与,目测前期会容易那么一占点,后面会严一些,因为我觉得君蠔的技术面试很不错了,但还是跪了(摸摸头,,不说了,我把这次还记得而且不是无脑的笔试面试题写在下面笔试:1,苏州有N(100)个景点,是一棵树,主角站在1节点,每去一个点,就会获得相应的权值,有k个点是一定要去的,问走完m个点能获得最大的权值是多少(包括1节点),没有答案输出-1.
2015-01-27 17:40:37
618
原创 我用到的Mac .bash_profile
export CLICOLOR=1export LSCOLORS=ExFxCxDxBxegedabagacadexport PATH="/usr/local/bin:/usr/local/sbin:$PATH"PATH="/usr/local/bin:$PATH"export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH"expo
2014-11-21 15:39:59
719
原创 【mac OS X】nginx-apache-php-fpm
1, apache工作方式:监听一个端口(eg.80), 文件把内容通过tcp/http协议传到这个端口,apache查看文件后缀,决定用哪个库解读它,用哪个库是怎么决定的呢,在配置文件中有若干LoadModule xxx/../xxx.so这样的东西,.so就是一个库,解读特定文件的库。那个库解读完后返回给apache,apache再把内容返回给客户端.eg(#代表注释).Loa
2014-11-20 19:45:40
993
原创 编译原理实验一
#include#includechar prog[80],token[80];char ch;int syn,p,m,n,sum,sum1,flag;char *rwtab[10]={"function","if","then","while","do","endfunc"};void scaner();int main(){ FILE *pfile; //pfile=f
2013-12-23 16:24:36
1033
原创 从0,1,2...n中统计0,1,2...9各出现了多少次【SWUN1597】
给你一个n,统计一下从0,1,2,3,4,5,,,,,,n-1,n中计算出0,1,2,3,,,,7,8,9分别出现了多少次...
2013-10-12 21:49:07
1523
原创 0 1分数规划的Dinkelbach算法...
个人觉得此文章不错:http://www.cnblogs.com/perseawe/archive/2012/05/03/01fsgh.html double ret=0.0,tmp=0.0; do { ret=tmp; tmp=work(...,tmp);//tmp=new tmp }while(fabs(ret-tmp)>=eps);
2013-09-29 21:52:48
1184
翻译 HDU 4725 The Shortest Path in Nya Graph-【SPFA最短路】
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4725题意:有N个点和N层..一层有X个点(0题解:依然是在点之间SPFA。不过在跑的时候不仅要跑与当前点相连接的点。还有把当前点所在层的相邻层的点判断是否加入队列...CODE:#include#include#include#include#inclu
2013-09-13 08:46:42
2056
原创 【一句话博客】_CodeForces 55D Beautiful numbers
题目:http://codeforces.com/problemset/problem/55/D一个数要想被它的每一位非0数字整除,那这个数字必须被它们的最小公倍数整除...1...9的最小公倍数是2520,,但两两的公倍数一共只有48个...
2013-09-01 16:40:08
836
原创 POJ 1470/PKU 1470 Closest Common Ancestors __LCA
题目链接:http://poj.org/problem?id=1470题目大意:开始让你构造一棵树,然后有Q对u,v,最后让你求出每对u,v的最近祖先的编号和次数。输入一个Q,然后有Q组(u,v)每组中间还有空格,tab等。但,稍稍想一下就能发现,Q组uv一共有Q*2个字符串,所以我们讲稿Q*2组str就可以了scanf("%s",str),然后处理每组str求得u,v/*
2013-06-15 23:11:15
1106
1
原创 HDU 2063 过山车
题上链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063题上要求找一个二分图最大匹配;/****************************HDU 2063By: South_streamEmail: South_stream@163.com****************************/#include#inclu
2013-04-23 15:45:23
793
原创 HDU 4452 Running Rabbits 【模拟】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4452所说这题把我队友坑了好几天。思维有洞呀,我没有想到什么bug去帮他解决。最后也是根据题意直接模拟过的。#include#includeusing namespace std;int Map[25][25];struct Rabbit{ int x,y; in
2012-11-07 17:39:34
809
原创 PKU 2481 Cows & PKU 2352 Stars & HDU 1541 Stars
题目链接地址:PKU 2481:http://poj.org/problem?id=2481PKU 2352:http://poj.org/problem?id=2352HDU 1541:http://acm.hdu.edu.cn/showproblem.php?pid=1541其中PKU 2352和HDU 1541是一样的。 = =、、买一送一。。 ***********
2012-08-23 00:26:07
1025
原创 HDU 1983 Kaitou Kid - The Phantom Thief (2)
Problem Description破解字迷之后,你得知Kid将会在展览开始后T分钟内盗取至少一颗宝石,并离开展馆。整个展馆呈矩形分布,划分为N*M个区域,有唯一的入口和出口(不能从出口进入,同样不能从入口出去)。由某个区域可直接移动至相邻四个区域中的一个,且最快需要一分钟。假设Kid进入放有宝石的区域即可盗取宝石,无需耗时。问至少要封锁几个区域(可以封锁放有宝石的区域,但不能封锁入口和出口
2012-08-16 17:21:14
969
原创 HDU 1428 漫步校园(记忆化搜索)
Problem DescriptionLL最近沉迷于AC不能自拔,每天寝室、机房两点一线。由于长时间坐在电脑边,缺乏运动。他决定充分利用每次从寝室到机房的时间,在校园里散散步。整个HDU校园呈方形布局,可划分为n*n个小方格,代表各个区域。例如LL居住的18号宿舍位于校园的西北角,即方格(1,1)代表的地方,而机房所在的第三实验楼处于东南端的(n,n)。因有多条路线可以选择,LL希望每次的
2012-08-13 14:02:13
1002
原创 HDU 1880 魔咒词典 (二分搜索)
Problem Description哈利波特在魔法学校的必修课之一就是学习魔咒。据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔咒,所以他需要你的帮助。给你一部魔咒词典。当哈利听到一个魔咒时,你的程序必须告诉他那个魔咒的功能;当哈利需要某个功能但不知道该用什么魔咒时,你的程序要替他找到相应的魔咒。如果他要的魔咒不在词
2012-08-13 00:01:49
1207
1
原创 hdu 1238 & POJ 1226 Substrings
hdu题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1238POJ题目链接:http://poj.org/problem?id=1226Problem DescriptionYou are given a number of case-sensitive strings of alphabetic characters, find the
2012-08-09 16:34:56
1239
原创 hdu 1010 Tempter of the Bone
Problem DescriptionThe doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He re
2012-08-08 17:31:18
632
原创 next_permutation & prev_permutation & hdu 1027 Ignatius and the Princess II
两个STL库函数next_permutation & prev_permutation本来不会,但看了别人的blog后有点感觉了!他的blog中没有样例(题解),而我有,所以我写成原创应该不算过分吧!如果想多了解两个函数可以去他的blog看看。blog链接:http://blog.youkuaiyun.com/aipb2008/article/details/2227490 next_perm
2012-08-07 22:04:15
727
原创 swun 1429&hdu 4320 进制转化(大牛&小牛代码)
描述最近小胖对小数的进制转换非常感兴趣。并且研究了整整一周。小胖发现,有些进制的小数是无法完全转化成另一进制的小数。比如 十进制的0.1 转化成 三进制 。现在,小胖要来考验你们了。 输入第一行输入一个整数T,代表有T组测试数据。(T对于每组测试数据,有两个整数A、B。(1输出对于每组测试数据,输出样式请参照样例输出。如果A进制的小数
2012-08-04 09:46:59
1119
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人