zoj 1091 Knight Moves

摘要: /*中午又熬了,做出来了,还值得小高兴一下,呵呵我的第一道宽度优先搜索注意横纵坐标及从'a''1'开始的吧感觉是个好题不过不会c++很吃力啊*/#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>int dir[8][2] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{1,-2},{-1,2},{-1,-2}};int flag[8][8];struct node{ int x,y,step;}q[1 阅读全文
posted @ 2011-08-21 14:57 java课程设计例子 阅读(135) 评论(0) 推荐(0) 编辑

zoj 1005 Jugs

摘要: 本来以为今天中午这题不会写出来了,不过幸运AC了;先说一下,我知道这题好的方法是用搜索DFS(BFS貌似不爽吧);不过我还不会用DFS,确切说是不敢用没有大胆尝试,DFS,一定要试着写一写;说一下我的原理吧:小杯子往大杯子里pour,只要小杯子能装下,大的一定也能,所以我只让小的pour大的,并且只检验大的杯子里的数是否是目标值(应该迟早能达到目标值,只不过这种做法不是最优解而已);还有,分别用x,y来表示小大杯子里的实际水量很有助于理解哦#include<stdio.h>#include<stdlib.h>#include<string.h>#includ 阅读全文
posted @ 2011-08-19 13:52 java课程设计例子 阅读(152) 评论(0) 推荐(0) 编辑

zoj 1914 Arctic Network

摘要: 找最小生成树的倒数第几长边的问题1,读入数据的处理,最终处理为结构体形式2,快排................................3,并查集找结点,并记录边长大小4,输出所求数据#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>typedef struct Tedge{ int from,to; int dist;}edge;edge dis[500*500]; //记录from点到to点的距离int ans[500+10]; //记录距离in. 阅读全文
posted @ 2011-08-19 10:15 java课程设计例子 阅读(116) 评论(0) 推荐(0) 编辑

zoj 1789 The Suspects

摘要: 这道题是并查集的题,写过这道题之后,我明白了一点,就是从根上改变所属father域#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>int p[30000+100];int a[30000+100];int find(int x){ if(p[x] == x) return x; p[x] = find(p[x]); return p[x];}int main(){ int n,m,k,i,count,temp; while(scanf("%d%d& 阅读全文
posted @ 2011-08-19 10:11 java课程设计例子 阅读(151) 评论(0) 推荐(0) 编辑

nyoj 44 子串和

摘要: 这道题竟然纠结了我好长时间,先是,我尝试了n多变量,WA的很无语当然我知道那是因为我的原理不正确,有的情况没有考虑;后来才用的下边的方法,简单易行,不过数组开得有点小虾仁,这个题使我不敢再小嘘任何题#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#include<limits.h>#define maxn 1000000int a[maxn+10];int main(){ int t,n,i; scanf("%d",& 阅读全文
posted @ 2011-08-19 08:48 java课程设计例子 阅读(102) 评论(0) 推荐(0) 编辑

回文字符串 的添加问题

摘要: 我学识所限,见的东西较少,做这个回文字符串的最少添加问题时绞尽脑汁,加之当天似乎不太舒服那整的是相当头蒙的,一个错误的方法可以使你愈陷愈深,最后请教了一下其他人,得知:只用把字符串逆序,然后求其最大公共子序列,用字符串长度减去LCR值即可,至于为什么,我也不知道为何这样做,只知道这样做是对的,知识匮乏啊#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>char a[1000+10],b[1000+10];int max[1010][1010];int main 阅读全文
posted @ 2011-08-18 20:40 java课程设计例子 阅读(175) 评论(0) 推荐(0) 编辑

zoj 1889 Ones

摘要: 这道题开始看不懂题,英文学得不好,主要是当输入为9999时要输出36位的数,这个数很难保存到一个long long 型的变量中,所以考虑取模公式,还算是一道简单题吧,不过这上午半天就做了这一道题,难受#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>int main(){ int m,count; long long n; while(scanf("%d",&m)==1) { n = 1; count = 1; while(n % 阅读全文
posted @ 2011-08-18 11:26 java课程设计例子 阅读(114) 评论(0) 推荐(0) 编辑

zoj 2704 Brackets

摘要: 输出最长的配对序列,brackets—括号忘了当时怎么讨论的了,总之用栈来存储序列的对应的标号,标号差值与序列的长度相关,然后从small 到big输出,只知道当时很纠结#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#define maxn 100000char target[maxn+10];int stack[maxn+10];int top; //栈顶的元素的下标 void push(int x) //入栈 { s... 阅读全文
posted @ 2011-08-17 16:47 java课程设计例子 阅读(119) 评论(0) 推荐(0) 编辑

素数环问题

摘要: DFS,好像主要是对dfs的递归调用吧,自己也不太懂,总之,它很神奇,多看看代码吧#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>int n;int isp[100];int vis[100]; int A[100];int is_prime(int x) //判断一个数是否为素数(该数比较小,不会引起超时) { int i=1,k; for(i=2;i<=(k=(int)sqrt(x));i++) if(x % i == 0)break; if(i& 阅读全文
posted @ 2011-08-17 16:36 java课程设计例子 阅读(250) 评论(0) 推荐(0) 编辑

zoj 1406 Jungle Roads

摘要: 从A到F找到最短路即可,由于我不会用prim算法只能用ku...算法,幸好这道题没有让输出路路径,所以用ku...算法也行我通常都是这样写的1.把边存起来2.快排3.并查集呵呵,过了,还行吧,对了输入注意用scanf中的%d前加一个空格#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> typedef struct Tedge { int from,to; int dist; }edge; edge dis[100]; int N; int fa[30] 阅读全文
posted @ 2011-08-17 16:08 java课程设计例子 阅读(136) 评论(0) 推荐(0) 编辑