摘要: 题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=29355与Trie树相关的计数问题。因为正反各插了一次,所以字典中一共有2N个单词。val[i]存储了在该位置有相同字母的单词的个数,对于在该位置的每个字母,2N-val[i]代表与其不同的单词个数,所以对于每个单词的每个位置的字母,不同的需要删,相同的不需要删。对于在该位置的所有单词,一共删的次数即为val[i]*( 2*N - val[i] )。把每个位置都跑一边,最后的式子即为:ans += val[i]*( 2*N - val[i] )这个方法也是从别人的代码里学来的,我能力有限 阅读全文
posted @ 2013-05-03 23:29 冰鸮 阅读(299) 评论(0) 推荐(0)
摘要: 题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=29065Descripion《火影忍者》中,在忍者们使用忍术的时候,需要一定的查克拉(可以看成是一种体力值)。在战斗前,大家都希望提高自己的查克拉。鸣人发明了一种忍术,可以在短时间内提高查克拉。在使用忍术前,鸣人需要做一个仪式,这个仪式决定之后每个时刻的一个查克拉值。这些值的使用规则是:如果在某个时刻发动这个忍术,鸣人需要先消耗该时刻的查克拉值;在某个时候结束这个忍术,鸣人能获得该时刻的查克拉值(忍术必须先发动才能结束)。当然,如果某时刻鸣人具有的查克拉值少于该时刻的查克拉值,那么鸣人是 阅读全文
posted @ 2013-05-03 21:16 冰鸮 阅读(275) 评论(0) 推荐(0)
摘要: dp[m][i][j]代表第m组以字母(i +'a') 开头和以字母 ( j + 'a' )结尾的最小块数。kuai[m]中存储了第 m 组最少可以分为多少块,显然最少为所有相同字母放在一起时的块数,即这一组中不同字母的个数。如果前一组的结尾与后一组的开头相同,则dp[m][i][j] = min( dp[m-1][st][ed] + kuai[m] - 1 );若不同,则dp[m][i][j] = min(dp[m - 1][st][ed] + kuai[m] ); 1 #include <cstdio> 2 #include <cstrin 阅读全文
posted @ 2013-05-03 16:03 冰鸮 阅读(310) 评论(0) 推荐(0)
摘要: 题意:给你一个能绕圆心转动的半径固定的半圆和N个点,问这个半圆最多能覆盖多少个点,半圆边界上的点也算在覆盖范围内。首先把半圆半径之外的点全部排除,枚举剩余所有点与圆心的连线。判断在同一侧的点有多少个。之前忽略的边界情况,WA一次。View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 6 const int MAXN = 200; 7 const double EPS = 1e-9; 8 9 struct point1 阅读全文
posted @ 2013-05-01 11:13 冰鸮 阅读(256) 评论(0) 推荐(0)
摘要: DescriptionYou are playing the game ‘Whack the Groundhog’ with your little nephew. Considering your terrible performance, you decide to get some help to establish your glory image in front of him. The first is to collect some necessary data. After a few times of practicing, you get to know exactly w 阅读全文
posted @ 2013-04-30 19:28 冰鸮 阅读(269) 评论(0) 推荐(0)
摘要: DescriptionYou are given a number matrixAwithNrows andMcolumns. Elements in the matrix are referred asAi,jwhere 0≤i<Nand 0 ≤j<M. The matrix has the following two properties:lFor each row, the numbers increase from left to right, that isAi,j-1≤Ai,jfor all 0 ≤i<Nand 1 ≤j<MlFor each column, 阅读全文
posted @ 2013-04-30 09:47 冰鸮 阅读(244) 评论(0) 推荐(0)
摘要: 题目链接:http://poj.org/problem?id=3460题意:有一些高度不等的书,可以一次取出一摞相对顺序不变的书插入任意位置,问最少多少次操作才能使书的高度递增有序。IDA*,刘汝佳黑书P169的例题,经典题目,启发函数的设计十分巧妙。以“h(s)=后继书本高度正确的书本个数”为估价函数,假设每次把一摞书本S从P1后面移动到P2后面,只有P1,S1的最后一本,P2三本书的后继有变化,h每次最多减少3,令h'=h(s)/3作为估价函数值,则每次h最多减少1。 1 #include <cstdio> 2 #include <cstring> 3 #i 阅读全文
posted @ 2013-04-25 23:01 冰鸮 阅读(441) 评论(0) 推荐(0)
摘要: 题目链接:http://poj.org/problem?id=3322源自Bloxorz游戏:点此试玩挺有意思的一题,搜索本身不难,主要在表示状态上想了很长时间。木块的状态可以压缩为三种:直立,横放,竖放。每种状态记录最上边或者最右边的坐标即可。初始状态不一定是竖直放的,我玩了几关游戏,初始状态都是竖直放的,我就默认为初始状态竖直了于是WA了几次……也可能有这种情况:7 5######...##O..##...##.XX##...######还有最好把全部的图都读入进来之后再判断起始坐标,读一个点判一次容易出错。单向广搜:11520958gbr3322Accepted10280K579MSG+ 阅读全文
posted @ 2013-04-25 12:17 冰鸮 阅读(209) 评论(0) 推荐(0)
摘要: 二分 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <algorithm> 5 6 #define LL long long int 7 8 using namespace std; 9 10 const int MAXN = 100010;11 12 LL a[MAXN];13 LL M, K;14 int N;15 16 bool check( LL mid )17 {18 LL TotUse = mid * M;19 LL use = 0;2 阅读全文
posted @ 2013-04-24 21:24 冰鸮 阅读(149) 评论(0) 推荐(0)
摘要: 题目链接:http://poj.org/problem?id=2374DP+线段树View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <algorithm> 5 6 #define lson l, m, rt << 1 7 #define rson m + 1, r, rt << 1 | 1 8 9 using namespace std; 10 11 const int MAXN = 100000; 12 c 阅读全文
posted @ 2013-04-24 15:30 冰鸮 阅读(291) 评论(0) 推荐(0)