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 |
狂汗....就因为一不小心把l写成了i,贡献了几次wa,以后还是得小心啊...#include <iostream> using namespace std; int main() { int a[100],n,k,i; for(i=0;i<100;i++) a[i]=0; cin >> n >> k; int temp; cin >> temp; a[(temp+(10000*k))%k]=1; for( i=2;i<=n;i++) { int b[100]; for(int j=0;j<100;j++) b[j]=0; cin >> temp; for(int l=0;l<k;l++)//新输入的数与上轮存在的余数进行加和减运算 { if(a[l]) //就是此处的l被我写成了i,最开始 { b[(l+temp+(k*10000))%k]=1; b[(l-temp+(k*10000))%k]=1; } } for(l=0;l<k;l++) a[l]=b[l];//某一轮输入结束后,所有存在的余数对应的a数组值取1,别的置0 } if(a[0])cout << "Divisible" << endl;//最后一轮输入结束后,看是否有余数为0,即能整除的结果 else cout << "Not divisible" << endl; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator