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

晕死用Gcc就能A ,用C就Runtime Error,,帮我看一下是什么原因呢,找了半天找不出来

Posted by jiangwuqwe at 2010-06-04 20:24:31 on Problem 1321
#include <stdio.h>

#define MAXN 10
#define inf 0x7fff
int board[MAXN][MAXN];
int n,k;

int getcnum()
{
	int c=0;
	int col[MAXN]={0},row[MAXN]={0};
	int h=0,w=0,i=0,t=0;
	col[0] = -1;
	do 
	{
		w = col[h];
		w++;
		if(w>n||h>=n)
		{
			col[h--] = -1;
			if(col[h]!=n)
			{
				t--;
				row[col[h]] = 0;
			}
			continue;
		}
		//找到下一个可放位置或着不放、、col[h] == n 代表不放
		while(w!=n&&(board[h][w]==inf||row[w]==1))w++;
		//可以放置
		col[h++] = w;
		col[h] = -1;
		if(w!=n){
			row[w] = 1;
			t++;
		}
		if(t==k)//成功放置一组
		{
			c++;
			row[col[--h]] = 0;
			t--;
		}
	} while(h!=-1);
	return c;
}

int main()
{
	int i,j;
	char ch;
	while (1)
	{
		scanf("%d%d%*c",&n,&k);
		if(n==-1)break;
		for(i=0;i<n;i++)
		{
			for (j=0;j<n;j++)
			{
				scanf("%c",&ch);
				if(ch == '.')board[i][j] = inf;
				else board[i][j] = 0;
			}
			scanf("%*c");
		}
		printf("%d\n",getcnum());
	}
	return 0;
}

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