07 2015 档案

摘要:字典树是一个比较简单的数据结构。它利用字符串的公共前缀来节约存储空间。并且效率不错;简单的说,就是多个字符串。如果前缀相同,就把他的前缀放在一条路上,用一个变量记录出现的个数。题目基本就是求给一堆字符串,再给一个字符串,问有多少出现过;基本相同原理,可以适当修改trie结构体里的内容,来达到要求; 阅读全文
posted @ 2015-07-31 09:21 sweat123 阅读(120) 评论(0) 推荐(0)
摘要:要注意二点 。这组数据16shehehesayshrheryasherhs出现重复的,也要算。所以这里答案为4;这一组16shehehesayshrheryasherhe查询单词中he出现过,所以后面的he不能记录,所以答案为4;#include#include#includestruct trie... 阅读全文
posted @ 2015-07-30 22:32 sweat123 阅读(220) 评论(0) 推荐(0)
摘要:开始以为枚举会超时,因为有50000的词。后来试了一发就过了。哈哈。枚举没一个单词,将单词拆为2半,如果2半都出现过,那就是要求的。#include#include#includestruct trie{ trie *next[26]; int flag;};trie *root;voi... 阅读全文
posted @ 2015-07-30 15:38 sweat123 阅读(127) 评论(0) 推荐(0)
摘要:这题印象深刻,我刚接触acm时,以为这题是水题(因为是中文,又短),一直没做出。现再想想也是。可能也是我以前字符串掌握不好;这题其实也可以用stl里的map写。这里我用字典树写的。其实这题算简单题了吧。#include#include#includestruct trie{ trie *nex... 阅读全文
posted @ 2015-07-30 14:54 sweat123 阅读(267) 评论(0) 推荐(0)
摘要:比较简单,出现前缀。不过要释放空间。#include #include #include struct trie{ trie *next[10]; int sum;};trie *root;char str[10002][11];void init(){ root=(trie*)m... 阅读全文
posted @ 2015-07-30 13:40 sweat123 阅读(377) 评论(0) 推荐(0)
摘要:这题我开始想的简单了,WA一次,然后看disscuss里有人说输入时长度从小到大的,然后我信了。然后开始while(1) WA;然后我尝试先放如数组。后来对了;discuss里面果然不能太相信。根据出现的次数来判断是否为前缀。#include#include#includestruct trie{ ... 阅读全文
posted @ 2015-07-30 10:50 sweat123 阅读(347) 评论(0) 推荐(0)
摘要:#include#include#include#define maxn 26//26个字母 struct trie{ trie *next[maxn];//向下26个字母扩展 int v;//记录个数};trie *root;void init(){ root=(trie*)ma... 阅读全文
posted @ 2015-07-29 22:58 sweat123 阅读(111) 评论(0) 推荐(0)
摘要:这题让我第一次感受到了什么叫做在绝望中A题。这题我总共交了18次,TLE不知道几次,WA也不知道几次。这题不能用dijkstra,用这个我一直超时(我没试过dij+优先队列优化,好像优先队列优化后可以过).。用了我近一天的时间。。。。。。#include#include#includeusing n... 阅读全文
posted @ 2015-07-29 14:47 sweat123 阅读(398) 评论(0) 推荐(0)
摘要:开始的时候想的比较简单,直接枚举所有输入的边,但最后超时;后来就先进行一次dij,记录所有最短路上的边,然后枚举删去这些边;#include#include#define maxn 1002#define INF 99999999int map[maxn][maxn],vis[maxn],n,dis... 阅读全文
posted @ 2015-07-29 09:08 sweat123 阅读(324) 评论(0) 推荐(0)
摘要:网上有优化的方法 就是乘上一个一维的矩阵;现在还没有想通。想通了不上代码;我用的就是普通的矩阵,压着时间过;只是多了一个判断条件,不加这个条件就超时;#include#include#define INF 99999999#define maxn 85struct Mat{ int mat[m... 阅读全文
posted @ 2015-07-28 16:18 sweat123 阅读(220) 评论(0) 推荐(0)
摘要:建图还是有点烦人的。#include#include#include#include#include#define maxn 105#define INF 99999999using namespace std;int g[maxn][maxn],vis[maxn],dis[maxn],n;void... 阅读全文
posted @ 2015-07-28 14:24 sweat123 阅读(156) 评论(0) 推荐(0)
摘要:字符串问题。是否出现iPhone Apple等词;我考虑时想到既然是否有这些词,可以写map标记一下;然后又最长的是iPhone,6个单词,所以第一个for遍历所有单词然后在一个for(1~6),用string+c[];然后判断是否该单词被标记,如果被标记过,那就是需要的词,随后第一个for加上单词... 阅读全文
posted @ 2015-07-28 11:00 sweat123 阅读(262) 评论(0) 推荐(0)
摘要:比较简单的题 搜索4个方向,维护位子的值。#include#include#includeusing namespace std;int a[10],b[10];int vis[10][10][10][10][10][10];struct node{ int x1,x2,x3,x4,x5,x6... 阅读全文
posted @ 2015-07-28 10:52 sweat123 阅读(273) 评论(0) 推荐(0)
摘要:既然输入的是损坏率,那1-x就是剩余的。最后只要剩余的最大。#include#include#define Max 99999999const int maxn=1003;double dis[maxn],map[maxn][maxn];int vis[maxn],n,val[maxn];void ... 阅读全文
posted @ 2015-07-28 10:44 sweat123 阅读(164) 评论(0) 推荐(0)
摘要:2边SPFA 然后求和#include#include#include#define INF 1000000000#define ii __int64using namespace std;struct node{ ii v; ii val; ii next;}edge1[1000... 阅读全文
posted @ 2015-07-28 10:40 sweat123 阅读(294) 评论(0) 推荐(0)
摘要:floyd一遍即可。如果floyd后值有变大就是#include#include#include#include#include#define INF 99999999using namespace std;const int maxn=36;double mmap[maxn][maxn],val;... 阅读全文
posted @ 2015-07-28 10:37 sweat123 阅读(254) 评论(0) 推荐(0)
摘要:输入是2个不在一起的人,可以用一个数组来保存和他矛盾的人。这样find的时候就find(hash[]);就可以;#include#includeint pa[100020],h[100020],n;void init(){ for(int i=0;i<=n;i++) { p... 阅读全文
posted @ 2015-07-28 10:34 sweat123 阅读(197) 评论(0) 推荐(0)
摘要:比较恶心1: 0 0 空树是一棵树2: 1 1 0 0 不是树 3: 1 2 1 2 0 0 不是树...4: 1 2 2 3 4 5 不是树 森林不算是树5: 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 1 错6: 1 2 2 1 0 0 也是错误的#include#i... 阅读全文
posted @ 2015-07-28 10:31 sweat123 阅读(230) 评论(0) 推荐(0)
摘要:#include#include#includeusing namespace std;int main(){ int n,m,i,j; char name[10003][33],str[33]; string s1,s2; while(scanf("%d",&n)!=EOF... 阅读全文
posted @ 2015-07-28 10:22 sweat123 阅读(179) 评论(0) 推荐(0)
摘要:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1332#include#include#include#include#includeusing name... 阅读全文
posted @ 2015-07-28 10:20 sweat123 阅读(155) 评论(0) 推荐(0)
摘要:QueuesandPriority Queuesare data structures which are known to most computer scientists. TheTeam Queue, however, is not so well known, though it occur... 阅读全文
posted @ 2015-07-28 10:18 sweat123 阅读(126) 评论(0) 推荐(0)
摘要:题意:最小生成树的最大边最小,sort从小到大即可poj2485#include#include#includeusing namespace std;#define maxn 505int map[maxn][maxn],pa[150000],num,n;struct node{ int x... 阅读全文
posted @ 2015-07-28 09:44 sweat123 阅读(257) 评论(0) 推荐(0)
摘要:判断最小生成树是否唯一。kruskal时记录需要的边,然后枚举删除它们,每次删除时进行kruskal,如果值未变,表明不唯一。#include#include#include#includeusing namespace std;struct Node{ int l; int r; ... 阅读全文
posted @ 2015-07-28 09:28 sweat123 阅读(247) 评论(0) 推荐(0)
摘要:题目的意思是求构成生成树的边的最大边和最小边的差最小。枚举即可#include#include#includeusing namespace std;#define maxn 102struct node{ int x; int y; int val;}s[maxn*(maxn-1... 阅读全文
posted @ 2015-07-28 09:24 sweat123 阅读(122) 评论(0) 推荐(0)
摘要:#include#include#includeusing namespace std;#define maxn 210int map[maxn][maxn],color[maxn];int vis[maxn],match[maxn],n;int bfs(int u,int n){ int i... 阅读全文
posted @ 2015-07-25 14:11 sweat123 阅读(133) 评论(0) 推荐(0)
摘要://判断图G是否为二分图,可以用染色法。//从一点开始,把他邻接的点图为与其不同的颜色,那么只要bfs一圈一圈图。如果图的时候遇到颜色相同,//表明2个点相连,所以不是;#include#include#includeusing namespace std;#define maxn 210int m... 阅读全文
posted @ 2015-07-25 14:06 sweat123 阅读(361) 评论(0) 推荐(0)
摘要:求重要的点。那就可以通过枚举来找;先做一次最大匹配,求出匹配数。然后逐一枚举这些点。如果匹配数改变,那就是重要点;#include#includeint map[103][103],n,m,vis[103],match[103];int x[103],y[103];int dfs(int u){ ... 阅读全文
posted @ 2015-07-25 10:19 sweat123 阅读(147) 评论(0) 推荐(0)
摘要:添加lb[],rb[]数组,来标记竖边。添加num,来计算竖边的个数,因为计算周长的时候,未覆盖的竖边都要加。#include#include#includeusing namespace std;#define lson l,m,rt=L&&R>=r) { tree[rt].c... 阅读全文
posted @ 2015-07-24 20:31 sweat123 阅读(157) 评论(0) 推荐(0)
摘要:这题真的呵呵了。敲了很长时间,调了很多bug,把0 1 输出,解决了。最后想取反,怎么搞都有bug,最后还是看了大牛们的博客。不过这题真的敲得爽,调bug时基本把线段树过程全部弄了一遍。#include#include#define lson l,m,rty?x:y;}int min(int x,i... 阅读全文
posted @ 2015-07-24 13:44 sweat123 阅读(231) 评论(0) 推荐(0)
摘要:strcmp比较的是所有的长度,而strncmp可以比较前几个长度 strncmp(s1,s2,n);这样就比较了s1,s2,前n个长度的大小。 阅读全文
posted @ 2015-07-23 09:55 sweat123 阅读(260) 评论(0) 推荐(0)
摘要:百度上说 三角形三条中线构成的新的三角形的面积是原三角形面积的3/4;,用正三角形随便试一下。如果是3条高ss^2=1/((1.0/ha+1.0/hb+1.0/hc)*(1.0/ha+1.0/hb-1.0/hc)*(1.0/ha-1.0/hb+1.0/hc)*(1.0/hb+1.0/hc-1.0/h... 阅读全文
posted @ 2015-07-22 16:16 sweat123 阅读(656) 评论(0) 推荐(0)
摘要:#include#include#includeint prime[1000010];int vis[1000010];int flag;void init_prime() { int i, j; for(i = 2;i <= sqrt(1000010); ++i) ... 阅读全文
posted @ 2015-07-22 16:13 sweat123 阅读(149) 评论(0) 推荐(0)
摘要://看了很多的博客 后来队友指点才懂//sum=f(g(0))+f(g(1))+....//sum=A^(b-1)*|...|....//要将b-1换,防止出现b=0时有负一,用A^b代替,取下面的即可//这样问题成了 sum=A^b(A+A^(2k)+A^(3k)+...+A^(k(n-1)));... 阅读全文
posted @ 2015-07-22 08:47 sweat123 阅读(517) 评论(0) 推荐(0)
摘要:添加 lsum[ ] , rsum[ ] , msum[ ] 来记录从左到右的区间,从右到左的区间和最大的区间;#include#define lson l,m,rty?x:y;}void pushup(int l,int r,int rt){ int m=(l+r)/2; lsum[r... 阅读全文
posted @ 2015-07-18 17:10 sweat123 阅读(168) 评论(0) 推荐(0)
摘要:由于坐标可能很大,此时需要离散化,将值转化为对应的坐标。#include#includeusing namespace std;#define lson l,m,rt=L&&R>=r) { sum[rt]=1; if(!mark[c]) { ... 阅读全文
posted @ 2015-07-18 15:46 sweat123 阅读(193) 评论(0) 推荐(0)
摘要:给n个数字 U表示第A个数改为B。A是从0开始。Q输出最大的递增序列个数。考虑左边,右边,和最大的。#include#define lson l,m,rty?x:y;}int min(int x,int y){ return x=p) updata(p,c,lson); e... 阅读全文
posted @ 2015-07-18 15:02 sweat123 阅读(234) 评论(0) 推荐(0)
摘要:求矩阵的并,也就是要求所有的面积。那可以吧总的图形按照矩阵来切割。使其为一块一块。输入的时候用坐标表示,这里扫描线从下到上扫描。初始时让下面的边为1,上面的为-1;用一条先从下面开始想上扫描。遇到更新线段树,加入该条边,为-1时就除去改变。这样从下到上一遍扫描就可以得到线段的长度。从下到上的过程中,... 阅读全文
posted @ 2015-07-18 14:18 sweat123 阅读(234) 评论(0) 推荐(0)
摘要:/* 不是叶子节点 ,且cnt=1.注意这里,cnt=1确切的意义是什么, 应该是,可以确定,这个区间被完全覆盖了1次, 而有没有被完全覆盖两次或以上则不知道无法确定,那么怎么怎么办了, 只要加上t[lch].s + t[rch].s 即,看看左右孩子区间被覆盖了一次或以上... 阅读全文
posted @ 2015-07-18 14:07 sweat123 阅读(171) 评论(0) 推荐(0)
摘要:简单线段树hdu1166 1 #include 2 #define lson l,m,rt m)43 ret += Query(L,R,rson);44 else if(m >= R)45 ret += Query(L,R,lson);46 else4... 阅读全文
posted @ 2015-07-13 13:53 sweat123 阅读(168) 评论(0) 推荐(0)