- 博客(78)
- 收藏
- 关注
转载 编译原理 语法分析器
当一个文法满足LL(1)条件时,我们就可以为它构造一个不带回溯的自上而下分析程序,这个分析程序是由一组递归过程组成的,每个过程对应文法的一个非终结符。这样的一个分析程序成为递归下降分析器。 例:一个支持 +,*,(,) 的简单文法为(用$表示空字符): E -> TE' E -> +TE' | $ T -> FT' T' -> *FT' | $ ...
2016-06-11 09:39:00
246
转载 2016 百度之星 复赛 - 拍照
小明在旅游的路上看到了一条美丽的河,河上有许多船只,有的船只向左航行,有的船只向右航行。小明希望拍下这一美丽的风景,并且把尽可能多的船只都完整地拍到一张照片中。 小明位于河的边上,并且可以在河边的任意位置进行拍照,照相机的视野恰好为90度角,只能以垂直于河边的方向进行拍照。河上的船只全都可看作是平行于河边的一条线段,跟河边的距离各不相同,有的正在向左移动,有的正在向右移动,但移...
2016-05-31 09:54:00
176
转载 2016 百度之星 初赛B - 瞬间移动(逆元)
规律是杨辉三角,也就是求排列组合。因为要取模,所以需要用到逆元。 #include "algorithm" #include "iostream" #include "cstring" #include "cstdio" #include "string" #include "stack" #include "cmath" #include "queue" #in...
2016-05-25 19:52:00
150
转载 Hdu 5696 区间价值(2016百度之星初赛Astar Round2B )(线段树)
思路来源于:http://blog.csdn.net/kk303/article/details/51479423 注意数组用 long long 存,否则WA。 /* Problem : Status : By wf, */ #include "algorithm" #include "iostream" #include "cstring" #inc...
2016-05-24 21:03:00
157
转载 Manacher算法(HDU3068 最长回文)
有一篇歪果仁写的关于Manacher的文章,个人感觉写的很好,尤其是配的插图,非常易于理解。 地址:http://articles.leetcode.com/longest-palindromic-substring-part-ii 下面是我趁热做的HDU3068。 /* Problem : Status : By wf, */ #include "a...
2016-05-17 09:47:00
125
转载 2016"百度之星" - 资格赛 解题报告
这次的百度之星,不得不吐槽下系统的判题数据,被坑了不知多少次。 第一题:大意:求一段区间的累乘。用线段树即可。坑点:如果询问范围超出边界,输出上一次的结果。 /* Problem : Status : By wf, */ #include "algorithm" #include "iostream" #include "cstring" #i...
2016-05-16 12:36:00
130
转载 ZOJ 3703 Happy Programming Contest(01背包的灵活运用)
一道模拟刷题的题: 输出能够获得的最高的分值;如果有相同的,输出做题数量多的;如果还有相同的,输出罚时少的。 /* Problem : Status : By wf, */ #include "algorithm" #include "iostream" #include "cstring" #include "cstdio" #include "st...
2016-05-14 10:39:00
147
转载 LA 3942 Remember the Word (Trie树)
——刘汝佳的白皮书里面介绍的题目。 /* Problem: Status : By WF, */ #include "algorithm" #include "iostream" #include "cstring" #include "cstdio" #include "string" #include "stack" #include "cmath" #...
2016-05-13 22:39:00
120
转载 ZOJ 3700 Ever Dream(Vector)
做了这道题,算是会vector了。 /* Problem : Status : By wf, */ #include "algorithm" #include "iostream" #include "cstring" #include "cstdio" #include "string" #include "stack" #include "cmath...
2016-05-12 20:31:00
127
转载 Hdoj 1686 Oulipo
/* Problem : Status : By wf, */ #include "algorithm" #include "iostream" #include "cstring" #include "cstdio" #include "string" #include "stack" #include "cmath" #include "q...
2016-05-12 09:54:00
144
转载 hdu 2795 Billboard(线段树)
题意:h*w的木板,放进一些1*L的物品,求每次放空间能容纳且最上边的位子 题目给出1 <= h,w <= 10^9; 1 <= n <= 200,000,数组存不下10^9。 实际上最多用到前n行,也即是可以这样理解h<=n,然后就够了。 /* Problem :http://acm.hdu.edu.cn/showproblem.php?...
2016-04-26 20:04:00
138
转载 hdu 1754 I Hate It(一个AC了,却有着奇葩问题的题目)
这道题目,近来为了熟悉线段树,有做了一遍。 本来不难,却发现一个奇葩问题(见代码72行): #include "algorithm" #include "iostream" #include "cstring" #include "cstdio" #include "string" #include "stack" #include "cmath" #inclu...
2016-04-23 20:26:00
110
转载 ZzuliOJ 1877 蛤玮打扫教室(线段树)
题目链接:http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1877 #include "algorithm" #include "iostream" #include "cstring" #include "cstdio" #include "string" #include "stack" #include "cmath...
2016-04-23 17:37:00
161
转载 ZZULIOJ 1875: 蛤玮的财宝(三维DP)
郑州轻工业大学“玲珑杯ACM程序设计比赛”第二题 官方题解: 由于只能往下往右走,所以两条路径的长度是一样的,用dp[l][i][j]表示两个人都走了l步,第一个人在第i行,第二个人在第j行所能得到的最大值,两个人分别往下或往右走一步,有四种转移,如果走到了相同点则权值只加一个. 比赛时搞了好久也没搞出来,看了题解后做了一下。AC后对比标准程序,发现比标程简洁些:) ...
2016-04-22 16:01:00
154
转载 郑州轻工业大学 ACM比赛记录
比赛从中午12点到下午5点,总共有160支参赛队伍,包含10道题目,难易都有,是一场合适的比赛。 该比赛题目及最终做题情况如下: Problem ID Title Source AC Submit Problem A 蛤玮学计网 81 680...
2016-04-17 22:15:00
478
转载 编译原理 - 词法分析器
样例输入:if num > 100 then num2 = 100 else num2 = 0 ; # 样例输出: #include "cstdio" #include "cstring" #include "cctype" const int ERROR = -1 ; const int OVER = 0 ; const int BEGIN =...
2016-04-12 11:46:00
111
转载 安卓上传文件至PHP服务器
前两个月有幸参加一次免费培训,开发了一款小软件。发现AsyncHttpClient还真是好用。 直奔主题,安卓上传文件至PHP服务器: 1.PHP端服务器: <?php //链接数据库 include ("config/db.php"); //获取用户id $userid = $_POST['userid']; //处理上传文件 $base...
2016-04-06 21:15:00
307
转载 hdu 5631 Rikka with Graph 并查集
众所周知,萌萌哒六花不擅长数学,所以勇太给了她一些数学问题做练习,其中有一道是这样的: 给出一张 n 个点 n+1 条边的无向图,你可以选择一些边(至少一条)删除。 现在勇太想知道有多少种方案使得删除之后图依然联通。 /* Title : Status: By wf, */ #include <algorithm> #include <...
2016-03-03 22:50:00
137
转载 安卓开发:查询本周、本月等的起始日期
用法: SearchDate date = new SearchDate(index);//index值为0到4,含义见下面代码String startTime = date.getStartTime();String endTime = date.getEndTime(); import java.text.SimpleDateFormat; import java.u...
2016-01-17 20:30:00
194
转载 hdu1043 Eight(康拓展开,记录路径)
利用康拓展开可以实现没有重复的hash判重。 用 pre[i] 数组存储上一步 i 。 用 walk[i] 数组存储从 pre[i] 到 i 的方向。 /* title :Eight status:AC by wf,2016.1.10 */ #include <algorithm> #include <iostream> #includ...
2016-01-10 19:49:00
121
转载 hihocoder 1151 骨牌覆盖问题 二 (矩阵快速幂)
思路见hihocoder,用的kuangbin的矩阵快速幂,一次AC,6的一笔。 #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <string> #include <stack&g...
2015-12-21 17:47:00
163
转载 hdu 1254 推箱子
用BFS让箱子走一遍即可。 其中判断箱子能否往前走,除了看它前面是否为墙,还要判断人能不能到它后面的方格。 还有标记状态,箱子和人有一个位置不同,便是不同的状态。我用的哈希判重,其实开个四维数组也行,毕竟数据范围不大。 #include <algorithm> #include <iostream> #include <cstring> ...
2015-12-10 15:15:00
92
转载 hdu 1539 Shredding Company ( DFS )
这道题,用string过不了,需用char数组。但是我不知道为什么。 题意:把一串数字拆分成几部分,使得和不超过给定值。求和最大的情况。 用DFS搜索。 #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #includ...
2015-12-05 14:04:00
137
转载 hdu1134 Game of Connections 高精度 四则运算 模板
即卡特兰数。 #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <string> #include <stack> #include <cmath> #inc...
2015-11-19 21:42:00
140
转载 hdu 5524 Subtrees 递推
二叉树如下: 1 / \ 2 3 / \ / \ 4 5 6 7 / \ / 8 9 10 从最后一个节点n开始沿着父节点往上爬,直到1(上图中就是:10->5->2->...
2015-11-03 20:29:00
116
转载 一些数论函数
1.计算a^b mod n //计算a^b mod n ll modexp(ll a,ll b,ll n) { ll ret=1; ll tmp=a; while(b){ //基数存在 if(b&1) ret=ret*tmp%n; tmp=tmp*tmp%n; b>>=1; } return ret; } ...
2015-10-30 19:42:00
117
转载 hdu 5480 Conturbatio (前缀和)
用两个数组,分别记录车所占的行和列的前缀和,每次查询可直接计算。 多亏这道题二维数组开不下,否则还真有可能想不到这种方法。 /* Title :Conturbatio Status:AC By wf,2015 09 26 */ #include <algorithm> #include <iostream> #include <cs...
2015-09-28 14:27:00
146
转载 hdu 5479 Scaena Felix (好坑的简单题)
坑点较多,能过以下数据估计就可以了。 样例:4()(((((()))))()(()))((()(((输出:1024 首先,遍历一遍,计算“(”和“”的个数,取最小值记为ans。 然后,判断有没有“)(”这种字串,有的话,最终的串要转换为“...)))))(((((...”这种形式。 用两个数组:dp1从左到右计算“)”的个数前缀和;dp2从右往左计算“(”的个数后缀和。 遍历一...
2015-09-28 14:22:00
149
转载 hdu 5465 Clarke and puzzle(树状数组 或 前缀和 + Nim游戏)
本题可转化为:求一个二维数组 (x1,y1)到(x2,y2) 每个元素的异或值,判断是否为0。 本题的两个相似解法:1.前缀和2.树状数组 #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <...
2015-09-22 08:48:00
124
转载 uva 10534 Wavio Sequence(LIS)
PS:求最长上升子序列的n*log(n)的做法: 建一个栈,从前往后遍历数组a[]。 如果栈顶值小于a[i],把a[i]进栈;否则,把栈中第一个大于等于a[i]的数替换为a[i]。 #include <algorithm> #include <iostream> #include <cstring> #includ...
2015-09-19 09:09:00
127
转载 hdu 5433 Xiao Ming climbing (BFS)
DFS超时,当时头脑混乱不会改成BFS。过了两天,思路清晰,一次AC,真爽。 思路:用dp[x][y][p]表示走到(x,y)且剩余斗志为p的最少体力,bfs的过程中,只有满足边界条件并且下一步算出来的值要小于dp[next.x][next.y][next.p]时才把这个点放入队列。 #include <algorithm> #include <iostr...
2015-09-16 20:08:00
142
转载 hdu 5285 wyh2000 and pupil(二分图判定)
对每两个不认识的人连一条边,则此题可转化为二分图判定(用染色法。注意:二分图可有多个)。 如果有一部分图判定为不是二分图,则输出“Poor wyh”。 否则,分别累加每个二分图的最多的颜色数。 #include <algorithm> #include <iostream> #include <cstring> #include ...
2015-09-10 22:05:00
121
转载 la 2965 Jurassic Remains (中途相遇法)
把串分成前后两半,前面的做暴力枚举,并把结果丢到集合里去, 后面的也暴力枚举,并且每次的结果去集合里看有无出现过相同的. 如果有那么异或后为0,就是符合题目要求的,选出包含字符串个数最多的! 这样一优化,前后两个2^12+2^12,瞬间时间复杂度开方了! #include <algorithm> #include <iostream>...
2015-09-06 20:01:00
163
转载 uva 10905 Children's Game (用String的话,就是水题)
本以为string会耗时,就用数组,结果老是WA,没了耐心找错误,就换成string,秒过! #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <string> #include ...
2015-09-06 11:30:00
82
转载 uva 10382 Watering Grass (最少区间覆盖)
首先,直径小于草坪宽度的喷水器不选。 然后,按喷水器能够覆盖草坪的矩形范围 转换成 区间覆盖问题。 #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <string> #in...
2015-09-06 09:44:00
104
转载 hdu 5418 Victor and World (最短哈密顿回路)
给你n个国家,m条路线:u_i与v_i之间的距离w_i。 输出从1号国家出发经过每个国家至少一次再回到1号国家的最短距离。 【官方题解】: 我们首先需要预处理出任意两个国家之间的最短距离,因为数据范围很小,所以直接用Floyd就行了。 之后,我们用f[S][i]表示访问国家的情况为S,当前最后访问的一个国家是i所需要的最小总油量,其中,S的二进制表示记录了访问国家...
2015-09-04 16:54:00
230
转载 hdu 5206 Four Inages Strategy (空间向量)
中文题目:《四象阵法》 判断空间四点能否组成正方形。 一次AC,好激动~ #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <cmath> typedef long long ll;...
2015-09-03 16:48:00
139
转载 la 3029 City Game (扫描法)
题目链接 思路:对每一个格子进行处理:计算包含它的最大矩形。 up[i][j]: 存储矩形的高; left[i][j]: 存储矩形的左边界的列号; right[i][j]:存储矩形的右边界的列号。 面积 = up[i][j] * ( right[i][j] - left[i][j] +1 )。 心得:即便是有了思路,写代码前也要在纸上画画,模拟模拟。否则就像...
2015-08-19 15:59:00
135
转载 uva 10054 The Necklace(欧拉通路)
提交了7次,总算AC了。题目不难,就是判断下欧拉通路。注意细节。 /* Status:AC Title :The Necklace */ #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <...
2015-08-17 17:07:00
103
转载 Hdu 5366 The mook jong 公式求解
The mook jong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 ZJiaQ为了强身健体,决定通过木人桩练习武术。ZJiaQ希望把木人桩摆在自家的那个由1*1的地砖铺成的1*n的院子里。由于ZJiaQ是个强迫症,所以他...
2015-08-09 09:19:00
158
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅