- 博客(28)
- 收藏
- 关注
原创 发现一种JavaScript“类的继承”的方法
function First(a, b) { this.a = a; this.b = b;}var first = new First(1, 2);console.log(first);function Second(c, d) { First.apply(this, [1, 2]); this.c = c; this.d = d;}var second = new Se
2014-09-29 21:32:03
809
原创 NJUST 1743 Boring Game(2013南京邀请赛G题)(thx to _LT_zyc)
本做法是基于暴力枚举第一行走法的O((n^2)*(2^n))的方法的预处理优化版。 首先做一个预处理,对于空白的棋盘,枚举第一行的走法,然后以把前n-1行复原成白的为目标,逐行向下推出下面n-1行的走法,记录下最后第n行的状态和对应走法的映射(可以用邻接表)。 对于每组case,第一行不动,同样地,以把前n-1行复原成白的为目标,逐行向下推出下面n-1行的走法x,这时第n行残留下一个状
2013-05-23 13:01:19
2823
原创 HDU 4445 Crazy Tank
先反求可行的和不可行的出射角度区间,再扫描线求最大覆盖区间数。// 2013-04-23 21:46:47 Accepted 4445 15MS 256K 2249 B G++ Aros#include#include#include#includeusing namespace std;const int MAXN = 200+5;const d
2013-04-23 22:20:02
810
原创 UVALive 4004 Space Beacon
先DP预处理出以i开头、长度为j、先升/降(0/1)的序列的个数:d[i][j][0/1]。再数给出的串是第几个串。// 4004 Space Beacon Accepted C++ 0.009 2013-03-27 10:52:06#include#include#include#includeusing namespace std;const int MAXN = 18+5;
2013-03-27 19:01:58
550
原创 Codeforces 235C Cyclical Quest
对第一个串s建立后缀自动机,用父亲指针求出每个节点代表的子串在s中出现的次数。对于串x,复制一个循环节加在后面。在后缀自动机上跑一遍,如果某个节点匹配长度大于x原来的长度,检查父节点是否也大于,是的话用父节点代替当前节点,把预处理出来的该节点的出现次数累加就是答案。//Feb 21, 2013 7:32:16 AM bigoceanlhy 235C - Cyclical Quest
2013-02-21 11:46:08
1147
原创 HYSBZ 2806 [Ctsc2012]Cheat
后缀自动机+单调队列优化的DP。参考了http://hi.baidu.com/wyl8899/item/568baeed5034eec2baf37d69,其实后缀处理和DP转移自己都想到了,只差单调队列的优化。做的第一道SAM+DP的题,纪念一下~//bigoceanlhy 2806 Accepted 54516 kb 2336 ms C++/Edit 2346 B 2013-02-20 20
2013-02-20 20:50:43
953
原创 HDU 4436 str2int
把所有串用没出现过的符号相连,建立后缀自动机。记录每个节点所表示的子串对于此问题所求的sum值,再记录这个节点能收到多少个有效子串,于是就能从根结点往后递推sum值了。最后把所有有效节点的sum加起来就是答案。注意:(1)带有前缀零的子串无效;(2)带有分隔符的子串无效。//2013-02-18 13:07:47 Accepted 4436 250MS 12624K 1780 B G++
2013-02-20 20:46:34
681
原创 UVA 709 Formatting Text
d[i][j]表示第i个词于第j列开始,且后面的词按规则摆放的最小代价。因为怕搞错多解时的答案,所以用了逆推。//709 Formatting Text Accepted C++ 0.020 2012-12-19 03:06:24#include#include#include#includeusing namespace std;const int MAXN = 80+
2012-12-19 11:10:17
788
原创 UVA 10163 Storage Keepers
方法一、d[i][j][k]表示前i个人看j个货总保险值为k时的最小花费。时间复杂度较高。//10163 Storage Keepers Accepted C++ 0.236 2012-12-14 03:23:11#include#include#includeusing namespace std;const int MAXN = 100+5, MAXM = 30+5,
2012-12-14 21:06:14
516
原创 UVA 10817 Headmaster's Headache
状态压缩DP,d[i][j]表示在前i个人中聘用某些人达到状态j所需的最小花费。//10817 Headmaster's Headache Accepted C++ 0.312 2012-12-13 11:14:13#include#include#include#include#includeusing namespace std;const int MAX = 16
2012-12-13 19:21:41
756
原创 UVA 11008 Antimatter Ray Clearcutting
明显的状态压缩DP,状态转移时要分打掉一个点或者打掉一条线,用最朴素的转移,总时间复杂度是O(2^N*N^3),姿势优越的话可以水过这题。//11008 Antimatter Ray Clearcutting Accepted C++ 2.656 2012-12-12 02:15:41#include#include#includeusing namespace std;
2012-12-12 10:34:16
507
原创 UVA 10913 Walking on a Grid
设d[i][j][k]为走到(i,j)经过k个负数的收益,负无穷表示无法达到这个状态。由于只能向下、左、右且不能走回头路,于是按层DP就好了。注意用long long。//10913 Walking on a Grid Accepted C++ 0.032 2012-12-10 13:29:24#include#include#includeusing namespace
2012-12-10 21:47:57
857
原创 UVA 10313 Pay the Price
算法:用前缀和把O(n^3)的dp优化成O(n^2)。注意:(1)long long。(2)L1、L2不一定在[1,300]内。(3)没有空行(不用处理空行能过)。//10313 Pay the Price Accepted C++ 0.056 2012-11-20 11:23:14#include#include#includeusing namespace std;co
2012-11-20 19:40:47
624
原创 UVA 10534 Wavio Sequence
正反两个方向各求一遍LIS(需要O(nlogn)算法),枚举中心。//10534 Wavio Sequence Accepted C++ 0.096 2012-11-14 10:34:30#include#include#includeusing namespace std;const int MAXN = 10000+5;int N, a[MAXN];int d[2]
2012-11-14 18:48:43
593
原创 UVA 10564 Paths through the Hourglass
设d[i][j][k]表示从i行j列往下走到底路径上的和为k的方案数。//10564 Paths through the Hourglass Accepted C++ 0.072 2012-11-14 01:49:52#include#include#includeusing namespace std;const int MAXN = 40+5, MAXM = 400+5
2012-11-14 18:46:54
579
原创 HDU 4433 locker
设状态d[i][j][k]表示前i位匹配,之后两位为j、k,达到此状态的最小代价。 (1)现场写的状态转移://2012-10-29 21:07:26 Accepted 4433 687MS 4552K 3686 B G++ Aros#include#include#include#include#define MAX 10#define up(x) (x+1)%
2012-10-29 21:12:20
759
原创 Tianjin Regional——区域赛初体验
终于迎来了向往已久的区域赛。20日早上出发,上午抵达天津,领了坑爹的贴纸+秋衣的参赛服、没有印名字的胸卡、新生手册……囧。中午吃饭的时候,教练说了一些让人压力很大的话(强校强队很多什么的),这时我才感觉到此行之凶险。于是我们果断改变目标,改保铜争银为保铁争铜(太没骨气了!)。 下午睡过开幕式,便是热身赛了。这桌子真是小得一逼,施展开来很不方便呐。前两题很简单,数列求和,于是我们各
2012-10-24 11:11:27
1049
原创 Codeforces Round #142 (Div. 2)
A.贪心,每次都选剩下的里面x最小的。//Oct 1, 2012 7:42:03 PM bigoceanlhy 230A - Dragons GNU C++ Accepted 46 ms 0 KB#include#include#includeusing namespace std;const int MAXN = 1000+5;int N, s, x[MAXN],
2012-10-02 18:18:18
549
原创 HDU 4416 Good Article Good sentence
求多串的子串并集元素的个数,先用没出现过的不同的字符把多个串拼接,用后缀数组求这个串的不同子串的个数,再减去含有拼接字符的子串的个数。用上述方法求『A、B1、……、BN』中不同子串的个数sumAB和『B1、……、BN』中不同子串的个数sumB,答案就是sumAB-sumB。//2012-09-26 13:22:35 Accepted 4416 671MS 7752K 2071 B G++ Ar
2012-09-26 13:36:32
1343
1
原创 HDU 4419 Colourful Rectangle
分别求出7种矩形并的面积(离散化+扫描线+线段树),再根据容斥关系计算所求颜色面积。//2012-09-24 20:30:42 Accepted 4419 359MS 4740K 2707 B G++ Aros#include#include#include#includeusing namespace std;const int MAXN = 10000+5, MAXM = 20
2012-09-24 20:16:50
491
原创 HDU 3713 Double Maze
码农题,直接BFS,一共就6^4种状态。//2012-09-21 10:19:01 Accepted 3713 0MS 316K 3912 B G++ Aros#include#include#include#includeusing namespace std;typedef pair, pair > Node;const int MAXN = 8;int T, mat[2]
2012-09-21 10:24:45
961
原创 HDU 4293 Groups
每个有效的(A,B),都能对应到一个group的区间[A+1,N-B]。把每个group看作一个节点,权值为这个group的player出现的次数(且不能超过区间长度)。若两个区间不冲突,从左边的区间向右边的连一条有向边。加上源点和终点(连上所有节点),求最长路。//2012-09-16 18:56:27 Accepted 4293 156MS 2260K 1900 B G++ Aros#i
2012-09-16 18:55:11
1656
原创 HDU 4082 Hou Yi's secret
把三边长平方约掉最大公因数后的值作为每个三角形的特征值插入map,避免了浮点精度问题。重点算作一个点(大坑注意)。//2012-09-14 18:51:01 Accepted 4082 0MS 312K 1824 B G++ Aros#include#include#include#includeusing namespace std;const int MAXN = 18+5,
2012-09-14 18:58:43
912
原创 HDU 4276 The Ghost Blows Light
先把必经之路上的边权、点权置零,如果还剩时间就树形背包DP。//2012-09-12 21:12:38 Accepted 4276 390MS 424K 2093 B G++ Aros#include#include#includeusing namespace std;const int MAXN = 100+5, MAXM = 500+5;int N, T, a, b, t,
2012-09-12 21:14:14
456
原创 HDU 4284 Travel
floyd+状态DP,计算哈密顿回路。也就是先计算H个点的哈密顿路径,再判断能否构成起点为1的回路。//2012-09-12 10:02:47 Accepted 4284 2531MS 4364K 1945 B G++ Aros#include#include#includeusing namespace std;const int MAXN = 100+5, MAXM = 1000
2012-09-12 10:05:39
498
原创 HDU 4277 USACO ORZ
3^15暴力枚举,set判重。//2012-09-08 18:34:41 Accepted 4277 1078MS 4724K 799 B G++ Aros#include#include#include#includeusing namespace std;const int MAXN = 15+5;int T, N, l[MAXN], L[3];set > ans;v
2012-09-08 18:35:50
751
原创 ZOJ 3543 Number String
d[i][j]表示1~i的全排列中以j结尾的满足要求的方法数,sum[i][j]表示d[i][1]+...+d[i][j]。最后发现d[i][j]都是中间变量,都能消掉。//2012-09-03 17:47:34 Accepted 3543 C++ 600 4124 Aros#include#include#includeusing namespace std;const
2012-09-03 21:05:52
419
原创 Codeforces 220B Little Elephant and Array
和今年某道多校的题很像。离线+线段树区间修改、单点查询。按右端点将查询区间排序。扫描数列,假设当前数a第x次出现,那么当x>=a时,区间[pos[a][x-a]+1,pos[a][x-a+1]]上所有点+1;当x>a时,区间[pos[a][x-a-1]+1,pos[a][x-a]]上所有点-1,pos[a][x]表示数a第x次出现的位置,为了方便,设所有数第一次出现的位置为0。若当前扫描到的位置有
2012-09-01 11:05:59
573
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人