- 博客(60)
- 收藏
- 关注
转载 常用stl 容器用法
1、stack push pop top empty sizestack 模板类的定义在头文件中。stack 模板类需要两个模板参数,一个是元素类型,一个容器类型,但只有元素类型是必要的,在不指定容器类型时,默认的容器类型为deque。定义stack 对象的示例代码如下:stack s1;stack s2;stack 的基本操作有:入栈,如例:s.push(x
2013-08-28 12:52:07
1261
原创 Poj 2774两个字符串的最长公共子串长度
给A ,B 两个串 要求两个字符串的最长公共子串长度只需要用'$',分割一下就好了,不能用0A$B#include#include#include#include#define MIN(a,b) (a)>(b)?(b):(a)#define MAX(a,b) (a)>(b)?(a):(b)#define INF 0x3f3f3fusing name
2013-08-26 18:36:53
765
原创 poj 1743求最长不重叠公共子串
后缀数组欧液!大意就是给出一串数字 (1-88)要寻找重复的最长不重叠子串儿 串长至少5but 由题意 12345 和 23456 可以算是重复的子串 因为相当于每个数加上了相同的数就是保持 差的顺序 不变啦就转化成求 差的序列中 最长至少为4的不重复子串儿于是 字符串里放的是差值 但是由于前后差可能为负数 而每个字符串会作为基数排序中的下标 故
2013-08-26 15:21:01
983
原创 用数组模拟双向链表
需要一个pre[ ] 和一个 next[ ] 一开始指向 -1表示没有前值 没有后值大小确定 然后用一个val[ ]数组来存相当与一个节点里面的值一个tot值 插入 新的 节点就+1 在中间插入新节点只要修改pre和next的值 hdu 多校2013 第十场 的 editor运用了这一结构 并且
2013-08-24 20:31:57
1336
转载 map set multimap multiset 对键值快速查找 插入 删除 O(logN)
#include #include #include #include using namespace std;/*map是一个键值对映射,不能出现相同的值,multimap里面可以有相同的值。 //插入multiset multimap set 只能用 insert 查找 find(key) 返回迭代器 upper_bound(key)大于等于k
2013-08-15 09:35:24
1484
原创 map容器
2013 ACM-ICPC杭州赛区全国邀请赛看了某人题解 shaolin 那题可以用 map (key,value)map 会根据 key 值 自动排序 因为和尚的id和战斗值都是唯一的所以可以把key值设为 战斗值 那么 每次查找 相近的 就 快多了要注意 如果 iterator指向 开头 map的 开头 x.begin()只能往后比
2013-08-11 17:47:27
554
原创 数位dp hdu3555
数位dp可以理解为按位 判断吧这题好经典呐就 包含49 和 以9开头 以及 不包含49的情况 (因为从位数为0开始递推 所以要有以9开头这一项)dp[i][0]=dp[i-1][0]*10-dp[i-1][1]; dp[i][1]=dp[i-1][0];dp[i][2]=dp[i-1][2]*10+dp[i-1][1];i为长度 j: 0 代表
2013-08-08 09:36:01
591
原创 DP hdu 4649 Professor Tian
赤裸裸dp ;_(主要还是题意理解太慢了 。。最后不过是要求这个答案的期望嘛!而答案就是由一个21位二进制数组成 只要求出每一位为1的概率 再 乘上每一位的权值 相加 就是所求最终期望!!(好妙!)对比一下最笨的想法:每对运算符和数 消不消失对 整体式子的答案期望 的影响 ,所以要算出每一种可能有 2^200种 是对整个答案做加法 而对每一位求期望值并相加只需要 21*200
2013-08-07 13:22:28
884
原创 树型dp poj1192
简单树型dp。题目好罗嗦。。一棵树找最大权值和子树。算出最大权值dfs 一下 搞掂!!麦当劳最爱板烧哈哈哈 ~#include #include #include #include //abs() 自己写宏好容易写错 要加好多好多括号- -外面一个大括号没加 wa到死#define Max(a,b) (a)>(b)?(a):(b)using na
2013-08-05 16:49:13
666
原创 树型dp Zoj3201 tree of tree
^_^ o(∩∩)o...我去刚要打个哈哈出现这么多颜文字还那么丑这题 算是 树型dp经典的 小变种 了吧 。。首先 理解一下 啥叫 树型dp,树型树型,告诉我们 这是一个 基于树(二叉树)结构的dp那么自然要有建树的过程。建树 有 三种 1)单方向 2)邻接表 3)孩子兄弟再想到dp是自下ershang故而先计算孩子节点信息利用孩子节点信息
2013-08-04 12:54:34
746
原创 区间dp经典 poj2955
从左到右 凡是 先遇到 '(' 后遇到‘)’ 或者 先遇到 '[‘ 后遇到 ’]'的算一个匹配 长度为2假设一个串 长度为 len0.....................(len-1)求 其中 任意 i 到 j 下标 的 子串 它 的 最长 匹配括号长度 设为 f(i,j)则 f(i,j)=max( f[i,k]+f[k+1][j](枚举) , f[i+1][
2013-08-03 12:55:53
599
原创 poj3667
这题对于每个节点有 3个 附加信息 :1.以左端点为首的最长连续空闲2.以右端点为首的(向左数)最长空闲3.该区间内总最长空闲关键在 查找最靠左的线段上 如果 第一个节点也就是最长区间的 max然后 先考虑左边 再考虑左边接右边 最后考虑右边#include #include #define Max(a,b) (a)>(b)?(a):(b)#defi
2013-08-02 20:10:25
696
原创 vim 编译运行
[Cr+z]进入shell shell中$ fg 返回 原编辑处 好方便喔 !!这样编译啦 运行啦 就可以切来切去的了 good也可一在 vim下面 执行各种 命令行 :!g++ file :!./a.out :!+各种命令 很强大 怎么跨终端复制呢??? 先 mark关于 vim的一个超好用各种代码 补全片段小插件
2013-08-02 13:40:48
1275
原创 hdu 多校contest4 group(树状数组)
树状数组 线段树 again- -又不会处理 again- -看了网上其他人的思路:就是 要找出最少的分组 分组以数值连续为标准 还是以 右端点 为关键点sum(i)为从 1~i(输入数下标)的最少分组个数从左向右 不断的更新 r(i)从第一个数开始扫描 当前数a[i]所对应的 i 向上update(i,1)加1 如果 在
2013-08-02 13:19:00
683
原创 树状数组no pain no game(hdu 2013多校contest3)
这道题 数据量 和 询问都达到 50000 要求 [l ,r]区间内的 最大gcd(a,b) 不能简单暴力 两两求 gcd(a,b)容易得 在 一个连续区间内 以 最右 的端点 为标志 (也可以最左的端点为标志,过程对称相反),从下标大的 向 下标小的 (从后向前)扫描 ,对 每个a[i]找出 它的所有约数,若出现两次(用一个数组 b[])来记录(若b[k]!=0 则出现两
2013-08-01 10:40:53
806
原创 一维树状数组小心得
最近在看树状数组,简单一维的。颇有心得。求owbit(x)过程就不罗嗦了就是 return x&(-x) 按位取反加一 可以先打表保存方便查询 (类比去掉二进制表示的 最右边的1位置也就是末尾0个数是该c[i]的高度 单数高度都为0)add(int i,int val)操作 1 向上 i+=lowbit(i) (i2 向下 i-lowbit(i)(i>0)这
2013-07-28 21:20:58
757
原创 hdu 2013多校2warmup2
#include #include #include #include #include #include using namespace std;int N,M;int result[101]; //记录V2中的点匹配的点的编号bool state [1010]; //记录V2中的每个点是否被搜索过int p1[1010][2],p2[1010][2];vector g[1
2013-07-28 17:52:35
625
原创 字典数 入门理解
又扒了一段代码 很简单 注释自己看 #include #include #include using namespace std;const int MAX = 26; //26个字母 若构成字典树是二进制数 MAX=2;struct Trie //内部所需可自己定义{ Trie *next[MAX]; bool isword; Trie (
2013-07-24 13:50:24
763
原创 线段树入门 理解
扒了一线段树代码 注释作分析#include #include #include #include using namespace std;int n,m;int a[100001]; // 叶子结点数N__int64 ans;struct{ int l,r; __int64 sum,add; //__int64 }tree[40
2013-07-24 13:36:48
618
转载 大数阶乘(n!)末尾0的个数
所谓零,就是5*2,所以 “n!末尾有多少个零”==“min(n!的质算因子中5的数目,n!的质因子中2的数目”又因为n!的质因子中5的数目必然小于等于2的数目,所以题目就变成了求n!的质因子中5的数目。比如 26! 是 1*2*3*4*5*6……24*25*26,它们中间有多少个数能被5整除?当然是26/5=5个,但看25,它本身是5*5,也就是25代表着2个5,所以26!尾
2013-07-19 11:49:21
981
转载 次方求模&同余定理
1 //a^b mod c=(a mod c)^b mod c很容易设计出一个基于二分的递归算法。 2 #include 3 #include 4 //快速幂算法,数论二分 5 long long powermod(int a,int b, int c) //不用longlong就报错,题目中那个取值范围不就在2的31次方内 6 { 7 long long t; 8
2013-03-30 15:43:14
2866
转载 Catalan数的解法
Catalan数的解法Catalan数的组合公式为 Cn=C(2n,n) / (n+1);此数的递归公式为 h(n ) = h(n-1)*(4*n-2) / (n+1) 小数解对于50以下的小数解来说,使用数组就可以完成,代码如下:#includeusing namespace std;int main(){ long long int a[101]
2013-03-30 14:48:41
698
原创 [递推]hdu1465错排公式
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1465 f[n]=(f[n-1]+f[n-2])*(n-1)有N个信封的时候,可以考虑第N个信封本来是对的。则对于这个信封只有两种选择,一种是找一个错的交换,一种是找另一个对的交换。找一个错的信封交换即从n-1种排错的信封中任取一封交换即f[n-1]*(n-1);另一种找n-1中唯一排对的信封与之
2013-03-29 10:40:10
826
转载 catalan数
原理令h(0)=1,h(1)=1,catalan数满足递推式:h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)h(0) (n>=2)例如:h(2)=h(0)*h(1)+h(1)*h(0)=1*1+1*1=2h(3)=h(0)*h(2)+h(1)*h(1)+h(2)*h(0)=1*2+1*1+2*1=5另类递推式:
2013-03-28 21:20:31
720
转载 匈牙利算法
问题简介设G=(V,E)是一个无向图。如顶点集V可分割为两个互不相交的子集V1,V2之并,并且图中每条边依附的两个顶点都分属于这两个不同的子集。则称图G为二分图。二分图也可记为G=(V1,V2,E)。给定一个二分图G,在G的一个子图M中,M的边集{E}中的任意两条边都不依附于同一个顶点,则称M是一个匹配。选择这样的子集中边数最大的子集称为图的最大匹配问题(maximal m
2013-03-09 15:34:26
1099
原创 Subset Sums
Subset SumsJRMFor many sets of consecutive integers from 1 through N (1 For example, if N=3, one can partition the set {1, 2, 3} in one way so that the sums of both subsets are identical:{3}
2013-03-06 17:52:16
672
原创 Preface Numbering
Preface NumberingA certain book's prefaces are numbered in upper case Roman numerals. Traditional Roman numeral values use a single letter to represent a certain subset of decimal numbers. Here is
2013-03-05 19:30:57
808
原创 Hamming Codes
Hamming CodesRob KolstadGiven N, B, and D: Find a set of N codewords (1 <= N <= 64), each of length B bits (1 <= B <= 8), such that each of the codewords is at least Hamming distance of D (1 <= D
2013-03-01 20:34:44
437
原创 Healthy Holsteins
Healthy HolsteinsBurch & KolstadFarmer John prides himself on having the healthiest dairy cows in the world. He knows the vitamin content for one scoop of each feed type and the minimum daily vita
2013-02-08 16:16:03
666
原创 Sorting a Three-Valued Sequence
Sorting a Three-Valued Sequence IOI'96 - Day 2Sorting is one of the most frequently performed computational tasks. Consider the special sorting problem in which the records to be sorted have at mo
2013-02-06 17:30:32
464
原创 Ordered Fractions
Ordered FractionsConsider the set of all reduced fractions between 0 and 1 inclusive with denominators less than or equal to N.Here is the set when N = 5:0/1 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4/
2013-02-05 17:24:39
500
转载 位移进制运算
位移进制运算带符号右移 题:-15 >> 2 = -415原码: 00000000 00000000 00000000 00001111 //32位,二进制反码: 11111111 11111111 11111111 11110000 //0变1,1变0补码: 11111111 11111111 11111111 11110001 //最后位加1,-15二进
2013-02-04 19:24:18
1133
原创 The Castle
The CastleIOI'94 - Day 1In a stroke of luck almost beyond imagination, Farmer John was sent a ticket to the Irish Sweepstakes (really a lottery) for his birthday. This ticket turned out to have on
2013-02-04 19:22:46
550
原创 Checker Challenge
Checker ChallengeExamine the 6x6 checkerboard below and note that the six checkers are arranged on the board so that one and only one is placed in each row and each column, and there is never more t
2013-02-02 19:27:51
536
转载 C++ 二进制位运算判断奇数偶数
//C++ 二进制位运算判断奇数偶数,二进制取位操作,取二进制末位#includeusing namespace std;void main(){ int i; for(i=0;i<100;++i) { if(1==(1&i)) cout是奇数"<<endl; else cout是偶数"<<endl; }}/*--例如一个数 N,(N&1)的结果就是
2013-01-27 19:46:29
2563
原创 Superprime Rib
Superprime RibButchering Farmer John's cows always yields the best prime rib. You can tell prime ribs by looking at the digits lovingly stamped across them, one by one, by FJ and the USDA. Farme
2013-01-27 19:43:36
535
转载 关于素数的算法
关于素数的算法是信息学竞赛和程序设计竞赛中常考的数论知识,在这里我跟大家讲一下寻找一定范围内素数的几个算法。看了以后相信对大家一定有帮助。 正如大家都知道的那样,一个数 n 如果是合数,那么它的所有的因子不超过sqrt(n)--n的开方,那么我们可以用这个性质用最直观的方法来求出小于等于n的所有的素数。 num = 0; for(i=2; i {
2013-01-25 20:28:38
459
原创 Prime Palindromes
Prime PalindromesThe number 151 is a prime palindrome because it is both a prime number and a palindrome (it is the same number when read forward as backward). Write a program that finds all prime
2013-01-25 20:24:49
430
原创 Number Triangles
Number TrianglesConsider the number triangle shown below. Write a program that calculates the highest sum of numbers that can be passed on a route that starts at the top and ends somewhere on the
2013-01-24 22:17:48
586
原创 Mother's Milk
Mother's MilkFarmer John has three milking buckets of capacity A, B, and C liters. Each of the numbers A, B, and C is an integer from 1 through 20, inclusive. Initially, buckets A and B are empty wh
2013-01-23 17:36:51
478
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人