摘要: 题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=1298/*字典树Date: 2012/11/1先用字典树存放单词,然后通过数字字符串枚举选择权值最大的那个单词即可注意枚举的时候要剪枝,不过也是很简单的剪枝*/#include<iostream>using namespace std;#define maxn 101struct Trie{ int n; Trie *next[26]; Trie() { n = 0; memset(next,0,sizeof(next)); }};int... 阅读全文
posted @ 2012-11-01 22:39 sorryhao 阅读(273) 评论(0) 推荐(0)
摘要: 题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=1800思路:仔细分析容易发现,其实就是求给定的字符串中出现最多的字符串个数,当用字符串实现时,注意前导0需去掉。方法一:map 这里为什么用map<int,int>可以,我想可能是因为虽然有的数超出范围但是读入的时候还是会读出一个数的(虽然这个数不是原来的那个数),而每个数都唯一,让然用map<string,int>似乎更合乎情理#include<stdio.h> #include<iostream>#include<map> usin 阅读全文
posted @ 2012-10-31 21:27 sorryhao 阅读(256) 评论(0) 推荐(0)
摘要: 题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=1671动态分配内存,当实例较多时需释放内存,不然会超空间#include<iostream>#include<string>#include<cstdio>using namespace std;#define maxn 10001char s[maxn][11];struct Trie{ Trie *next[10]; Trie() { memset(next,0,sizeof(next)); }};void Insert(Trie *root,char . 阅读全文
posted @ 2012-10-28 15:02 sorryhao 阅读(167) 评论(0) 推荐(0)
摘要: 方法一:字典树515ms#include<iostream>#include<string>using namespace std;struct Trie{ string s; //在每个单词的末尾节点上保存该单词的英语意思 Trie *next[26]; Trie() { s = ""; memset(next,0,sizeof(next)); }};void Insert(Trie *root,string s1,string s2){ Trie *p = root; for(int i = 0; i < s2.si... 阅读全文
posted @ 2012-10-28 13:09 sorryhao 阅读(230) 评论(0) 推荐(0)
摘要: /*Date: 2012/10/27题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=1247思路:把字典中的每个字符串拆成0->j 和 j->n 两个子串,再分别查找这两个子串 在不在字典中,若在则满足题意*/方法1:字典树#include<iostream>#include<string>using namespace std;#define maxn 50001string s[maxn];struct Trie{ int n; Trie *next[26]; Trie() { n = 0; ... 阅读全文
posted @ 2012-10-27 23:41 sorryhao 阅读(270) 评论(0) 推荐(0)
摘要: 题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=4432Sum of divisorsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 137 Accepted Submission(s): 54 Problem Descriptionmmm is learning division, she's so proud of herself that she can figure out 阅读全文
posted @ 2012-10-26 16:39 sorryhao 阅读(330) 评论(0) 推荐(0)
摘要: 题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=44382012天津赛区现场赛H题/*简单数学题只要稍微懂点概率论的知识就能做出来当Alice首选tiger时,期望为:mp1 = q*(p*x + p*y) + (1-q)*x;当Alice首选wolf是,期望为:mp2 = q*y + (1-q)*(p*x + p*y);*/#include<iostream>using namespace std;int t;double x,y,p,q;int main(){ //freopen("4438.txt",&qu 阅读全文
posted @ 2012-10-26 14:46 sorryhao 阅读(260) 评论(0) 推荐(0)
摘要: 题目描述:把只包含因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含因子7。 习惯上我们把1当做是第一个丑数。求按从小到大的顺序的第N个丑数。输入:输入包括一个整数N(1<=N<=1500)。输出:可能有多组测试数据,对于每组数据, 输出第N个丑数。样例输入:3样例输出:3 题目链接地址:http://ac.jobdu.com/problem.php?cid=1039&pid=17思路:就是用已经找到的丑数乘以2,3,5继续迭代下面的,和HDU 1085(Humble numbers) 差不多#include<iostre 阅读全文
posted @ 2012-10-18 20:20 sorryhao 阅读(235) 评论(0) 推荐(0)
摘要: 题目链接地址:http://ac.jobdu.com/contest.php?cid=1039用stl中的next_permutation()函数,它的作用是如果对于一个序列,存在按照字典排序后这个排列的下一个排列,那么就返回true且产生这个排列,否则返回false。调用之前先把一个序列排序使之为有序序列代码1:#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){ //freopen("12.txt","r&quo 阅读全文
posted @ 2012-10-16 17:18 sorryhao 阅读(523) 评论(0) 推荐(0)
摘要: /*简单DFS题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=2616*/#include<iostream>using namespace std;#define maxn 11#define INF 0x3f3f3f3fint arr[maxn],w[maxn],n,m,count;bool flag,visited[maxn];void dfs(int i,int rest,int num){ if(flag && num >= count) return; if(num > n) return; 阅读全文
posted @ 2012-10-14 22:56 sorryhao 阅读(193) 评论(0) 推荐(0)