摘要: http://poj.org/problem?id=1308 1 #include 2 #include 3 #define N 100001 4 int bin[N],flag; 5 int find(int x) 6 { 7 //不压缩路径 8 /*int r=x; 9 while(bin[r]!=r)10 r=bin[r];11 return r;*/12 13 //压缩路径14 int k,t;15 t=x;16 while(t!=bin[t])17 t=bin[t];18 ... 阅读全文
posted @ 2013-08-02 10:49 海东青飞吧! 阅读(217) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1611 1 #include 2 int bin[30003],rank[30003]; 3 int find(int x) 4 { 5 int r=x; 6 while(bin[r]!=r) 7 r=bin[r]; 8 return r; 9 }10 void merge(int x,int y)11 {12 int fx,fy;13 fx=find(x);14 fy=find(y);15 if(fx==fy)16 return;17 if(r... 阅读全文
posted @ 2013-08-02 09:17 海东青飞吧! 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 题目描述二叉排序树的定义是:或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值; 若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值; 它的左、右子树也分别为二叉排序树。 今天我们要判断两序列是否为同一二叉排序树输入开始一个数n,(1 2 #include 3 char a[10000],b[10000]; 4 void creat(char *x,char *y) 5 { 6 x[1]=y[0]; 7 int t=1; 8 for(int i=1;y[i];i++) 9 {10 ... 阅读全文
posted @ 2013-07-30 18:38 海东青飞吧! 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 题目描述请定一个无向图,顶点编号从0到n-1,用深度优先搜索(DFS),遍历并输出。遍历时,先遍历节点编号小的。输入输入第一行为整数n(0 2 #include 3 int p[101][101];//标记边 4 int o[101];//标记点 5 int num[101];//存遍历完的点 6 int z; 7 //dfs算法 8 void dfs(int k,int v) 9 {10 int j;11 o[v] = 1;12 num[z++] = v;13 for(j = 0;j <= k-1;j ++)14 {15 if(p[... 阅读全文
posted @ 2013-07-30 15:27 海东青飞吧! 阅读(272) 评论(0) 推荐(0) 编辑
摘要: 题目描述众人皆知,在编程领域中,C++是一门非常重要的语言,不仅仅因为其强大的功能,还因为它是很多其他面向对象语言的祖先和典范。不过这世上几乎没什么东西是完美的,C++也不例外,多继承结构在带来强大功能的同时也给软件设计和维护带来了很多困难。为此,在java语言中,只允许单继承结构,并采用接口来模拟多继承。KK最近获得了一份java编写的迷你游戏的源代码,他对这份代码非常感兴趣。这份java代码是由n个类组成的(本题不考虑接口),现在,他想要知道这份代码中有多少个类没有直接基类。n个类分别用数字1..n表示。输入输入数据包含多组,每组数据格式如下。第一行包含两个整数n,m,表示该份代码中的n个 阅读全文
posted @ 2013-07-30 14:54 海东青飞吧! 阅读(487) 评论(0) 推荐(0) 编辑
摘要: 题目描述refresh最近发了一笔横财,开了一家停车场。由于土地有限,停车场内停车数量有限,但是要求进停车场的车辆过多。当停车场满时,要进入的车辆会进入便道等待,最先进入便道的车辆会优先进入停车场,而且停车场的结构要求只出去的车辆必须是停车场中最后进去的车辆。现告诉你停车场容量N以及命令数M,以及一些命令(Add num 表示车牌号为num的车辆要进入停车场或便道,Del 表示停车场中出去了一辆车,Out 表示便道最前面的车辆不再等待,放弃进入停车场)。假设便道内的车辆不超过1000000.输入首先输入N和M(0< n,m <200000),接下来输入M条命令。输出输入结束后,如果出现停车场内 阅读全文
posted @ 2013-07-30 14:40 海东青飞吧! 阅读(301) 评论(0) 推荐(0) 编辑
摘要: 题目描述Well, how do you feel about mobile phone? Your answer would probably be something like that "It's so convenient and benefits people a lot". However, If you ask Merlin this question on the New Year's Eve, he will definitely answer "What a trouble! I have to keep my fingers 阅读全文
posted @ 2013-07-30 10:35 海东青飞吧! 阅读(308) 评论(1) 推荐(0) 编辑
摘要: Catch That CowTime Limit:2000MSMemory Limit:65536KTotal Submissions:37622Accepted:11666DescriptionFarmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a pointN(0 ≤N≤ 100,000) on a number line and the cow is at a pointK(0 ≤K≤ 100,000) on the 阅读全文
posted @ 2013-07-30 10:03 海东青飞吧! 阅读(226) 评论(0) 推荐(0) 编辑
摘要: 题目描述给定一个无向连通图,顶点编号从0到n-1,用广度优先搜索(BFS)遍历,输出从某个顶点出发的遍历序列。(同一个结点的同层邻接点,节点编号小的优先遍历)输入输入第一行为整数n(0 2 #include 3 int map[110][110]; 4 int vis[110],que[110]; 5 int m,k,t,flag; 6 void bfs(int t) 7 { 8 int l=0,r=0,tt,j; 9 que[r++]=t;10 while(l<r)11 {12 tt=que[l++];13 if(flag==1... 阅读全文
posted @ 2013-07-30 08:48 海东青飞吧! 阅读(482) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2299 1 #include 2 int a[500005]; 3 long long count; 4 5 void merge(int first,int mid,int last) 6 { 7 int s1,s2,f1,f2,i,k,f[500005]; 8 s1=first; 9 s2=mid+1;10 f1=mid;11 f2=last;12 k=0;13 while(s1<=f1&&s2<=f2)14 {15 if(a[s1]<a[s2])16 ... 阅读全文
posted @ 2013-07-29 20:50 海东青飞吧! 阅读(160) 评论(0) 推荐(0) 编辑
摘要: Fence RepairTime Limit:2000MSMemory Limit:65536KTotal Submissions:19664Accepted:6237DescriptionFarmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needsN(1 ≤N≤ 20,000) planks of wood, each having some integer lengthLi(1 ≤Li≤ 50,000) uni 阅读全文
posted @ 2013-07-29 17:25 海东青飞吧! 阅读(225) 评论(0) 推荐(0) 编辑
摘要: DescriptionAccounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc.All what they remember is that MS Inc. posted a surplus or a deficit each month of 1999 and each month when MS Inc. posted surplus, the amount of surplus 阅读全文
posted @ 2013-07-29 15:12 海东青飞吧! 阅读(146) 评论(0) 推荐(0) 编辑
摘要: Language:Ubiquitous ReligionsTime Limit:5000MSMemory Limit:65536KTotal Submissions:20242Accepted:9938DescriptionThere are so many different religions in the world today that it is difficult to keep track of them all. You are interested in finding out how many different religions students in your uni 阅读全文
posted @ 2013-07-29 11:25 海东青飞吧! 阅读(229) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 #define N 255 4 int f[N][N]; 5 int main() 6 { 7 int i,j,n; 8 while(~scanf("%d",&n)) 9 {10 memset(f,0,sizeof(f));11 f[0][0]=1;12 f[1][0]=1;13 f[2][0]=3;14 if(n=0;i--)36 printf("%d",f[n][i]);37 printf(... 阅读全文
posted @ 2013-07-29 10:49 海东青飞吧! 阅读(247) 评论(0) 推荐(0) 编辑
摘要: A字符串扩展题目描述Tom有些时候为了记录的方便,常常将一些连续的字符用扩展符'-'简单表示。比如abcdefg可以简写为a-g,即用起始的字符和终止字符中间加上一个扩展符'-'来表示这个字符串。但是为了处理的方便,Tom又必须将这些我们简单记法扩展成原来的字符串。很明显要是人工来做的话必定很麻烦,Tom知道计算机可以帮助他完成这个任务,但是他却不会编程,这的确让他很上火。他知道今天是山东理工大学第三届ACM校赛的日子,届时来自全校的编程爱好者都会来参加比赛,他很兴奋,因为这个困惑他良久的问题终于要被解决了。给你一个含有扩展符'-'的字符串,你的 阅读全文
posted @ 2013-05-26 18:21 海东青飞吧! 阅读(325) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>int judge(int x){ int p[110],k,i,t,num; k=0; if(x<0) { x=-x; k=1; } num=1; while(x) { p[num++]=x%10; x=x/10; } t=0; for(i=1;i<num;i++) t=t*10+p[i]; if(k) return -t; else return t;}int main(){ int n,a,b,x,y,s1,s2; scanf("%d",&n); while(n--) { scanf("%d 阅读全文
posted @ 2013-05-23 11:17 海东青飞吧! 阅读(213) 评论(0) 推荐(0) 编辑
摘要: Problem DescriptionIgnatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.InputThe input contains several test cases. The first line of the input is a single integer T which is the number of test c 阅读全文
posted @ 2013-05-23 00:49 海东青飞吧! 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 123*123=: 1 2 3 1 2 3------------------------- 3 6 9 2 4 6 1 2 3-------------------------- 1 5 1 2 9 9=3*3;2=2*3+3*2%10;。。。。。。 1 #include<stdio.h> 2 #include<string.h> 3 #define N 50000 4 5 int main() 6 { 7 int n,m,i,j,leap,max; 8 int a[300],b[300],r[N]; 9 c... 阅读全文
posted @ 2013-05-10 20:30 海东青飞吧! 阅读(395) 评论(0) 推荐(0) 编辑
摘要: 今天,参加了腾讯马拉松比赛。看到第一题我就高兴了,大水题一个。然后没读完题,看了数据就开始做。可按照我的理解老是运行不出结果。我以为是我的输出格式错了,就在那改,终于改对了,交上WA.然后再改,一连4次WA。还有二十分钟的时候,我才决定好好看看题。仔细一读,果然是我理解错了,输出的是第几个裁判,我一直理解为输出平均分数。唉。。。。。。怪自己太大意了,还好最后A了。无论多么水的题,都不能大意,要好好读题,有时候一不小心就会错了。以后要继续努力,这次只是开始。我的路还长,加油。。。。。。 阅读全文
posted @ 2013-03-24 21:55 海东青飞吧! 阅读(225) 评论(0) 推荐(0) 编辑
摘要: http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2054&cid=1156 1 #include 2 #include 3 typedef struct node 4 { 5 int data; 6 struct node *rb; 7 struct node *zb; 8 }lb; 9 lb *creat(int n)10 {11 lb *head,*p,*tail;12 int i;13 head=(lb *)malloc(sizeof(lb));14 head->rb=NULL;1... 阅读全文
posted @ 2013-03-22 22:37 海东青飞吧! 阅读(168) 评论(0) 推荐(0) 编辑
摘要: http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2056&cid=1156 1 #include 2 #include 3 typedef struct node 4 { 5 int data; 6 struct node *next; 7 }lb; 8 lb *creat(int n) 9 {10 int i;11 lb *p,*head,*tail;12 p=(lb *)malloc(sizeof(lb));13 p->data=1;14 p->next=NULL;15 he... 阅读全文
posted @ 2013-03-20 19:30 海东青飞吧! 阅读(153) 评论(0) 推荐(0) 编辑
摘要: http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2279 1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 char st1[1002],st2[1002]; 6 int a[1000],b[1000],n1,n2,k,i,j,n,l; 7 scanf("%d%*c",&n); 8 for(l=1;l<=n;l++) 9 {10 scanf("%s %s&q 阅读全文
posted @ 2013-03-13 20:37 海东青飞吧! 阅读(154) 评论(0) 推荐(0) 编辑
摘要: http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2122 1 #include 2 #include 3 typedef struct node 4 { 5 int data; 6 struct node *next; 7 }lb; 8 lb *creat(int n) //建立逆序链表 9 { 10 int i; 11 lb *head,*p; 12 head=(lb*)malloc(sizeof(lb)); 13 ... 阅读全文
posted @ 2013-03-11 20:37 海东青飞吧! 阅读(232) 评论(0) 推荐(0) 编辑
摘要: http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1464 1 #include 2 #include 3 typedef struct node 4 { 5 int data; 6 struct node *next; 7 }lb; 8 lb *creat(int m)//建顺序表 9 {10 int i;11 lb *head,*tail,*p;12 head=(lb*)malloc(sizeof(lb));//申请空间,开辟结点13 head->ne... 阅读全文
posted @ 2013-03-11 20:32 海东青飞吧! 阅读(157) 评论(0) 推荐(0) 编辑