04 2013 档案

摘要:1 //2^n个运动员 2 #include<stdio.h> 3 int a[100][100]; 4 int n; 5 6 void fun(int n) 7 { 8 int u,v,j,i; 9 if(n==0) a[n][n]=1;10 else11 {12 fun(n-1);13 u=1<<(n-1);14 v=1<<n;15 for(i=0;i<u;i++)16 for(j=u;j<v;j++)17 a[i][j]=a[i][j... 阅读全文
posted @ 2013-04-30 09:53 萧凡客 阅读(222) 评论(0) 推荐(0) 编辑
摘要:问题描述:n在我们现在使用的日历中, 闰年被定义为能被4整除的年份n但是能被100整除而不能被400整除的年是例外,它们不是闰年。例如:1700, 1800, 1900 和 2100 不是闰年,而 1600, 2000 和 2400是闰年。给定从公元2000年1月1日(周六)开始逝去的天数,你的任务是给出这一天是哪年哪月哪日星期几输入:n输入包含若干行,每行包含一个正整数,表示从2000年1月1日开始逝去的天数。输入最后一行是−1, 不必处理。可以假设结果的年份不会超过9999。输出:n对每个测试样例,输出一行,该行包含对应的日期和星期几。n格式为“YYYY-MM-DD DayOfWeek”, 阅读全文
posted @ 2013-04-26 18:07 萧凡客 阅读(1374) 评论(0) 推荐(0) 编辑
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 const int maxn = 6; 5 int table[maxn][maxn]; 6 int hash_col[maxn][maxn], hash_row[maxn][maxn], hash_gro[maxn][maxn]; 7 int gro_id[maxn][maxn]; 8 int cas = 0; 9 void next_pos(int& r, int& c)10 {11 if(5 == c)//这里写成了 阅读全文
posted @ 2013-04-25 11:04 萧凡客 阅读(380) 评论(6) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 void move(char a,char b) 3 { 4 printf("%c->%c\n",a,b); 5 } 6 void han(int n,char a,char b,char c) 7 { 8 if(n>0) 9 {10 han(n-1,a,c,b);11 move(a,b);12 han(n-1,c,b,a);13 }14 }15 int main()16 {17 int n;18 scanf("%d",&n);19 printf... 阅读全文
posted @ 2013-04-25 10:13 萧凡客 阅读(161) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 #include<string.h> 3 #include<set> 4 #include<time.h> 5 using namespace std; 6 7 typedef int state[9]; 8 const int max=1000000; 9 state st[max],goal;10 int dist[max];11 const int dx[]={-1,1,0,0};12 const int dy[]={0,0,-1,1};13 14 struct cmp15 {16 bool op 阅读全文
posted @ 2013-04-24 21:43 萧凡客 阅读(197) 评论(0) 推荐(0) 编辑
摘要:拓扑排序一.概念 由某个集合上的一个偏序得到该集合上的一个全序,这个操作称之为拓扑排序。二.拓扑排序方法如下: (1)从有向图中选择一个没有前驱(即入度为0)的顶点并且输出它. (2)从网中删去该顶点,并且删去从该顶点发出的全部有向边. (3)重复上述两步,直到剩余的网中不再存在没有前趋的顶点为止.三.算法实现 1.普通实现 1 #include<iostream> 2 #include<stdlib.h> 3 #include<stdio.h> 4 #define MAX 100 5 using namespace std; 6 7 void toposo 阅读全文
posted @ 2013-04-23 20:54 萧凡客 阅读(149) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 #include<string.h> 3 4 char a[7]; 5 char b[750][7]; 6 char c[6]={'A','B','C','D','E','*'}; 7 int t[4][2]={1,0,0,1,0,-1,-1,0}; 8 int temp; 9 10 int fun(char *p,int n,int m)11 {12 int i,j,x,y,u;13 char v[6],k;14 if(!(str 阅读全文
posted @ 2013-04-22 14:06 萧凡客 阅读(281) 评论(0) 推荐(0) 编辑
摘要:矢量叉积矢量P = ( x1, y1 ),Q = ( x2,y2 ),则矢量叉积定义为由(0,0)、p1、p2和p1+p2所组成的平行四边形的带符号的面积,即:P× Q = x1*y2 - x2*y1积的一个非常重要性质是可以通过它的符号判断两矢量相互之间的顺逆时针关系: 若 P × Q > 0 , 则P在Q的顺时针方向。 若 P × Q < 0 , 则P在Q的逆时针方向。 若 P × Q = 0 , 则P与Q共线,但可能同向也可能反向。折线段的拐向判断: 折线段的拐向判断方法可以直接由矢量叉积的性质推出。对于有公共端点的线段p0p1和p1p 阅读全文
posted @ 2013-04-21 10:47 萧凡客 阅读(1879) 评论(0) 推荐(1) 编辑
摘要:/*问题描述:n个人(编号0~(n-1)),从0开始报数,报到m-1的退出,剩下的人继续从0开始报数。求胜利者的编号。*/#include <stdio.h> int main(void) { int n, m, i, s=0; printf ("N M = "); scanf("%d%d", &n, &m); for (i=2; i<=n; i++) s=(s+m)%i; printf ("The winner is %d\n", s); return 0 ; } 1 #include<std 阅读全文
posted @ 2013-04-18 13:06 萧凡客 阅读(170) 评论(0) 推荐(0) 编辑
摘要:1 //超时了!!! 2 #include<stdio.h> 3 #include<string.h> 4 5 char a[200001]; 6 char b[100001]; 7 int next[100001]; 8 int A,B; 9 10 void getnext()11 {12 int i,j;13 i=0;j=-1;14 next[0]=-1;15 while(i<B)16 {17 if(j==-1||b[i]==b[j])18 next[++i]=++j;19 else20 ... 阅读全文
posted @ 2013-04-16 21:51 萧凡客 阅读(179) 评论(0) 推荐(0) 编辑
摘要:/*在很多软件中,输入拼音的首写字母就可以快速定位到某个词条。比如,在铁路售票软件中,输入: “bj”就可以定位到“北京”。怎样在自己的软件中实现这个功能呢?问题的关键在于:对每个汉字必须能计算出它的拼音首字母。 GB2312汉字编码方式中,一级汉字的3755个是按照拼音顺序排列的。我们可以利用这个特征,对常用汉字求拼音首字母。 GB2312编码方案对每个汉字采用两个字节表示。第一个字节为区号,第二个字节为区中的偏移号。为了能与已有的ASCII编码兼容(中西文混排),区号和偏移编号都从0xA1开始。 我们只要找到拼音a,b,c,...x,y,z 每个字母所对应的GB2... 阅读全文
posted @ 2013-04-16 14:00 萧凡客 阅读(321) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 #include<time.h> 3 #include<string.h> 4 //#include<conio.h> 5 //#include<math.h> 6 //有的注释 是用来测试数据 7 #define N 21 8 int a[10][N+1]; 9 void fun() 10 { 11 int i,temp,j,k,t; 12 memset(a,0,sizeof(a)); 13 for(i=1;i<10;i++) 14 { 15 a[i][0]=1; 16 ... 阅读全文
posted @ 2013-04-14 08:28 萧凡客 阅读(197) 评论(0) 推荐(0) 编辑
摘要:1 //就是字符串和它的逆串最大连续公共字串 2 3 #include<stdio.h> 4 #include<string.h> 5 #include<stdlib.h> 6 char a[100]; 7 char b[100]; 8 int c[100][100]; 9 10 int main()11 {12 int n,i,j,k,t,p;13 scanf("%d",&n);14 while(n--)15 {16 scanf("%s",a);17 t=strlen(a);18 for(i=0;i<t 阅读全文
posted @ 2013-04-12 17:01 萧凡客 阅读(156) 评论(0) 推荐(0) 编辑
摘要:【数学之美】抽屉原理桌上有十个苹果,要把这十个苹果放到九个抽屉里,无论怎样放,我们会发现至少会有一个抽屉里面放两个苹果。这一现象就是我们所说的“抽屉原理”。 抽屉原理的一般含义为:“如果每个抽屉代表一个集合,每一个苹果就可以代表一个元素,假如有n+1或多于n+1个元素放到n个集合中去,其中必定至少有一个集合里有两个元素。” 抽屉原理有时也被称为鸽巢原理(“如果有五个鸽子笼,养鸽人养了6只鸽子,那么当鸽子飞回笼中后,至少有一个笼子中装有2只鸽子”)。它是组合数学中一个重要的原理。例1:从1、2、3、4、…、19、20这20个自然数中,至少任选几个数,就可以保证其中一定包括两个数,它们的差是12。 阅读全文
posted @ 2013-04-11 22:47 萧凡客 阅读(278) 评论(0) 推荐(0) 编辑
摘要:C语言字符串函数大全函数名: stpcpy功能: 拷贝一个字符串到另一个用法: char *stpcpy(char *destin, char *source);程序例:#include <stdio.h>#include <string.h>int main(void){ char string[10]; char *str1 = "abcdefghi"; stpcpy(string, str1); printf("%s\n", string); return 0;}函数名: strcat功能:字符串拼接函数用法: char * 阅读全文
posted @ 2013-04-11 15:15 萧凡客 阅读(177) 评论(0) 推荐(0) 编辑
摘要:标题:计算差三角仔细观察下面的数字组成的三角形:314562看出什么特征吗?首先,它包含了1~6的连续整数。重要的是:每个数字都是其下方相邻的两个数字的差(当然是大数减去小数)满足这样特征的三角形,称为:差三角。你的任务是找出1~15的整数组成的一个更大的差三角。其形如:?4????*????????其中,只给出了一个确定的数字:4请确定出“*”代表的是哪个一个数字。直接提交该数字,不要提交多余的内容。//暴力求解#include<stdio.h>#include<math.h>#include<string.h>int a[5][6];int v[16]; 阅读全文
posted @ 2013-04-11 14:05 萧凡客 阅读(248) 评论(0) 推荐(0) 编辑
摘要:1 //线段树的节点 2 //节点包括两部分信息,基本域,和信息域 3 //基本域:左右边界ld,rd. 左右孩子:lc,rc 4 //信息域:key值,如RMQ问题中,信息域中存储的是区间最大值 5 struct Node{ 6 int ld,rd; 7 Node *lc,*rc; 8 int key; 9 };10 11 //空树的建立,内含key值的初始化;12 //一般在主函数中首先调用 Node* root= buildtree(1,n);建立一棵新树13 Node *buildtree(int a,int b){14 Node * p=new ... 阅读全文
posted @ 2013-04-09 22:03 萧凡客 阅读(150) 评论(0) 推荐(0) 编辑
摘要:1. 概述RMQ(Range Minimum/Maximum Query),即区间最值查询,是指这样一个问题:对于长度为n的数列A,回答若干询问RMQ(A,i,j)(i,j<=n),返回数列A中下标在i,j之间的最小/大值。这两个问题是在实际应用中经常遇到的问题,下面介绍一下解决这两种问题的比较高效的算法。当然,该问题也可以用线段树(也叫区间树)解决,算法复杂度为:O(N)~O(logN),这里我们暂不介绍。2.RMQ算法对于该问题,最容易想到的解决方案是遍历,复杂度是O(n)。但当数据量非常大且查询很频繁时,该算法无法在有效的时间内查询出正解。本节介绍了一种比较高效的在线算法(ST算法 阅读全文
posted @ 2013-04-09 21:59 萧凡客 阅读(437) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 #include<string.h> 3 4 char a[1000010]; 5 char b[10010]; 6 int next[10010]; 7 int A,B; 8 void getnext() 9 {10 int i=0,j=-1;11 next[0]=-1;12 while(i<B)13 {14 if(j==-1||b[i]==b[j]) next[++i]=++j;15 else j=next[j];16 }17 }18 19 int kmp_i()... 阅读全文
posted @ 2013-04-09 21:47 萧凡客 阅读(286) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 5 char a[12]; 6 char b[12]; 7 8 int f() 9 {10 int i,n,t=0;11 n=strlen(a);12 for(i=0;i<n;i++)13 t=t*26+(a[i]-'A'+1);14 return t;15 16 }17 char* v()18 {19 int i,j,t,n;20 char c[1... 阅读全文
posted @ 2013-04-08 11:23 萧凡客 阅读(296) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 char str[1005]; 5 int start; 6 char s[50],ss[50];int i,j; 7 double Term();double Expression();double Factor(); 8 double Term() 9 { 10 double f=Factor(),t; 11 --start; 12 if(str[start]=='*') 13 { ... 阅读全文
posted @ 2013-04-06 17:00 萧凡客 阅读(193) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 #include<queue> 3 #include<string.h> 4 using namespace std; 5 6 int c[2][3]; 7 int v[100][100]; 8 typedef struct 9 {10 int vis[3];11 int deep;12 }node;13 14 int fun()15 {16 int i,j,at;17 queue <node> q;18 node n,t;19 memset(v,0,sizeof(v));20 n.vis... 阅读全文
posted @ 2013-04-06 16:30 萧凡客 阅读(183) 评论(0) 推荐(0) 编辑
摘要:Office办公软件考试试题题目课程名称Office 办公自动化(XHKC-ZY-002)题型单选题题目在选定了整个表格之后,若要删除整个表格中的内容,以下哪个操作正确( )选择A单击“表格”菜单中的“删除表格”命令选择B按Delete键选择C按Space键选择D按Esc键答案B题目艺术字对象实际上是( )选择A文字对象选择B图形对象选择C链接对象选择D既是文字对象,也是图形对象答案B题目在Excel 2003 中,进行分类汇总之前,我们必须对数据清单进行( )选择A筛选选择B排序选择C建立数据库选择D有效计算答案B题目Word 2003 中对文档分栏后,若要使栏尾平衡,可在最后一栏的栏尾插入 阅读全文
posted @ 2013-04-06 15:24 萧凡客 阅读(10246) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 3 int fun(int n,int p) 4 { 5 int a,t; 6 if(p==0) return 1; 7 if(p==1) return n; 8 a=fun(n,p/2); 9 t=a*a%10003;10 if(p&1)11 t=t*n%10003;12 return t;13 }14 15 int main()16 {17 int n,m,t,i,sum;18 scanf("%d",&t);19 while(t--)20 ... 阅读全文
posted @ 2013-04-06 15:19 萧凡客 阅读(401) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 3 int a[32][32]; 4 int m; 5 6 int fun() 7 { 8 int i,j,k; 9 for(i=0;i<m;i++)10 if(a[i][i]!=0) return 1;11 12 for(i=0;i<m;i++)13 for(j=0;j<m;j++)14 if(i!=j)15 if(a[i][j]<=0) return 2;16 17 for(i=0;i<m;i++)18 ... 阅读全文
posted @ 2013-04-06 11:47 萧凡客 阅读(180) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 3 int a[4][4]; 4 typedef struct 5 { 6 int x; 7 int y; 8 }node; 9 node s[10]; 10 11 void cs()//用来存放数字的结构体,x,y分别是他们的行列坐标 12 { 13 s[0].x=3;s[0].y=1; 14 s[1].x=0;s[1].y=0; 15 s[2].x=0;s[2].y=1; 16 s[3].x=0;s[3].y=2; 17 s[4].x=1;s[4].y=0; 18 ... 阅读全文
posted @ 2013-04-06 11:26 萧凡客 阅读(157) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 #include<algorithm> 3 #include<stdlib.h> 4 using namespace std; 5 6 typedef struct 7 { 8 int x; 9 int y;10 }node;11 12 int fun(int a)13 {14 int t=0;15 while(a)16 {17 t=t*10+a%10;18 a=a/10;19 }20 return t;21 }22 23 int cmp(const nod... 阅读全文
posted @ 2013-04-06 10:36 萧凡客 阅读(226) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 #include<string.h> 3 int a[1000]; 4 5 void fun(int n) 6 { 7 int i,t,v; 8 v=0; 9 for(i=0;i<1000;i++)10 {11 t=a[i]*n+v;12 a[i]=t%10;13 v=t/10;14 }15 }16 17 int main()18 {19 int i,j,n,m;20 scanf("%d",&n);21 while(n--)22 ... 阅读全文
posted @ 2013-04-06 10:35 萧凡客 阅读(303) 评论(0) 推荐(0) 编辑
摘要:1 #include <iostream> 2 using namespace std; 3 const int N = 11; 4 int Board[N][N]; 5 int tile = 0; 6 7 /* 8 tr:棋盘左上角方格的行号 9 tc:棋盘左上角方格的列号10 dr:特殊方格所在的行号11 dc:特殊方格所在的列号12 size:方形棋盘的边长13 */14 void ChessBoard(int tr, int tc, int dr, int dc, int size)15 {16 if(size == 1)17 return;18 ... 阅读全文
posted @ 2013-04-05 20:27 萧凡客 阅读(258) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 #include<string.h> 3 4 int main() 5 { 6 int i,j,f[100],t[1000],w[100],T,M; 7 scanf("%d%d",&T,&M); 8 for(i=0;i<M;i++) 9 scanf("%d%d",&t[i],&w[i]);10 memset(f,0,sizeof(f));11 for(i=0;i<M;i++)12 for(j=T;j>=t[i];j--)13 f[j]=f 阅读全文
posted @ 2013-04-05 19:36 萧凡客 阅读(127) 评论(0) 推荐(0) 编辑
摘要:1 double p(int m,int n) 2 { 3 double a,b; 4 if(n==1) return (double)m; 5 else b=p(m,n/2); 6 a=b*b; 7 if(n%2==1) 8 a=a*m; 9 return a;10 } 阅读全文
posted @ 2013-04-05 09:36 萧凡客 阅读(150) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 3 int n,l; 4 char s[100]; 5 6 int dfs(int cur) 7 { 8 int i,j,ok,equal,k; 9 if(cur==n)10 {11 for(i=0;i<n;i++)12 printf("%c",'A'+s[i]);13 printf("\n");14 return 0;15 }16 for(i=0;i<l;i++)17 {18 s[cur]=i;19 ... 阅读全文
posted @ 2013-04-03 22:25 萧凡客 阅读(274) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 #include<string.h> 3 #include<queue> 4 using namespace std; 5 6 const int max=100; 7 int c[3]; 8 int w; 9 int vis[max][max];10 int m;11 typedef struct 12 {13 int v[3];14 int deep;15 //ruct node *fa;16 //t a;17 //t b;18 }node;19 20 21 int bfs()22 {23 in... 阅读全文
posted @ 2013-04-03 17:53 萧凡客 阅读(171) 评论(0) 推荐(0) 编辑
摘要:1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 /*下面定义结点的类型*/ 5 #define Min(a,b) ((a>b)?b:a) 6 //宏定义的操作符Min作用 取最小值; 7 const int MAX=1010; 8 //解答树的结点最多 9 typedef struct Node 10 { 11 int v[3];//三个杯子的剩余水量; 12 int fa;//第一次访问到这个结点是的前一个结点的下标; 13 //通过下... 阅读全文
posted @ 2013-04-01 22:25 萧凡客 阅读(1912) 评论(0) 推荐(1) 编辑