05 2012 档案
摘要:题目链接自己居然想了个很麻烦的办法。。。重复搜索了很多次,最后除以K!,果断超时。。。早该想到应该往下搜,就不会重复了,没改好啊,居然又WA几次。。。多亏了虎哥的提示。。。 1 #include <stdio.h> 2 #include <string.h> 3 int n,k; 4 long long num; 5 char p[10][10],h[10],l[10]; 6 void dfs(int x,int y,int step) 7 { 8 int i,j; 9 h[x] = 1;10 l[y] = 1;11 if(step == k)12 {1...
阅读全文
摘要:题目链接 很久很久以前就见过的,当时不会做,最近在搞DFS,做做吧。。。花时间好长,折腾了一下午,由于一个1打成了0,2Y。。。期间可耻的冲进DISCUSS查错,有时候DISCUSS也会误导人啊,里面说啥的也有,很多不靠谱的说法。。。还好,自己又检查了一遍代码,发现这个错误。。。把深搜的过程写复杂了,看discuss的时候看见有简单的表达方式。 由于把代码打出来后,发现行和列倒过来了,改一下输入就好。我把英文看做行,数字看做列,所以字典序应该是先上 再左。所以深搜的时候按这个顺序。每组数据注意多输出个空行。 1 #include <stdio.h> 2 #include <s
阅读全文
摘要:题目链接好裸,BFS。杭电多组。。2A。。 1 #include <stdio.h> 2 #include <string.h> 3 int p[100001],o[100001]; 4 int main() 5 { 6 int n,k,i,j,start=0,end=0,num=0; 7 while(scanf("%d%d",&n,&k)!=EOF) 8 { 9 memset(o,0,sizeof(o));10 start=0,end=0,num=0;11 p[start] = n;12 o[n] = 1...
阅读全文
摘要:题目链接无语+ 无奈 10+的错误,看不懂的题意,不懂为何会AC,为神马删了对O和0的判断就AC。。。真受不了。。。 1 #include <stdio.h> 2 #include <string.h> 3 int main() 4 { 5 int i,j,len,x,y; 6 char p[1000],o[1000]; 7 while(gets(p)) 8 { 9 x = y = 1;10 len = strlen(p);11 for(i = 0; i <= len-1; i ++)12 {13 ...
阅读全文
摘要:题目链接练习DFS,以前知道思路,枚举每个点翻或者不翻,可是不知道如何去表达。虎哥给提示了下,自己编出来很费劲啊。。。而且,判断边界的时候WA了好几次啊。。而且居然,跑的异常的慢。。。#include <stdio.h>#include <stdlib.h>#include <string.h>char p[5][5];int min;int judge()//判断函数{ int i,j,sum = 0; for(i = 0;i <= 3;i ++) for(j = 0;j <= 3;j ++) { if(p[i][j]=='b'
阅读全文
摘要:题目链接这个题应该有别的方法吧,DFS参考解题报告,开始的时候不太明白如何在搜过之后如何把状态回溯,看了解题报告后,看到后恍然大悟啊。。。只要加上一个语句就完成了。这个程序好慢啊,250ms,最近学习搜索,争取今天做出独立做出一个的DFS。 1 #include <stdio.h> 2 #include <string.h> 3 int p[21],o[21],k[40]; 4 int n; 5 void dfs(int num,int step) 6 { 7 int i; 8 p[step] = num ; 9 o[num] = 1;10 if(step ==...
阅读全文
摘要:题目链接难得的1A。想的时间有点长啊,精力集中不起来。思路:本来是开始把 a1 a2 a3... an 全部用题目中的表达式给表示出来,想着肯定会全部消去吧,结果。。。还剩下个an,然后,没啥想法了。。想想,试试规律吧。把n = 2 3 4 时候全部写出来了发现有规律啊。an 可以用a1和a0表示出来。。把an套到前一个推出来的公式去,然后,实现这个规律,又浪费一些时间。。。还好1A。 1 #include <stdio.h> 2 double c[5000]; 3 int main() 4 { 5 int i,j,t,m; 6 double a0,an,sum1,sum2,a..
阅读全文
摘要:题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2107裸DFS。 1 #include <stdio.h> 2 #include <string.h> 3 int p[101][101],o[101],num[101],z; 4 void dfs(int k,int v) 5 { 6 int i; 7 o[v] = 1; 8 num[z] = v; 9 z ++;10 for(i = 0;i <= k-1;i ++)11 {12 ...
阅读全文
摘要:题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2139 裸BFS。 1 #include <stdio.h> 2 #include <string.h> 3 int p[1001][1001],o[1001],k[1001]; 4 int bfs(int n) 5 { 6 int i,j,start,end,a,num = 1; 7 start = end = 0; 8 while(start <= end) 9 {10 a = 1;11 ...
阅读全文
摘要:题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2138 第一个搜索,我也不知道这到底是BFS还是DFS。。。。那个全局标记变量没有初始化,WA了一次。。。本来多么美好的一个开始就这样破坏了。。 1 #include <stdio.h> 2 #include <string.h> 3 int p[1001][1001],o[1001],z; 4 void dfs(int n,int x) 5 { 6 int i; 7 o[x] = 1; 8 if(x == 1
阅读全文
摘要:题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1435这个题做的好没状态。上几天刷的高精度都白刷了啊。。。首先代码除法和取余以前都做过,还要查看以前的代码,模板还打错。。DEBUG好久,然后由于这个破精度(还是看的队友的解题报告),错了好几次,开始数组RE一一次,忘记0的情况(高精度老问题),还要有那个破空格,终于6A。。。基本上这个题所有的trick我都踩了。 1 #include <stdio.h> 2
阅读全文
摘要:题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2137 后序遍历没啥好说的,递归就好,层次遍历有点BFS的感觉。 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 struct tree 5 { 6 char l; 7 struct tree *left,*right; 8 }; 9 struct tree *build(char *p,char *s,int n
阅读全文
摘要:题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2136 这个题看书+问学长.2A.#include <stdio.h>#include <string.h>#include <stdlib.h>int num=-1;char str[51];struct tree{ char lat; struct tree *left; struct tree *right;};struct tree *build()//建树{ struct tree *p;
阅读全文
摘要:题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2141 这个题听虎哥给讲的,开始自己想的时候老是以为BFS就必须得用递归,这个题的思路没有想象的那么复杂啊。#include<stdio.h>#include<string.h>int p[101][101],ans[101],o[101];int main(){ int a,b,c,d,i,j,k,m,n; scanf("%d",&a); while(a--) { memset(a
阅读全文
摘要:题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2129最裸的并查集。。模板代码,好久没打过了。#include<stdio.h>int p[1001];int find(int x){ int a=x; while(p[a]!=a) a=p[a]; return a;}void mermge(int x,int y){ int x1=find(x),y1=find(y); if(x1!=y1) p[x1]=y1;}int main(){ int...
阅读全文
摘要:坑爹的百度空间升级之后,成那个熊样了。。。所以,转战博客园。题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1291 给出先序遍历和中序遍历,求后序遍历。代码参考白书上的。。 思路:先序遍历中第一个肯定是根节点,找到在此节点在中序遍历的位置,则左边为左子树,右边为右子树。递归下去,用一个字符串,存下后序遍历的过程。#include<stdio.h>#include<string.h>void build(int n,char *s1,char *s2,char
阅读全文