摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1247题意:给你一连串的单词,输出其中可以由所给出的两个单词(可以自己和自己组成)组成的单词。思路:建好字典树后,枚举单词的组成就好。#include<iostream>#include<cstring>using namespace std;typedef struct tree{ tree *next[26]; int flag;}tree;tree *root=(tree *)malloc(sizeof(tree));char s[50000][50];void creat(ch 阅读全文
posted @ 2012-12-11 12:39 紫忆 阅读(867) 评论(0) 推荐(0) 编辑
摘要: 很抱歉,这是错的--坑爹啊,我做一道字典树+dp的题目,用这模版,一直wa,我一只以为是dp转移错了,谁知道,竟然是字典树模版错了-- 阅读全文
posted @ 2012-12-07 11:51 紫忆 阅读(156) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<string.h>using namespace std;#define max 26typedef struct tree{ tree *next[26]; int v;}tree;tree tmp;tree *root=&tmp;void creat(char str[]){ int len=strlen(str);// printf("\n%d\n",len); tree *p=root,*q; for(int i=0;i<len;i++) { int x=str[i]- 阅读全文
posted @ 2012-12-07 11:50 紫忆 阅读(178) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3336这道题是水题,但是我超时了三次才过。而我队友是水过的,这个问题值得我反思。以前,对于ac过的题目,我一般是不会再回去看代码的,因为我觉得可以用更多时间来做下一道题目,而我队友不这样认为,他对他的代码和算法在时间复杂度上要求高。他会一题多做几遍,尽量缩减他代码的时间复杂度。以前一道题目,我们两的思路是一样的,但是我的代码超时了,而他过了,那次我并没有多重视,现在这样的情况再次出现了,我想我自己也必须重视自己代码的时间复杂度了,尽量精益求精,将代码中那些不必要花费的时间都精简一遍,这也是对自己代码和思维的严 阅读全文
posted @ 2012-12-04 23:41 紫忆 阅读(1006) 评论(2) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=4198#include<iostream>#include<queue>using namespace std;int n,m,d;int t[4][2]={0,1,0,-1,1,0,-1,0},vist[510][510];int mx,my;char s[510][510];struct ss{ friend bool operator<(const ss a,const ss b) { return a.sum>b.sum; } int x,y,sum;};prior 阅读全文
posted @ 2012-12-03 18:37 紫忆 阅读(287) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1896题意:Sempr在走路时,如果遇到为奇数的石头,就把它往前扔,遇到为偶数的石头则不处理,要是同一位置有多个石头,则先扔最重的石头(也就是扔的最近的那个石头),要你求扔的石头离初始位置的最大距离。#include<iostream>#include<queue>using namespace std;struct ss{ friend operator<(const ss a,const ss b) { if(a.p>b.p) return 1; ... 阅读全文
posted @ 2012-12-02 16:16 紫忆 阅读(419) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1509#include<iostream>#include<queue>using namespace std;struct ss{ friend operator<(const ss a,const ss b) { if(a.v>b.v) return 1; else if(a.v==b.v&&a.num>b.num) return 1; else return 0; } int num,v,sum; char s[50];};int main(){ 阅读全文
posted @ 2012-12-02 16:09 紫忆 阅读(293) 评论(0) 推荐(0) 编辑
摘要: 优先队列用法在优先队列中,优先级高的元素先出队列。标准库默认使用元素类型的<操作符来确定它们之间的优先级关系。优先队列的第一种用法,也是最常用的用法:priority_queue<int>qi;通过<操作符可知在整数中元素大的优先级高。故示例1中输出结果为:96532第二种方法:在示例1中,如果我们要把元素从小到大输出怎么办呢?这时我们可以传入一个比较函数,使用functional.h函数对象作为比较函数。priority_queue<int,vector<int>,greater<int>>qi2;其中第二个参数为容器类型。第二个参 阅读全文
posted @ 2012-12-01 23:27 紫忆 阅读(714) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<queue>using namespace std;struct ss{ friend bool operator<(const ss a,const ss b) { if(a.v<b.v) return 1; else if(a.v==b.v&&a.num>b.num) return 1; else return 0; } int num,v;};int main(){ int n; while(scanf("%d",&n)>0) { ss t; 阅读全文
posted @ 2012-12-01 23:25 紫忆 阅读(256) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=4027思路:这一题不能用成段更新,那样会超时的。仔细看题,会发现一个2的64次方被开8次就会变成1,也就是如果一段区间和等于它的右极限-左极限+1的话,就代表这段区间不用再被开方了......接下来就是区间求和的问题了..............#include<iostream>#include<math.h>using namespace std;struct node{ __int64 l,r,num;}str[900010];__int64 yy[500006],ans=0;v 阅读全文
posted @ 2012-11-29 18:15 紫忆 阅读(338) 评论(0) 推荐(0) 编辑