Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

帮你看代码是不可能的,只能定位一下re的错误位置

Posted by hawk at 2004-07-17 12:46:58 on Problem 1077
In Reply To:Re:一般来说数组越界,自己好好查查哪里下标可能越界 Posted by:bluepiano at 2004-07-17 10:12:26
下面我指出re的位置了,以后最好不要贴这么长的代码,没人帮你看的^_^
> 用深搜写的
> 用哈系表判重
> 如果有时间帮我看看好吗  我在zju上也交过无数次了 再不行只能放弃了……
> 谢了
> 
> #include <stdio.h>
> #include <stdlib.h>
> 
> const
>   int maxn = 30000;
>   int cmax [9][9] = {0, 1, 2, 1, 2, 3, 2, 3, 4,
> 		 1, 0, 1, 2, 1, 2, 3, 2, 3,
> 		 2, 1, 0, 3, 2, 1, 4, 3, 2,
> 		 1, 2, 3, 0, 1, 2, 1, 2, 3,
> 		 2, 1, 2, 1, 0, 1, 2, 1, 2,
> 		 3, 2, 1, 2, 1, 0, 3, 2, 1,
> 		 2, 3, 4, 1, 2, 3, 0, 1, 2,
> 		 3, 2, 3, 2, 1, 2, 1, 0, 1,
> 		 4, 3, 2, 3, 2, 1, 2, 1, 0};
> 
> struct point
> {
>   int value, step;
>   point *next;
> };
> 
> point * hx[maxn], * p, *ne, *te;
> 
> int result, i, j, k, l, n, pos, max, path[100], opath[100], num, ten[10] = {1,100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1};
> char c;
> 
> void search(int deep)
> {
>   if (num == 123456780)
>   {
>     max = deep;
>     for (i = 0; i < deep; i ++)
>       opath[i] = path[i];
>     return;
>   }
>   if (deep + 1 >= max) return;
>   int last, lpos;
> 
>   last = num; lpos = pos;
> 
>   i = num % maxn;
>   p = hx[i];
>   while (p->next != NULL)
~~~~~~~~~~~~就在这一句,p指向不该指的地方
>   {
>     if (p->next->value == num)
>     {
>       if (p->next->step <= deep) return;
> 	else {(p->next->step = deep);break;}
>     } else
>     if (p->next->value < num) break;
>     p = p->next;
> 
>   }
>   if (p->next == NULL)
>   {
>     ne = new(struct point);
>     ne-> next = p->next;
>     p -> next = ne;
>     ne-> value = num;
>     ne-> step = deep;
>   } else
>   if (p->next->value < num)
>   {
>     ne = new(struct point);
>     ne-> next = p->next;
>     p -> next = ne;
>     ne-> value = num;
>     ne-> step = deep;
>   }
> 
> 
> //d
>   if (pos < 7)
>   {
>     i = num / ten[pos] % 10;
>     j = num / ten[pos + 3] % 10;
>     num = num - i * ten[pos] - j * ten[pos + 3] + j * ten[pos] + i * ten[pos + 3];
>     pos = pos + 3;
> 
>     path[deep] = 4;
>     search(deep + 1);
>   }
> //u
>   pos = lpos;num = last;
>   if (pos > 3)
>   {
>     i = num / ten[pos] % 10;
>     j = num / ten[pos - 3] % 10;
>     num = num - i * ten[pos] - j * ten[pos - 3] + j * ten[pos] + i * ten[pos - 3];
>     pos = pos - 3;
> 
>     path[deep] = 1;
>     search(deep + 1);
>   }
> //r
>   pos = lpos;num = last;
>   if (pos % 3 != 0)
>   {
>     i = num / ten[pos] % 10;
>     j = num / ten[pos + 1] % 10;
>     num = num - i * ten[pos] - j * ten[pos + 1] + j * ten[pos] + i * ten[pos + 1];
>     pos = pos + 1;
> 
>     path[deep] = 2;
>     search(deep + 1);
>   }
> //l
>   pos = lpos;num = last;
>   if (pos % 3 != 1)
>   {
>     i = num / ten[pos] % 10;
>     j = num / ten[pos - 1] % 10;
>     num = num - i * ten[pos] - j * ten[pos - 1] + j * ten[pos] + i * ten[pos - 1];
>     pos = pos - 1;
> 
>     path[deep] = 3;
>     search(deep + 1);
>   }
> }
> 
> main()
> {
>   num = 0; max = 0;
>   for (i = 1; i <= 9; i ++)
>   {
>     scanf("%c", &c);
>     if (i != 9) scanf(" ");
>     if (c == 'x') {num = num * 10; pos = i;}else
>     {
>       num = num * 10 + c - 48;
>       max = max + cmax[i][c - 48];
>     }
>   }
>   for (i = 0; i < maxn; i ++)
>   {
>     hx[i] = new(struct point);
>     hx[i]->next = NULL;
>   }
> 
>   max = max + 30;
>   result = max;
>   search(0);
>   if (result == max) printf("unsolvable"); else
>   for (i = 0; i < max; i ++)
>     if (opath[i] == 1) printf("u"); else
>     if (opath[i] == 2) printf("r"); else
>     if (opath[i] == 3) printf("l"); else
>     if (opath[i] == 4) printf("d"); else
>   for (i = 0; i < maxn; i ++)
>   {
>     p = hx[i];
>     while (p != NULL)
>     {
>       ne = p->next;
>       free(p);
>       p = ne;
>     }
>   }
>   printf("\n");
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator