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

路过的大侠帮忙看

Posted by xmm1989218 at 2010-01-02 21:53:05 on Problem 1745
我写了2个滑动数组的代码一个如下(WA了):
#include<stdio.h>
#include<string.h>
bool last[110];
bool now[110];
int main()
{
	int N,K,i,j;
	int tmp,tmp1,tmp2;
	bool *plast,*pnow,*ptmp;
	while(scanf("%d %d",&N,&K)!=EOF)
	{
		plast=last,pnow=now;
		memset(pnow,0,sizeof(pnow));
		scanf("%d",&tmp);
		while(tmp<0)	tmp+=K;
		pnow[tmp%K]=true;
		for(i=1;i<N;i++)
		{
			scanf("%d",&tmp);

			ptmp=pnow;pnow=plast;plast=ptmp;
			memset(pnow,0,sizeof(pnow));
			//for(j=0;j<K;j++)
			//	pnow[j]=false;
			tmp1=-tmp;
			while(tmp1<0)	tmp1+=K;
			tmp1=tmp1%K;
			tmp2=tmp;
			while(tmp2<0)	tmp2+=K;
			tmp2=tmp2%K;

			for(j=0;j<K;j++)
			{
				if(plast[j]==true)
				{
					pnow[(tmp1+j)%K]=true;
					pnow[(tmp2+j)%K]=true;
				}
			}
		}
		if(pnow[0]==false)
			printf("Not divisible\n");
		else
			printf("Divisible\n");
	}
	return 0;
}

另一个是(AC的)
#include<stdio.h>
#include<string.h>
bool last[110];
bool now[110];
int main()
{
	int N,K,i,j;
	int tmp,tmp1,tmp2;
	bool *plast,*pnow,*ptmp;
	while(scanf("%d %d",&N,&K)!=EOF)
	{
		plast=last,pnow=now;
		memset(pnow,0,sizeof(pnow));
		scanf("%d",&tmp);
		while(tmp<0)	tmp+=K;
		pnow[tmp%K]=true;
		for(i=1;i<N;i++)
		{
			scanf("%d",&tmp);

			ptmp=pnow;pnow=plast;plast=ptmp;
			//memset(pnow,0,sizeof(pnow));
			for(j=0;j<K;j++)
				pnow[j]=false;
			tmp1=-tmp;
			while(tmp1<0)	tmp1+=K;
			tmp1=tmp1%K;
			tmp2=tmp;
			while(tmp2<0)	tmp2+=K;
			tmp2=tmp2%K;

			for(j=0;j<K;j++)
			{
				if(plast[j]==true)
				{
					pnow[(tmp1+j)%K]=true;
					pnow[(tmp2+j)%K]=true;
				}
			}
		}
		if(pnow[0]==false)
			printf("Not divisible\n");
		else
			printf("Divisible\n");
	}
	return 0;
}

区别仅仅是注释的哪里 为什么一个AC一个WA 求帮忙

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