摘要: 改了很久还是超时,没有办法做dfs,我喜欢定义一些全局变量,其实这样在应用dfs()时,会导致一些不必要的赋值,变之前,要改动,变后还得恢复现场,这就很容易出错了从人家的代码,while(sticks[i]==sticks[i+1])i++;这一句可以节省时间,当然这是单单这道题目而言的,而且我一开始是打算每次调用dfs时都检查一下是否所有的set都是1,即都是应用过的,结果看了他的代码发现,其实可以用一个变量s来记录已经结合了多少段,毕竟当每段的长度选好了,总的段数是固定的这是人家的正确代码,解答得很详细了#include #include #include #include using n 阅读全文
posted @ 2013-10-29 15:13 龙城星 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 做的过程有个疑问,要不要建一个4倍于原来价格的数组,其中前四个相同等于第一个原来的价格,后来发现这样会导致tie,所有就放弃这种做法,后面用了一个for(j)循环搞定了 for(i=a+1;ibestlei){bestlei=tem;return 0;} else if(tem==bestlei){return 1;} else return 2;}void chang(int a){ int i; x=a; for(i=1;iy)return; if(step>4)return; if(sum==y){ int tem=check(); if(tem==0){ ... 阅读全文
posted @ 2013-10-28 15:46 龙城星 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 广搜省时在这道题目就明显得看出来而且不一定要走全,但是一定要走到最后那个点我的代码超时#include "iostream"#include "string.h"#include "algorithm"using namespace std;struct{ int a,b,l,t,pre;}edge[10010];int f[120],next[120],longth,MIN,k,m,n,num;void add(int a,int b,int l,int t){ edge[num].b=b; edge[num].l=l; edge[ 阅读全文
posted @ 2013-10-11 21:34 龙城星 阅读(206) 评论(0) 推荐(0) 编辑
摘要: 看了人家的代码才知道的不知道为什么?就是每个城市最多经过4次(网上说的“闸数”)就可以跳出循环了————这个是人家说的,我也不懂仔细想了想,难道是因为超过4次的话,他就有可能超时,这样解释的话,不是大家在钻空子吗???#include "iostream"#include "string.h"using namespace std;struct{ int b,c,p,r,pre;}edge[120];int next[120],f[120],m,n,MIN,num;void add(int a,int b,int c,int p,int r){ edge 阅读全文
posted @ 2013-10-11 19:38 龙城星 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 超时了啊我的代码#include "iostream"#include "string.h"#include "algorithm"using namespace std;char dir[4]={'C','G','A','T'};int set[110],MIN,end,n;char aim[110],map[110][6];int min(int a,int b){return a>b?b:a;}void dfs(int a){ int flag=0,i,j; 阅读全文
posted @ 2013-10-11 13:32 龙城星 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 我的错误代码#include "iostream"#include "math.h"#include "algorithm"#define N 100000;using namespace std;int total,list[1000],n,m,MIN,top,step,data[1000];void dfs(int a){ int i,j,num; if(total>m)return; if(m-total>m>>n&&m&&n){ top=1;step=1; while(n 阅读全文
posted @ 2013-10-02 20:12 龙城星 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 我的代码是错的,第一次是超时,后来看了人家的代码,才知道原来可以用一个数组来节省时间我的错误的代码原因:搜索比n小的数字,此时为了搜索到的解 m 是最小的,应该从区间[0,s]的第s位开始向第0位搜索,因为在相同 pnum 情况下,把高位数字变小所得到的 m 值更小。我的错误代码#include "iostream"#include "math.h"#include "algorithm"#include "string.h"#define N 10000000;using namespace std;int to 阅读全文
posted @ 2013-10-02 20:09 龙城星 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 这道题看了人家的题解的,不过中心思想跟人家不一样我的ACCEPT代码#include "iostream"#include "algorithm"#include "string.h"using namespace std;int set[120],map[120][120],MAX,n,top;int count(){ int total=0,i,j; for(i=1;i>n; for(i=1;i>map[i][j]; } } memset(set,0,sizeof(set)); MAX=0; dfs(0); coutu 阅读全文
posted @ 2013-10-01 16:35 龙城星 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 虽然数据通过了,但是超时这是一定的,那么多循环,发现一个规律,用数组可以省时间,而且少错误我的代码——超时#include "iostream"#include "string.h"#include "algorithm"using namespace std;int map[10][10];int dir[9][2]={{1,1},{1,4},{1,7},{4,1},{4,4},{4,7},{7,1},{7,4},{7,7}};bool chang(){ int set[10],set1[10],set2[10],i,j; mems 阅读全文
posted @ 2013-10-01 14:31 龙城星 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 怎么今天都是compile error 呢,奇怪啊我的代码#include "iostream"#include "string.h"#include "queue"#include "math.h"#include "algorithm"using namespace std;struct Point{ char list[5]; int step;};int chang(char list[5]){ int i,total=0; for(i=0;i=0;i--){ list[i]=' 阅读全文
posted @ 2013-09-30 18:54 龙城星 阅读(241) 评论(0) 推荐(0) 编辑