自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(744)
  • 收藏
  • 关注

原创 Manacher 算法详解:O(n) 复杂度求最长回文子串

先预处理下:在每个字符的两边都插入一个特殊的符号,比如abba变成#a#b#b#a#,aba变成#a#b#a#(因为Manacher算法只能处理奇数长度的字符串)。同时,为了避免数组越界,在字符串开头添加另一特殊符号,比如$#a#b#a#。以字符串3212343219为例,处理后变成S[] = "$#3#2#1#2#3#4#3#2#1#9#"。然后用一个数组Len[i]来记录以字符S[i

2014-02-03 12:27:09 4292 2

转载 程序员技术练级攻略

月光博客6月12日发表了《写给新手程序员的一封信》,翻译自《An open letter to those who want to start programming》,我的朋友(他在本站的id是Mailper)告诉我,他希望在酷壳上看到一篇更具操作性的文章。因为他也是喜欢编程和技术的家伙,于是,我让他把他的一些学习Python和Web编程的一些点滴总结一下。于是他给我发来了一些他的心得和经历

2013-08-19 11:48:38 2190 1

原创 基于链表实现的珂朵莉树

以下内容基于 CF896C Willem, Chtholly and Seniorious 来介绍。珂朵莉树实质上是一种可以维护区间上的分裂与合并的数据结构,但要求数据是随机的,或者有大量的随机合并操作,这样才能保证维护的区间个数是一个很小的值。一开始,我们用不同的节点表示 [1,1],[2,2],...,[n,n][1,1],[2,2],...,[n,n][1,1],[2,2],...,[n...

2019-10-29 22:18:17 608 1

原创 Codeforces 1251D Salary Changing (二分+最大化中位数)

https://codeforces.com/problemset/problem/1251/D提供一个比官方题解还简洁的二分思路。首先,中位数越大,发出的工资越多,这满足二分条件。于是二分中位数,判断所发工资是否不超过 sss,整个过程如下:二分前预处理,将数据按照 lll 从大到小排序,另外还需计算基础工资之和 baseCostbaseCostbaseCost,即所有 lll 之和...

2019-10-28 18:10:16 451

原创 UVa 11178 Morley's Theorem (向量旋转)

http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2119/*0.025s*/#include#includestruct P{ double x, y; P(double x = 0.0, double y = 0.0): x(x), y(y) {} v

2014-03-27 16:35:30 1464

原创 LightOJ 1258 Making Huge Palindromes (回文&KMP)

http://lightoj.com/volume_showproblem.php?problem=1258首先原串+翻转过来的串必然是一个回文串,但是二者在中间可以“融合”,而KMP算法恰好可以求出最大融合长度。所以看翻转过来的串能匹配多少原串即可,答案就是len+(len-匹配个数)。完整代码:/*0.140s,7548KB*/#includeusin

2014-03-27 13:40:28 1799

原创 LightOJ 1255 Substring Frequency (KMP模板)

http://lightoj.com/volume_showproblem.php?problem=1255/*0.068s,7548KB*/#includeusing namespace std;const int mx = 1000005;char t[mx], p[mx];int f[mx];void getfail(){ f[0] = f[1] = 0

2014-03-26 23:27:28 1403

原创 LightOJ 1062 Crossed Ladders (二分)

http://lightoj.com/volume_showproblem.php?problem=1062/*0.000s,1700KB*/#includeusing namespace std;double EPS = 1e-8;int main(){ double a, b, c, j, c1, h, k, x; int T, cas = 0; scanf("

2014-03-26 18:57:16 1480

原创 LightOJ 1203 Guarding Bananas (凸包最小顶角)

http://lightoj.com/volume_showproblem.php?problem=1203/*0.164s,6512KB*/#includeusing namespace std;#define sqr(x) ((x)*(x))const double INF = 1e100;const double pi = acos(-1.0);const doub

2014-03-26 17:52:26 1442

原创 Python version 2.7 required, which was not found in the registry

安装Python时没注册注册表?好办,把下面的代码放到你Python所在目录,运行即可。## script to register Python 2.0 or later for use with win32all# and other extensions that require Python registry settings## written by Joakim

2014-03-26 10:27:21 1147

原创 LightOJ 1085 All Possible Increasing Subsequences (DP&离散化&树状数组)

http://lightoj.com/volume_showproblem.php?problem=1085先说个很快的方法——二维思考,从右下往左上离散化:/*0.364s,2860KB*/#includeusing namespace std;const int mx = 100005;const int mod = 1000000007;int tree[m

2014-03-25 21:28:21 1593

原创 LightOJ 1009 Back to Underworld (种类并查集)

http://lightoj.com/volume_showproblem.php?problem=1009种类并查集实现(当然用二分图染色也可以)/*0.204s,2820KB*/#includeusing namespace std;const int mx = 20000;int fa[mx * 2 + 5], rk[mx * 2 + 5], x[100005

2014-03-24 16:35:47 1699

原创 LightOJ 1080 Binary Simulation (线段树&成段更新)

http://lightoj.com/volume_showproblem.php?problem=1080模板。/*0.484s,4312KB*/#include #include #include using namespace std;#define lson l , m , rt << 1#define rson m + 1 , r , rt << 1 | 1

2014-03-24 08:18:36 1404

转载 SGU 108 Self-numbers 2 (另一种滚动数组)

http://acm.sgu.ru/problem.php?contest=0&problem=108我直接转的http://www.cnblogs.com/staginner/archive/2011/12/24/2300689.html他写得很好:这个题目可以直接筛出来结果,但要注意几个问题:①数组不够大,但由于推断的时候前后影响的区间并不大,因此我们可以把

2014-03-23 20:49:53 1400

原创 SGU 104 Little Shop of Flowers (DP&打印路径)

http://acm.sgu.ru/problem.php?contest=0&problem=104/*15ms,142KB*/#includeusing namespace std;const int mx = 105;int a[mx][mx], dp[mx][mx], f;void print(int i, int j){ if (i == 0) retur

2014-03-23 18:35:29 1377

原创 Codeforces Round #227 (Div. 2) / 387C George and Number (贪心)

http://codeforces.com/contest/387/problem/C/*31ms,100KB*/#includechar str[100005];int main(){ gets(str); int i, j, res = 0; for (i = 0; str[i]; i = j) { for (j = i + 1; str[j] == '0

2014-03-22 18:12:42 1187

原创 POJ 3104 Drying (二分&最大化最小值)

http://poj.org/problem?id=3104一开始没注意k为1的情况,WA了一发。。加个特判就过了。完整代码:/*750ms,576KB*/#include#include#includeusing namespace std;const int mx = 100005;int n, k, a[mx];bool judge(int

2014-03-22 10:10:20 1270

原创 POJ 3273 Monthly Expense (二分&最大化最小值)

http://poj.org/problem?id=3273/*63ms,556KB*/#includeconst int mx = 100005;int n, mon, a[mx];bool judge(int m){ int sum = 0, cnt = 1; for (int i = 0; i < n; ++i) { sum += a[i]; if

2014-03-22 09:38:17 1137

原创 POJ 2932 Coneology (扫描线判断最外面的圆&set维护最近的圆)

http://poj.org/problem?id=2932先给圆的最左端和最右端的点排个序,当两点x相同时,左端点排在前面。然后就是扫描了,若扫描到的是圆的左端点,就判断圆心(y坐标)在其上方且离其最近的圆是否包含此圆,以及圆心(y坐标)在其下方且离其最近的圆是否包含此圆,若包含就continue,不包含就insert到set中;若扫描到的是圆的右端点,就从set中era

2014-03-20 15:08:49 1144

原创 Codeforces Round #237 (Div. 2) / 404B Marathon (fmod或long long表示浮点)

http://codeforces.com/contest/404/problem/B/*124ms,0KB*/#includeusing namespace std;double a;void f(double len){ int c = ((int)(len / a)) % 4; len = fmod(len, a); if (c == 0) printf("

2014-03-20 09:40:48 1141

原创 Codeforces Round #237 (Div. 2) / 404C Restore Graph (构造最短路径树)

http://codeforces.com/contest/404/problem/C思路:我们构造一颗最短路径树就行了。若能够构造,边数必然为n-1(样例1的边数可以是两条)。如何构造?从距离为1的点开始,逐渐往下加边,生成一颗k叉树。若在中间生成了大于k的叉,则输出-1。完整代码:/*265ms,4436KB*/#includeusing namesp

2014-03-20 09:28:28 1696

原创 HDU 4741 Save Labman No.004 (异面直线距离&直线与平面的交点)

http://acm.hdu.edu.cn/showproblem.php?pid=4741模板题。理论知识见代码注释。这题背景居然是命运石之门。。/*218ms,276KB*/#include#includeconst double eps = 1e-9;struct P3{ double x, y, z; P3(double x = 0.0, do

2014-03-16 19:20:13 1244

原创 Codeforces Round #185 (Div. 1) / 311A The Closest Pair (“陷阱”题)

http://codeforces.com/problemset/problem/311/AIf we ignore "break", tot will be up to .Consider whether we can make such inequality d ≤ p[j].x - p[i].x is always false. The obvious way

2014-03-15 13:15:35 1353

原创 Codeforces Round #183 (Div. 1) / 303A Lucky Permutation Triple (强大的数学&想法题)

http://codeforces.com/problemset/problem/303/Awhen n is odd, A[i] = B[i] = iwhen n is even, there is no solution.why? If , then  or just , where S = 0 + 1 + ... + n - 1 = n(n - 1) / 

2014-03-15 12:35:29 1776

原创 Codeforces Round #206 (Div. 2) / 355C (转化&枚举)

http://codeforces.com/contest/355/problem/C枚举i,左手操作了i次,右手操作了n-i次,然后重复次数可以直接算出来,所以答案就可以在O(n)的时间内算出来。/*30ms,4000KB*/#includeusing namespace std;int a[100005];int main(){ int n, l, r,

2014-03-14 20:17:32 958

原创 Codeforces Round #217 (Div. 2) / 370C Mittens (构造&贪心)

http://codeforces.com/contest/370/problem/C/*31ms,0KB*/#include#includeusing namespace std;int C[5005];int main(){ int N, M; cin >> N >> M; for (int i = 0; i > C[i]; sort(C, C + N

2014-03-14 20:07:18 1232

原创 Codeforces Round #217 (Div. 2) / 370B Berland Bingo (set_union)

http://codeforces.com/contest/370/problem/B/*15ms,200KB*/#includeusing namespace std;vector v[105], tmp(105);int main(){ int n, i, j, k, x; scanf("%d", &n); for (i = 0; i < n; ++i) {

2014-03-14 16:57:41 1211

原创 Codeforces Round #197 (Div. 2) / 339C Xenia and Weights (爆搜)

http://codeforces.com/contest/339/problem/C爆搜水过,复杂度貌似是O(m)的?/*62ms,4KBm*/#includeint m, ans[1005]; ///ans从1开始char s[15];bool ok;///O(m)复杂度?int dfs(int deep, int diff) /// diff表示重量之差{

2014-03-14 16:24:46 1312

原创 Codeforces Round #198 (Div. 2) / 340B Maximal Area Quadrilateral (点集中的最大四边形)

http://codeforces.com/contest/340/problem/B枚举一条线段,再枚举这条线段左右两边的三角形,拼起来就是一个四边形了。完整代码:/*186ms,0KB*/#includeusing namespace std;int x[300], y[300], A[2];int main(){ int n, i, j, k,

2014-03-14 14:19:20 1172

原创 Codeforces Round #196 (Div. 2) / 337D Book of Evil (树的直径变形——树的最长标记弦)

http://codeforces.com/contest/337/problem/D/*154ms,10300KB*/#includeusing namespace std;const int mx = 100005;vector g[mx];int d1[mx], d2[mx], p[mx];void dfs(int p, int u, int deep, i

2014-03-13 16:05:58 930

转载 汇编端口及其作用详细列表

原文见:http://blog.chinaunix.net/uid-7672958-id-2598950.html[This file was provided by Wim Osterholt (2:512/56 or [email protected]).]Last Change: 11/6/94  XT, AT and PS/2  I/O por

2014-03-13 12:06:40 3914

原创 Codeforces Round #209 (Div. 2) / 359D Pair of Numbers (一点点想法)

http://codeforces.com/problemset/problem/359/D/*124ms,2300KB*/#includeint a[300005], w[300005];int main(){ int n, i, l, r, cnt = 0, maxd = 0; scanf("%d", &n); for (i = 0; i < n; i++) s

2014-03-12 21:25:26 1137

原创 Codeforces Round #120 (Div. 2) / 190D Non-Secret Cypher (计数&two pointers)

http://codeforces.com/contest/190/problem/D【神题必有神解】从这一题可大题了解two pointers算法的威力。/*1024ms,42062KB*/#includeusing namespace std;const int mx = 400005;int a[mx];map mp;/*数据例子:10 22 3

2014-03-12 19:54:31 1508

原创 Codeforces Round #218 (Div. 2) / 371B Fox Dividing Cheese (想法题)

http://codeforces.com/contest/371/problem/B神题必有神解——你能想到这么做吗?/*15ms,0KB*/#includeusing namespace std;int op_cnt[6];int main(){ int a, b, ans = 0; cin >> a >> b; for (int n = 2; n <=

2014-03-12 12:59:43 1553

原创 Codeforces Round #218 (Div. 2) / 371C Hamburgers (二分)

http://codeforces.com/contest/371/problem/C直接二分能做的汉堡数,注意上界要开大一点。完整代码:/*15ms,0KB*/#includeusing namespace std;const long long mx = 1e13;///多开一位,因为结果可以略大于1e12const char b[] = "BSC";

2014-03-12 12:15:33 972

转载 i386中的状态和控制寄存器

状态和控制寄存器是由指令指针EIP、标志寄存器EFLAGS和4个控制寄存器(CR0~CR3)组成1. 指令指针寄存器和标志寄存器指令指针寄存器EIP中存放下一条将要执行指令的偏移量(offset )是相对于目前正在运行的代码段寄存器CS而言的。偏移量加上当前代码段的基地址,就形成了下一条指令的地址。EIP中的低16位可以分开来进行访问,给它起名叫指令指针IP寄存器,用于

2014-03-12 08:28:08 1737

原创 Codeforces Round #235 (Div. 2) / 410D Roman and Numbers (带有整除性质的数位DP)

http://codeforces.com/problemset/problem/401/D解释全部在代码的注释中:/*78ms,205464KB*/#includeusing namespace std;const int mx = 1 << 18;long long dp[mx][100];///dp[mask][j]表示余数为j时的mask对应的x的个数///

2014-03-11 20:25:34 2045

原创 数位DP小记 + HDU 2089 不要62

【背景】如何求出在给定区间[A,B]内,符合条件P(i)的数i的个数?条件P(i)一般与数的大小无关,而与数的组成有关,有一下几种P(i):数i是递增/递减的:1234, 2579,…双峰的:19280,26193,…含/不含某一数字的,比如含49:49, 149, 1492,… 被某一数m整除的,比如m=13:39,130,650...【思路】采用

2014-03-11 13:14:59 1905 1

原创 ZOJ 3762 Pan's Labyrinth (点集中的最大点-线距&技巧性枚举)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3762思路:(转自这篇文章)假设拥有最大高的三角形是ABC,如下图结合此图我们可以看出最大高是点C到直线AB,在这种情况下,下列两个假设至少有一个成立1.点C是所有点中距离点A最远的2.点C是所有点中距离点B最远的反证:(这里先证明在AB上侧成立的情况

2014-03-10 18:59:17 1676 2

原创 HDU 3903 Trigonometric Function (三角恒等式&余弦定理)

http://acm.hdu.edu.cn/showproblem.php?pid=3903如何判断的有理性?由这三个式子:问题可化归为判断A,B,C的正弦和余弦是否为有理数,又由余弦定理以及cos(arccos x)=x若x=p/q,则sqrt(1-x^2)=sqrt(q^2-p^2)/q故只需判断q^2

2014-03-09 12:13:41 1249

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除