- 博客(80)
- 资源 (4)
- 收藏
- 关注
原创 hdu2817 A sequence of numbers (a^i mod n)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2817#include #define MOD 200907_int64 pow_mod(_int64 a,_int64 k){ _int64 temp=1; while(k) { if(k&1) temp=(temp*a)%MOD; a=(a*a)%MOD;
2013-08-31 09:31:58 613
原创 hdu2157 How many ways?? (矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2157题解:见:http://www.matrix67.com/blog/archives/276#include #include #define MAXN 21 #define MOD 1000 typedef struct Matrix {
2013-08-28 19:01:10 570
原创 hdu1575 Tr A (矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1575#include #include #define MAXN 11#define MOD 9973typedef struct Matrix{ int matr[MAXN][MAXN];}Matrix;int n;Matrix init,unit,c;Matr
2013-08-28 12:41:01 532
原创 hdu2473 Junk-Mail Filter (并查集删除节点)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2473题解:为每一个结点加一个虚根,这样每个结点都是叶子结点.插入结点时,把它们都并到虚根的集合中.删除结点时,只要把它的父结点置为一个无用的虚根。#include #include #define MAXN 1000002int father[MAXN<<1],flag
2013-08-27 12:26:15 698
原创 hdu1811 Rank of Tetris (并查集+拓扑排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1811#include #include #include #include #define MAXN 10001 using namespace std; vector mp[MAXN]; queueQ;int n,sum;int indegree[
2013-08-26 21:35:15 641
原创 hdu1598 find the most comfortable road
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1598#include #include #include #define INF 9999999#define MAXN 1002struct node { int st,end,val;}edge[MAXN];int father[202];int cmp(co
2013-08-26 19:01:41 599
原创 hdu1879 继续畅通工程 (prim)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1879题解:已修建道路,边权值赋值0#include #include #define MAXN 102#define INF 9999999int mp[MAXN][MAXN],visited[MAXN],dist[MAXN];int prim(int n){
2013-08-26 12:36:37 681
原创 hdu1272 小希的迷宫
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1272题解:任意两个房间有且仅有一条路径可以相通,判断是否是一棵树(不存在回路)#include #include #define MAXN 100002int father[MAXN],flag[MAXN],sig;int find(int x){ while(
2013-08-26 11:56:59 569
原创 hdu1978 How many ways
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1978题解:状态转移方程:dp[i+k][j+h]=(dp[i+k][j+h]+dp[i][j])%10000;#include #include #define MAXN 102int dp[MAXN][MAXN];int main(){ int i,j,k,h
2013-08-25 18:11:44 600
原创 hdu1789 Doing Homework again (贪心)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1789题解:贪心,reduced score最大最先完成#include #include #include #define MAXN 1002struct node { int deadline,score;}hwork[MAXN];int cmp(cons
2013-08-25 12:35:27 653
原创 hdu1723 Distribute Message
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1723题解:dp[i]表示传到第i个有dp[i]种方法,i可以传给后面1--m之间任意一个人dp[i+j]+=dp[i]#include #include int main(){ int n,m,i,j; int dp[32]; while (scanf("%d %
2013-08-23 08:09:31 665
原创 hdu2647 Reward (拓扑排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647#include #include #include #include #define MAXN 10002using namespace std;vector mp[MAXN];queueQ;int indegree[MAXN],reward[
2013-08-22 20:24:24 583
原创 hdu2094 产生冠军 (并查集+拓扑排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2094题解:转化成图,a->b,b->c......能产生冠军,存在唯一一个点入度为0.#include #include int father[2001],degree[2001],tot;char str[2001][20];int check(char *s)
2013-08-22 17:12:57 849
原创 hdu2087 剪花布条
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2087#include #include #define MAXN 1002 int next[MAXN],len1,len2; char text[MAXN],pattern[MAXN]; void
2013-08-20 20:43:41 479
原创 hdu2203 亲和串
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2203题解:要求一个串循环后是否包含另外一个串,只要将母串重复一次再进行KMP匹配,因为在重复母串的过程中,其实据已经将循环后的所有可能都列举出来了,比如串 "ABCD" 重复后为 "ABCDABCD" 在这个串中 "BCDA" , "CDAB" 以及 "DABC" 都接踵呈现了。
2013-08-20 20:21:43 618
原创 hdu2594 Simpsons’ Hidden Talents
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2594题解:finds the longest prefix of s1 that is a suffix of s2. s1作为模式串 s2作为原串,进行KMP #include #include #define MAXN 50002
2013-08-20 13:26:34 533
原创 hdu1841 Find the Shortest Common Superstring
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1841题解:1.s1是s2的子串,或者s2是s1的子串。2.s1是s2的前缀或者后缀。#include #include #define MAXN 1000002 int next[MAXN]; char str1[MAXN],str2
2013-08-20 12:42:58 766
原创 hdu1848 Fibonacci again and again (博弈SG值)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848#include #include #define MAXN 1002int sg[MAXN],hash[MAXN];int fib[15]={1,2,3,5,8,13,21,34,55,89,144,233,377,610,987};void getSG(int n)
2013-08-20 11:14:30 785
原创 hdu1686 Oulipo
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1686裸KMP#include #include #define MAXN 1000002 int next[10002],n,m; char text[MAXN],pattern[10002]; void getNext()
2013-08-20 08:24:01 695
转载 KMP算法
KMP字符串模式匹配详解来自CSDN A_B_C_ABC 网友KMP字符串模式匹配通俗点说就是一种在一个字符串中定位另一个串的高效算法。简单匹配算法的时间复杂度为O(m*n);KMP匹配算法。可以证明它的时间复杂度为O(m+n).。一. 简单匹配算法先来看一个简单匹配算法的函数:int Index_BF ( char S [ ], char T [ ], int po
2013-08-20 08:03:38 626
原创 hdu1711 Number Sequence
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1711题解:KMP模版题使用"输入外挂"时间缩短很多(484ms-->156ms) "输入外挂":http://blog.csdn.net/niushuai666/article/details/6689043#include #include #defi
2013-08-20 00:10:02 576
原创 hdu1800 Flying to the Mars (字典树)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1800题解:the minimum number of broomsticks needed,The soldier who has a higher level could teach the lower , that is to say the former’s level > the
2013-08-19 22:37:30 641
原创 hdu1250 Hat's Fibonacci
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1250大数相加#include #include #include int fib[7050][510];int main(){ int i,j,temp=0,n; for(i=1; i<=4; ++i) fib[i][1]=1;
2013-08-19 09:55:22 614
原创 hdu1113 Word Amalgamation
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1113题解:输入单词,判断字典里是否存在和输入的一样的单词(字典单词字母可以任意排序)。将字典里的单词(组成单词的字母排序)按字典序排列,输入的单词也按字典序排序,在进行比较。#include #include #include #include using namesp
2013-08-18 21:40:23 584
原创 hdu2846 Repository (字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2846题解:For each query, you just output the number of the merchandises, whose names contain the search string as their substrings. 求输入的单词是字
2013-08-17 20:59:20 742
原创 hdu1305 Immediate Decodability (字典树)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1305题解:判断字符串是否存在前缀#include #include #define MAXN 100002 int child[MAXN][11];//child[i][j]=0说明没有对应的节点,以i为根节点的子树, int flag[MAXN]; i
2013-08-17 19:50:21 624
原创 hdu1072 What Are You Talking About (字典树)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1075题解:套字典树模版即可#include #include #include #define MAXN 50002 typedef struct node { struct node *child[26];//存储下一个字符
2013-08-17 19:15:30 621
原创 hdu1247 Hat’s Words (字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1247题解:给一些单词,找出那些可以分成另外的两个单词的单词,字典树#include #include #include #define MAXN 50002typedef struct node { struct node *child[26];
2013-08-17 13:54:34 638
原创 hdu1671 Phone List (字典树)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1671 题解:判断字符串是否存在前缀,字典树(静态字典树)#include #include #define MAXN 100002int child[MAXN][10];//child[i][j]=0说明没有对应的节点,以i为根节点的子树,int flag[MAXN]
2013-08-17 11:53:27 600
原创 hdu1251 统计难题 (字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251题解:字典树模版题,Trie树|字典树的简介及实现(转)Trie,又称字典树、单词查找树,是一种树形结构,用于保存大量的字符串。它的优点是:利用字符串的公共前缀来节约存储空间。相对来说,Trie树是一种比较简单的数据结构.理解起来比较简单,正所谓简单的东西也得付出代价.故T
2013-08-17 10:01:01 638
原创 hdu2161 Primes
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2161#include int isprime(int n){ int i; if(n==1||n==2) return 0; for (i=2;i*i<=n;i++) { if(n%i==0) r
2013-08-16 21:06:50 1032
原创 hdu1262 寻找素数对
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1262#include #include #define MAXN 10000#define SIZE 10002int prime[SIZE],valid[SIZE];void getPrime()//素数筛选O(N){ int i,j,tot=0; memset(va
2013-08-16 21:00:34 628
原创 hdu1285 确定比赛名次 (拓扑排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1285#include #include #include #include #include #define MAXN 502using namespace std;vectormp[MAXN];int ans[MAXN],degree[MAXN],n;struct
2013-08-16 20:23:15 666
原创 hdu1128 Self Numbers
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1128#include #include #define MAXN 1000000#define SIZE 1000002bool arr[SIZE];int main(){ int i,j,pre; memset(arr,false,sizeof(false)); f
2013-08-16 18:21:12 538
原创 hdu1215 七夕节 (因子分解)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1215#include int main(){ int t,sum,i,n; scanf("%d",&t); while(t--) { sum=0; scanf("%d",&n); for (i=1;i*i
2013-08-16 17:40:40 577
原创 hdu2824 The Euler function (欧拉函数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824打表#include #include #define MAXN 3000002#define MAX 3000000int prime[MAXN],phi[MAXN],valid[MAXN],tot;void getPrime()//素数筛选O(N){
2013-08-16 10:37:51 602
原创 hdu2138 How many prime numbers (素数测试)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2138米勒拉宾算法#include _int64 pow_mod(_int64 a,_int64 b,_int64 mod){ _int64 ans=1; while(b) { if(b&1) ans=(ans*a)%mod; a=(a*a)%mod
2013-08-16 09:52:06 624
原创 hdu2577 How to Type
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2577题解:dp[i][0]存放当前是小写状态,dp[i][1]存放当前是大写的状态。 小写字母可在caps lock不亮时打出,也可在caps lock亮时,按shift打出 大写字母可在caps lock亮时打出,也可在caps lock不亮时,按
2013-08-15 20:47:53 613
原创 hdu1505 City Game (最大子矩形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1505题解:hdu1506的二维情况,见hdu1506题解。#include #include #define MAXN 1002 int height[MAXN],left[MAXN],right[MAXN];int main(){ int n,m,i,j,a
2013-08-15 11:22:20 662
原创 hdu1506 Largest Rectangle in a Histogram
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1506对于每一块木板,Area=height[i]*(j-k+1) 其中,jxk,height[x]>=height[i];#include #define MAXN 100005_int64 height[MAXN],left[MAXN],right[MAXN];
2013-08-15 10:34:41 590
计算机端口TCPIP详细介绍
2011-04-16
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人