摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166线段树节点更新练习第三棵线段树……TUT…… 1 #include <cstdio> 2 #include <cstring> 3 4 const int MAXN = 50000 + 10; 5 6 struct Node 7 { 8 int l, r; 9 int sum;10 Node *l_child, *r_child;11 };12 13 int N;14 int cnt;15 Node Tree[ MAXN + MAXN ];16 17 void Bu.. 阅读全文
posted @ 2012-10-27 13:20 冰鸮 阅读(166) 评论(0) 推荐(0)
摘要: 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=111&page=show_problem&problem=77题意:判断摆放过程中是否出现已经出现过的图案,图案可以顺时针旋转90°,180°和水平翻转。分析:字符串哈希判重 1 #include <cstdio> 2 #include <cstring> 3 4 const int MAXN = 100007; 5 6 char map[52][52] 阅读全文
posted @ 2012-10-24 20:38 冰鸮 阅读(221) 评论(0) 推荐(0)
摘要: 题目链接:http://poj.org/problem?id=3468题意:给N个数,有两组操作:(1)对某个区间[a, b]中所有的数都增加c(2)求某个区间[a, b]个数的和共操作Q次,每次只输出操作(2)的结果第二棵线段树……TUT……需要用到延迟标记,每次更新不用到达叶子节点,只需要在标记上进行累加,当询问的时候再将标记向下传递。 1 #include <cstdio> 2 #include <cstdlib> 3 4 const int MAXN = 100000 + 5; 5 6 struct TNode 7 { 8 int l, r; 9 ... 阅读全文
posted @ 2012-10-23 12:18 冰鸮 阅读(187) 评论(0) 推荐(0)
摘要: 题目链接:http://poj.org/problem?id=3264题目描述:跟N个数和Q个询问,求询问区间[a, b]中最大值和最小值的差。我的第一个线段树…… 1 /* 2 Interval Tree 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <cstdlib> 7 8 const int MAXN = 50000 + 2; 9 const int INF = 2147483645; 10 11 struct Node 12 { 13 int l, r; 14 int maxi,. 阅读全文
posted @ 2012-10-22 22:26 冰鸮 阅读(144) 评论(0) 推荐(0)
摘要: 我知道写这东西挺二,可是我确实被USACO的提交折腾了很久……首先,它的TEXT Submitting Solutions里面有标程,格式照搬就行。拿PROB Your Ride Is Here为例…… 1 /* 2 ID: XXXXX //例程TEXT Submitting Solutions中有给标准格式,可以直接复制 3 PROG: ride //你所做的题目的简称(PROGRAM NAME: ride) 4 LANG: C++ 5 */ 6 #include <cstdio> 7 #incl... 阅读全文
posted @ 2012-10-20 10:29 冰鸮 阅读(450) 评论(0) 推荐(0)
摘要: 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=109&page=show_problem&problem=506题意:一群人想点一个Pizza,每个人都提出一些条件,求出一个Pizza满足每个人至少一个要求。分析:一共16中物品,每种放或不放,最多2^16中情况,用二进制表示一下就行。我做的有些麻烦了,一开始没加剪枝1,TLE,加上剪枝1过的也很悬,2.440s。剪枝1:如果这种选法选择了未出现的物品,则不符合条件。剪枝2:如果满足了这个人的某 阅读全文
posted @ 2012-10-17 20:53 冰鸮 阅读(360) 评论(0) 推荐(0)
摘要: 简单的分解质因数约分 1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 5 const int MAXN = 10000 + 10; 6 7 bool Prime[MAXN]; 8 9 int aaa[5]; 10 int bbb[5]; 11 int num[2][MAXN]; 12 13 void GetPrime() 14 { 15 memset( Prime, true, sizeof(Prime) ); 16 Prime[0] = false ; 17 Pr... 阅读全文
posted @ 2012-09-26 22:36 冰鸮 阅读(259) 评论(0) 推荐(0)
摘要: 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1611简单的贪心 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 5 const int MAXN = 110; 6 7 struct worker 8 { 9 char name[20];10 int A, B;11 in 阅读全文
posted @ 2012-09-03 23:15 冰鸮 阅读(290) 评论(0) 推荐(0)
摘要: 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1659题意:给出数N, L, U, 求一个数M, L ≤ M ≤ U,使得 N 与 M 按位或运算的结果最大,求最小的 M。分析:贪心。从最高位开始枚举,如果 N 的二进制表示形式的第 i 位是0,那么就尽可能让 M 的第 i 位在给定范围内是1。如果 N 的二进制表示形式的第 i 位是1,因为要求最小的M,则 M 的第 i 位要在给定范围 阅读全文
posted @ 2012-09-03 22:28 冰鸮 阅读(222) 评论(0) 推荐(0)
摘要: 题目链接:http://poj.org/problem?id=2488分析:简单DFS,注意字典序最小 1 #include <cstdio> 2 #include <cstring> 3 4 const int dx[] = { -1, 1, -2, 2, -2, 2, -1, 1 }; 5 const int dy[] = { -2, -2, -1, -1, 1, 1, 2, 2 }; 6 const int MAXN = 30; 7 8 struct point 9 {10 int x, y;11 };12 13 bool vis[MAXN][MAXN];14 p 阅读全文
posted @ 2012-08-24 11:30 冰鸮 阅读(182) 评论(0) 推荐(0)