上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 18 下一页
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2899 简单二分,但这个不满足单调性。 题目要求极值点,以函数导数的正负作为条件二分即可。code:#include<cstdio>#include<cmath>doubley=0;doublecal(doublex){return42*pow(x,6.0)+48*pow(x,5.0)+21*pow(x,2.0)+10*x-y;}doublesolve(doublex){return6*pow(x,7.0)+8*pow(x,6.0)+7*pow(x,3.0)+5*pow(x,2.0)- 阅读全文
posted @ 2012-02-14 23:21 追逐. 阅读(179) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2199 简单二分查找,应该属于水题了吧...纠结的是样例没过,一试竟然AC。 这两天状态太差了,发生这么多事,有点不知所措的感觉。现在都过去了,感觉还是挺烦燥...只能从头加深下搜索了。code:#include<iostream>#include<cstdio>#include<cmath>#include<iomanip>usingnamespacestd;doubley;doublel,r,m;doubleslove(doublex){return8*po 阅读全文
posted @ 2012-02-14 22:42 追逐. 阅读(178) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3507 斜率优化的DP,完全是看资料做出来的。下面给出资料中对两个结论的证明: 对基本公式f[i]=min{f[j]+(s[i]-s[j])^2+M},取i的两个一般决策点j,k(j<k),s[i]为1..i的cost总和,因为cost非负,所以s随i不减。 若k优于j,则f[k]+(s[i]-s[k])^2+M<f[j]+(s[i]-s[j])^2+M,化简得f[k]-f[j]+s[k]^2-s[j]^2<2*s[i]*(s[k]-s[j])。 由于j<k,则s[k]>s[j] 阅读全文
posted @ 2012-02-10 04:39 追逐. 阅读(907) 评论(0) 推荐(0) 编辑
摘要: http://acm.fzu.edu.cn/problem.php?pid=1894 简单单调队列。code:#include<cstdio>intdata[1000001];intqueue[1000001];intnum[1000001];inth,r,n;voidinsert(){if(r==h-1||data[n]<queue[r]){r++;queue[r]=data[n];num[r]=n;}else{while(r>=h&&data[n]>=queue[r])r--;queue[++r]=data[n];num[r]=n;}}void 阅读全文
posted @ 2012-02-09 23:25 追逐. 阅读(230) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2823 纯粹的单调队列练习题,用了一下输入的加速,结果发现还不如scanf快... 话说前段时间搞单调优化的时候,就是有点卡在单调队列上了,当时真没整明白资料里说的到底在维护什么...今天费老传了DP资料(完整版...)才算真搞懂。唉,浪费了那么多激情... 为DP的单调优化做准备吧,明天开始搞DP了,不能再缩了...code:#include<cstdio>intdata[1000005];intqueue[1000005];intn,k;voidgetMin(){inth,r;h= r = 0 ;queue[0]=0;for 阅读全文
posted @ 2012-02-08 00:52 追逐. 阅读(266) 评论(1) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2503 思路很简单,对foreign language word建trie树,插入时一并传入word的序号,与english word相对应。查找时直接查找word标记的序号,从存储数组中输出englishword就好了。 比较蛋疼的是这题的输入,一开始真心搞不定啊。。搞定后直接1Y。code:#include<cstdio>#include<cstring>charstr[100001][11];//模式串charestr[100001][11];#defineMAX26//字符集大小typedefstructTr 阅读全文
posted @ 2012-02-07 21:54 追逐. 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 拿到这题,大致的画了画图,发现只要标记好每个节点出现的次数就好了。 插入时,若字符存在,n++,若不存在建立新节点,他本身也为自己的前缀。 查找时,若next[k]->nCount!=1,说明其子节点有多个,无法确定唯一,则输出该字符,若nCount=1,则可以结束查找了。code:#include<cstdio>#include<cstring>charstr[1001][21];#defineMAX30//字符集大小typedefstructTrieNode{intnCount;//记录该字符出现次数structTrieNode*next[MAX];}Trie 阅读全文
posted @ 2012-02-07 19:54 追逐. 阅读(135) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3450 沾3080的光,这题让我WA了N多次!看到两个题一样,买一送二啊,上手就做,悲剧了。。 主要是没考虑一个字符时的情况,改来改去,最后终于想起来把KMP中的m初始化成-1就OK了。我这脑子是锈掉了么?忙活3个小时最后改了一个数就行了,纠结啊!code:#include<cstdio>#include<cstring>intnext[201];charsubstr[201];charstr[4001][201];charresult[201];chartemp[201];intlen[4001];intn,max 阅读全文
posted @ 2012-02-06 00:06 追逐. 阅读(369) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1936 额,这个用到啥了?好像只有字符串以'\0'为结尾吧...code:#include<cstdio>charstr[100001];charsubstr[100001];intmain(){inti,j;while(~scanf("%s%s",substr,str)){i=0,j=0;while(substr[i]!='\0'&&str[j]!='\0'){if(substr[i]==str[j])i++;j++;}if(substr[i] 阅读全文
posted @ 2012-02-05 19:19 追逐. 阅读(126) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3080 给定n个字符串,求最长公共子串。 利用KMP是对子串从1..j匹配母串,枚举第一个母串的所有后缀子串,在KMP匹配过程中得到j的最大值(这里不能完全匹配后再得最大值,为了确保取到所有子串),对n-1个母串匹配完成后,j最大值的最小值便为公共子串。若有多个这样的子串,字典顺序小者为result。 这里用到了string的两个函数,strcpy(substr, str)和strncpy(substr, str, n)。前者是复制到空字符停止复制,后者则是先找到n个字符再开始复制。使用后者后,要对复制所得字符串封存,substr[n] = 阅读全文
posted @ 2012-02-05 19:02 追逐. 阅读(372) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 18 下一页