| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
路过的大侠帮忙看我写了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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator