摘要: 中国剩余定理例1:一个数被3除余1,被4除余2,被5除余4,这个数最小是几?题中3、4、5三个数两两互质。则〔4,5〕=20;〔3,5〕=15;〔3,4〕=12;〔3,4,5〕=60。为了使20被3除余1,用20×2=40;使15被4除余1,用15×3=45;使12被5除余1,用12×3=36。然后,40×1+45×2+36×4=274,因为,274>60,所以,274-60×4=34,就是所求的数。例2:一个数被3除余2,被7除余4,被8除余5,这个数最小是几?题中3、7、8三个数两两互质。则〔7,8〕=56;〔3, 阅读全文
posted @ 2012-02-29 22:41 yejinru 阅读(231) 评论(0) 推荐(0) 编辑
摘要: /*题目1)简介输入:正则表达式字符串 待匹配字符串,如果输入”### ###”程序终止,输出:如匹配成功,输出整个字符串,如果匹配不成功,输出lost,然后等待下一次用户的输入。^ 代表字符串开始. 代表任意字符$ 代表字符串末尾2)参考输入,输出^a.$ abc ←regular express and target string (separate by space),inputlost ←result, outputab.$ ababc ←regular express and target string (separate by space), inputababc ←match s 阅读全文
posted @ 2012-02-29 22:41 yejinru 阅读(5892) 评论(0) 推荐(1) 编辑
摘要: 编辑器加载中...本电子词典功能:查单词,单词复习,单词学习,单词填空,根据汉语输入英文,有时间提示的单词风暴第一部分:main函数编写#include <stdio.h>#include <string.h>#include "list.h"#include "tool.h"#include "game.h"#include <stdlib.h>int main(){int m=0,n=7950,c;char ch[130];struct wordnode *head=NULL;head=Crea 阅读全文
posted @ 2012-02-29 22:40 yejinru 阅读(674) 评论(0) 推荐(1) 编辑
摘要: ZOJ自己做了的(简单题,可直接点击题号到该题网页):1001 1002 1037 1045 1048 1049 1057 1067 1073 1078 1086 1089 1090 1095 1109 1110 1115 1151 1195 1240 1241 1251 1295 1414 1631 1715 1730 1755 1760 1763 1796 1884 1915 2001 2022 2060 2095 2099 2104 2108 2172 2176 2186 2201 2321 2345 2388 2405 2417 2421 2433 2476 2478 2480 248 阅读全文
posted @ 2012-02-29 22:40 yejinru 阅读(1062) 评论(0) 推荐(1) 编辑
摘要: #include <stdio.h>#include <stdlib.h>#define MAXN 1000 typedef struct queue{int qq[MAXN]; //队中元素int front; //队首下标int rear; //队尾下标int count; //队列中元素个数}queue;queue *q;int init() //队列初始化{q=(struct queue*)malloc(sizeof(struct queue)); //申请内存q->front=0; //都置为0q->rear=0;q->count=0;ret 阅读全文
posted @ 2012-02-29 22:38 yejinru 阅读(289) 评论(0) 推荐(0) 编辑
摘要: #include <cstdlib>#include <iostream>#include <cstdio> using namespace std;#define X 150001typedef struct node{ int id,m; int key; //按顺序}node;struct node f[X];int cmp(const void *a,const void *b){ struct node *c=(node *)a; //强转 struct node *d=(node *)b; if(d->m==c->m) //如果相等, 阅读全文
posted @ 2012-02-29 22:37 yejinru 阅读(169) 评论(0) 推荐(0) 编辑
摘要: //贪心法,使用排序函数,每次都找最便宜的牛奶,然后判断够没够重量#include <iostream>#include <algorithm>#define X 5010using namespace std;typedef struct milk //定义牛奶结构体{ int p; int a;}milk;int cmp(milk a,milk b) //对牛奶结构体排序{ return a.p<b.p; }int main(){ int n,m; freopen("sum.in","r",stdin); freopen 阅读全文
posted @ 2012-02-29 22:37 yejinru 阅读(282) 评论(0) 推荐(0) 编辑
摘要: 1000 A+B Problem 10% 直接加1002 Phone Numbers 50% 动态规划或最短路1003 Parity 70% 区间减法1004 Sightseeing trip 60% 最短路1005 Stone Pile 30% 动态规划或搜索1006 Square Frames 35% 模拟1007 Code Words 30% 模拟1008 Image encoding 30% 广度优先搜索1009 K-Based Numbers 20% 递推或枚举(数据规模小) 1010 Discrete Function 40% 贪心1011 Conductors 25% 搜索101 阅读全文
posted @ 2012-02-29 22:36 yejinru 阅读(300) 评论(0) 推荐(1) 编辑
摘要: Find a minimal interger K which is merely comprised of N and can be divided by M.For example,11 is the minimal number that and be divided by 11, and it is comprised of two '1's, and 111111 can be divided by 13 which is comprised of six '1's.InputOn each line of input , there will be 阅读全文
posted @ 2012-02-29 22:35 yejinru 阅读(371) 评论(0) 推荐(0) 编辑
摘要: 编辑器加载中...自己写了一个:根据m^n mod y,m*m*...*m = y*x+r,再乘以m时相当于r乘以m即可同理,令r = 1,r = (r*m)%y,这样相乘n次,我的模板(时间复杂度为O(n)),n太大时,可能超时:int r = 1;for(j=0;j<n;j++)r = (r*i)%m;求a^b%c(这就是著名的RSA公钥的加密方法) 算法1:直接将b个a相乘,利用a*b%c=((a%c)*b)%c,每一步都进行这种处理,解决了a^b可能太大存不下的问题,这个算法的时间复杂度是O(n)。当b很大时运行时间会很长 。 算法2:利用分治的思想,可以达到O(logn)。 可 阅读全文
posted @ 2012-02-29 22:34 yejinru 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 偶做完的:1000100110021003100410051006100710081011101210141017102810391041104610471050106110641066106710681080108810891094110111021106111311181125112611271129114011411144114511491151115911631164118211901195120112041207122212261228123612371247125112581265126912701273127412761284128613081325132813301338135 阅读全文
posted @ 2012-02-29 22:32 yejinru 阅读(539) 评论(0) 推荐(1) 编辑
摘要: 题目:给出两个顶点并且给出两个顶点之间的概率,求从1到n的最大的概率分析:纯粹是dijkstra算法,只不过把最短路径改动一下而已要先定义dp[n]=1;后面的直接套用dijkstra模板,把min部分改为max即可,并且之前加的部分改为相乘即可dijkstra模板:设图由邻接矩阵g存储。memset(dist,0x3f,sizeof(dist));memset(used,false,sizeof(used));dist[0]=0;//设0为源点for(i=0;i<n;i++)//循环n次{min=10000000;for(j=0;j<n;j++)//找到最小值if(!used[j 阅读全文
posted @ 2012-02-29 22:31 yejinru 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 第一道懂的深度优先搜索题,找图中八连块的个数#include <iostream>#include <cstring>using namespace std;#define X 100int visit[X][X];int a[X][X];void dfs(int x,int y) //深度优先搜索{if(visit[x][y]||!a[x][y]) //如果是白色或者是遍历过的return;visit[x][y] = 1; //遍历过的标记为一dfs(x-1,y-1); dfs(x-1,y); dfs(x-1,y+1); //递归遍历周围dfs(x,y-1); dfs 阅读全文
posted @ 2012-02-29 22:31 yejinru 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 题目:回文是一个对称的字符串,换句话说,这个字符串从左到右读和从右到左读是一样的。给出一个字符串,你要编一个程序,决定要插入的最少的字符个数,使得原字符串成为一个回文。比如,字符串”Ab3bd”中插入2个字符,使得它能变成一个回文("dAb3bAd" 或 "Adb3bdA")。如果插入少于2个字符,将无法产生回文。求最少插入几个字符,使其变成回文字符串分析:S1 = Ab3bd 的反转为S2 = db3ba要使S1变成回文字符串,可先求出S1,S2的最长公共子序列,用n-lcs(S1,S2)即可,本题转化为求S1,S2的最长公共子序列状态转移方程:if( 阅读全文
posted @ 2012-02-29 22:30 yejinru 阅读(212) 评论(0) 推荐(0) 编辑
摘要: ******************************************************************************* 简单题(包括枚举,二分查找,(复杂)模拟,基础数据结构(栈、队列),杂题等 * ******************************************************************************1001 A+B1002 A+B+C1009 Fat Cat1010 The Angle1011 Unix ls1012 Decoding Task1019 Grandpa's Other Est 阅读全文
posted @ 2012-02-29 22:30 yejinru 阅读(2295) 评论(0) 推荐(1) 编辑
摘要: /*记忆化搜索,每次遍历到该位置,先把他能够遍历的邻点遍历完,直到不能遍历为止,然后选择四个可走的邻接点的最值,利用数组记录当前位置的最优值,若遇到已经遍历过的位置时,直接返回该位置的最优值,完成该次递归*/#include <iostream>#include <cstring>#include <cstdio>using namespace std;#define X 102int map[X][X],dp[X][X],n,m;int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1}}; //状态偏移量int f(int x, 阅读全文
posted @ 2012-02-29 22:29 yejinru 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 题目:纯粹最长上升子序列(lis:Longest Increasing Subsequence)状态转移方程(时间复杂度为O(n*n)) if(a[i]<a[j])dp[i]=Max(dp[i],dp[j]+1);解一:根据状态转移方程:if(a[i]<a[j])dp[i]=Max(dp[i],dp[j]+1);#include <iostream>#include <cstring>using namespace std;#define X 1003int dp[X];int a[X];int Max(int a,int b){return a>b? 阅读全文
posted @ 2012-02-29 22:29 yejinru 阅读(180) 评论(0) 推荐(0) 编辑
摘要: /*题目: 求最大子矩阵的和分析: 我的做法: 0 -2 -7 0 9 2 -6 2 -4 1 -4 1 -1 8 0 -2 我们可以按每一行计算从j开始到k结束的该段和,用dp[i][j][k] 表示第i行的元素从下标j开始到k结束的和,把每一行的都求出, 从而转化为求每一列的最大子序和,本例中, 先求dp[0][0][0] = a[0][0],dp[0][0][1] = a[0][0]+a[0][1],... 从而求完n行,时间复杂度为O(n*n*n),然后每一列dp根据一维最大 子序列和来计算,算出最大的和即... 阅读全文
posted @ 2012-02-29 22:28 yejinru 阅读(260) 评论(0) 推荐(0) 编辑
摘要: 参考别人的程序后弄明白了,看来我还是很菜啊==!别人:状态定义为dp[i],在i之前要达到合法message需要删除的最少的字符数,转移的时候是dp[i-1]+1和dp[i-(能匹配的字典串的长度+需要删除的字符串的长度)]+需要删除的字符串的长度。自己:定义状态为dp[i],dp[i]为i前的单词最少要删除的字母数,当i=i+1时,判断target[i]==word[j][word[j].size()-1]是否相等,即判断该单词与字典中的单词的最后一位是否匹配,匹配的话往前算算是否该字典中的单词全部出现在要求匹配单词中,如果是并且该dp小于dp[i]+1的话,转移!转移方程为:dp[i]=m 阅读全文
posted @ 2012-02-29 22:28 yejinru 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 矩阵链乘法:矩阵P={}标准模板:for(int i=2;i<=n;i++)for(int j=1;j<=n-i+1;j++){int temp = i+j-1;dp[j][temp] = 1000000000;for(int k=j;k<=temp-1;k++){v = dp[j][k]+dp[k+1][temp]+p[j-1]*p[k]*p[temp];if(v<dp[j][temp]){dp[j][temp] = v;s[j][temp] = k;}}}相乘次数(答案) = dp[1][n]打印最佳链乘表达式:void print(int i,int j){if( 阅读全文
posted @ 2012-02-29 22:27 yejinru 阅读(187) 评论(0) 推荐(0) 编辑