Here is my implementation ;)

#include <iostream>
#include <cstring>
using namespace std;

int balls[91]; //maximum balls
int N;

//verify if its impossible to call out every number from 0 to N
bool impossible(){
   int i,j;
   if(!balls[0])return true; //if ball 0 was removed
                             //its impossible to call 0
   for(i=1;i<=N;++i){ //search all balls from 1 to N
       if(!balls[i]){ //if theres no ball i
           for(j=0;j<=N-i;++j){ //Search a difference that results i
               //if there are 2 balls which their difference is i
               //number i can be called
               if(balls[j+i]&&balls[j])break; //j+i-j =
i                                             //
           }
           //ball i cant be called
           if(j==N-i+1)return true;
       }
   }
   return false; //can be called all numbers from 0 to N
}

int main() {
   int B,i,cb;
   while(cin>>N>>B,N,B) {
       memset(balls,0,sizeof(balls));
       for(i=0;i<B;++i){ //puts 1 -> removed balls
           cin>>cb;
           balls[cb]=1;
       }
       if(impossible()) cout<<"N";
       else cout<<"Y";
       cout<<endl;
   }
   return 0;
}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to