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

求助 为何WA...

Posted by finalspace at 2006-08-26 13:15:51 on Problem 1745
同余,但总WA,请高手指点.
我总怀疑是输入输出有问题...
#include<stdio.h>
#include<deque>
#include<string>
#include<math.h>
using namespace std;

struct node
{
	int mod,pos;
};

deque<node> que;

int f[102],num[10002];
int T,n,k;

void clean(void)
{
	memset(f,0,sizeof(f));
	memset(num,0,sizeof(num));
	que.clear();
}

int make(void)
{
	if ((n==1)&&(num[1]%k==0))
    	return 1;
	int temp,bignum;
	node p,q;
	q.mod=num[1]%k;
	q.pos=1;
	que.push_back(q);
	while(!que.empty())
	{
		p=*que.begin();
		if ((p.pos)==(n-1))
		{
			if (((p.mod+num[n])%k==0)||((p.mod-num[n])%k==0))
     			return 1;
		}
		else
		{
			bignum=p.mod+num[p.pos+1];
			temp=bignum%k;
			if (f[temp]==0)
			{
				f[temp]=1;
    		    q.mod=temp;
	    		q.pos=p.pos+1;
	    		que.push_back(q);
			}
			
			bignum=p.mod-num[p.pos+1];
			temp=bignum%k;
			if (f[temp]==0)
			{
				f[temp]=1;
    		    q.mod=temp;
	    		q.pos=p.pos+1;
	    		que.push_back(q);
			}
		}
		que.pop_front();
	}
	return 0;
}
			
void print(int Case)
{
	if (Case==1)
    	printf("Divisible\n");
    	else
		printf("Not divisible\n");
}

int main(void)
{
	int i;
	scanf("%d",&T);
	while((T--)>0)
	{
		clean();
		scanf("%d %d",&n,&k);
		for(i=1;i<=n;i++) 
	    	scanf("%d",num+i);
	    print(make());
	    if (T>0)
    		printf("\n");
	}
	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