摘要:
欧拉函数的应用。/* * hdu1286/linux.cpp * Created on: 2011-9-1 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>using namespace std;void work();int main() {#ifndef ONLINE_JUDGE freopen("data.in", "r", s 阅读全文
摘要:
这种水题都PE了好几次,真是不应该啊!/* * hdu1036/linux.cpp * Created on: 2011-8-31 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>using namespace std;void work();int main() {#ifndef ONLINE_JUDGE freopen("data.in", &quo 阅读全文
摘要:
这题完全是看解题报告做出来的,之前完全没有这样的思路, DP数组的含义还是挺好理解的,后面使用的时候反而是想了好久才理解……/* * hdu3555/linux.cpp * Created on: 2011-8-30 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>using namespace std;typedef long long I64;typedef unsig 阅读全文
摘要:
上次在北大暑期课期末考试里遇到这道题。最开始我是用BF实现DFA,超时。后来参考别人的程序用Trie实现,过了,但是还是理解得不够透彻。这几天做了不少KMP的题目,今天就用KMP实现了这个DFA,过了,很有成就感,呵呵~~/* * hdu3407/linux.cpp * Created on: 2011-7-29 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>using 阅读全文
摘要:
求模式串在主串中出现的次数,需要理解KMP后才能做,其实还是挺简单的,只要匹配完成一次后,j滑动到next[j]继续比较即可。刚开始一直TLE,上网找别人的代码比对,发现自己多写了一层循环,太粗心了……/* * hdu1686/linux.cpp * Created on: 2011-8-29 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>using namespace 阅读全文
摘要:
网上好多说得不够清楚,不过真正理解了KMP的next数组的含义,一点就通了。非优化的next数组的含义是:next[i]=k表示模式串下标为i的字符的前k个字符与开头的前k个字符相等,那么从0到i-1的模式串必然是循环的,循环节为从0到next[i] - (2 * next[i] - i),其中 2 * next[i] - i表示的是从后往前的部分与从前往后的部分相交的长度。/* * hdu1358/linux.cpp * Created on: 2011-8-29 * Author : ben */#include <cstdio>#include <cstdlib> 阅读全文
摘要:
刚学Sunday算法,都说Sunday比KMP快,于是我用Sunday打了半天,一直TLE,最后还是用KMP过了。不知道是不是我对Sunday算法的理解不正确,还是它只适合真正字符串的模式匹配。/* * hdu1711/linux.cpp * Created on: 2011-8-20 * Author : ben */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#define MAX_PAR_LEN 10005#define MAX_TXT_L 阅读全文
摘要:
水题,对输入的每一条信息,都对所有的四位数逐一判断是否符合,记录下即可。/* * hdu1172/linux.cpp * Created on: 2011-8-29 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>using namespace std;bool maybeans[10005];void work();int main() {#ifndef ONLINE_J 阅读全文
摘要:
长方体与球相交则必然是长方体中离球最近的点在球面上或球内,而长方体离球最近点必是每一维中离球最近的坐标组成的点。/* * hdu2436/linux.cpp * Created on: 2011-8-28 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>using namespace std;typedef long long I64;void work();int mai 阅读全文
摘要:
/* * hdu3629/linux.cpp * Created on: 2011-8-25 * Author : ben */#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>using namespace std;const int MAXN = 705;const double PI = acos(-1);typedef struct { int x; int y;} MyPoint;int N;MyPoint points[MAXN];double 阅读全文