上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 30 下一页
  2012年10月20日
摘要: 大意:判断一个字符串是否由给定的一些字符中两个组成。思路:可以用hash,也可以用字典树+枚举,字典树似乎比较快。CODE:#include<iostream>#include<cstring>#include<cstdio>#include<cstdlib>usingnamespacestd;#defineMAXN120010charsave[120010][30];structTrie{Trie*next[26];intvalue;Trie(){for(inti=0;i<26;i++)next[i]=0;value=0;}};voidi 阅读全文
posted @ 2012-10-20 16:28 有间博客 阅读(210) 评论(0) 推荐(0) 编辑
摘要: /*哈希函数的构造方法其实和建立邻接表的方法非常类似*/#include<stdio.h>#include<string.h>#include<stdlib.h>charst[121000][30],temp[30];intfirst[10000019],next[121000];voidinit(){memset(first,-1,sizeof(first));}inthash(char*key)//ELHhash{ULh=0;while(*key){h=(h<<4)+*key++;ULg=h&0xf0000000L;if(g)h^=g 阅读全文
posted @ 2012-10-20 11:57 有间博客 阅读(371) 评论(0) 推荐(0) 编辑
摘要: 我只会用二分枚举,即sum(1,mid-1) == sum(mid+1, n) -->2*pow(mid, 2) == n*(n+1); 然后去网上看了看其他人是用打表的方式过去的,今天第一次接触了暴力打表。共同进步啊。由于我不知道最大数是多少,于是我将n的范围开到了一亿,反正也只要前十组,如果少了就增加n的范围。打表CODE:#include<stdio.h>#include<string.h>intmain(){freopen("UVA138.cpp","w",stdout);longlonginti,j,x,mid,y 阅读全文
posted @ 2012-10-20 11:36 有间博客 阅读(243) 评论(0) 推荐(0) 编辑
  2012年10月19日
摘要: 题意:求几个最小公倍数为n的数的最小和1、每个素因子组成的最大数加,如:12=(2*2)+ 32、区分单个素因子16=(2*2*2*2)+13、素因子只有1和本身的7=1+7=8,即本身是素数。CODE:#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#include<ctype.h>usingnamespacestd;longlongn;longlongs 阅读全文
posted @ 2012-10-19 22:37 有间博客 阅读(262) 评论(0) 推荐(0) 编辑
摘要: 大意:判断一个256进制数增加2个字节(16位)是否可以被32493整除。说实话,真难看懂题意。CODE:#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#include<ctype.h>usingnamespacestd;#defineMAXN1050charstr[MAXN];intmain(){charsave[8];longlongres=0,ans 阅读全文
posted @ 2012-10-19 20:20 有间博客 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 大意:判断是否是一个特定的数字。思路:按照题目的要求写就行,枚举+判断是否是素数。CODE:#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>usingnamespacestd;#defineMAXN65100intvis[MAXN]={0};intprime[MAXN]={0};intn,tot;voidinit(){tot=0;intSIZE=(int)sqrt(MA 阅读全文
posted @ 2012-10-19 15:03 有间博客 阅读(213) 评论(0) 推荐(0) 编辑
摘要: 大意:给你一些加油站A的坐标,一些需要基地B的坐标,问你这两者之间的最小值。思路:用一个标记来表示分别在A和B中,数组长度变大了两倍,然后就是最近点对模板题啦。另外:输出是%.3f,我用%.3lf就WA。CODE:#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>usingnamespacestd;#defineMAXN100010constintINF=1e50;str 阅读全文
posted @ 2012-10-19 11:25 有间博客 阅读(762) 评论(0) 推荐(0) 编辑
摘要: 大意:广场上固定着一些玩具,让你设计一个圆环使得最多只有一个玩具落入环中。(使得圆环具有最大半径)思路:去寻找最近的一个对点,它们之间的距离/2就是圆环的最大半径。最近点对模板题.CODE:#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>usingnamespacestd;#defineMAXN100010structnode{doublex,y;}p[MAXN*2], 阅读全文
posted @ 2012-10-19 11:18 有间博客 阅读(186) 评论(0) 推荐(0) 编辑
  2012年10月18日
摘要: 最近点对模板题,算法导论P591有具体的证明,我不会实现 - -!,有一个博主写的很好,具体的证明可以见博客:http://blog.csdn.net/zhang20072844/article/details/6776386#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>usingnamespacestd;#defineMAXN100010structnode{dou 阅读全文
posted @ 2012-10-18 22:06 有间博客 阅读(255) 评论(0) 推荐(0) 编辑
摘要: 大意:一台机器可以使用2种命令,即复制最后一个单词,将最后一个单词的最后一个字母删去,问你使用最少打印的字母打印所有的字符串。思路:每次枚举出于前一个字符串具有最长长度的公共前缀,贪心性质可以被证明,直到所有的字符串都被包括。CODE:#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>usingnamespacestd;#defineMAXN1001charstr[MAXN][MAXN];intsave[MAXN],n; 阅读全文
posted @ 2012-10-18 19:35 有间博客 阅读(213) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 30 下一页