@rgap i think u have misunderstood the question u are solving for old version of game it says solve for new version specified in 2nd paragraph but not a big problem, can be done with slight modifications as input is small, just generate all B^2 possibilities and keep track of absolute differences generated if all differences are generated return true else return false
On Tue, Jan 25, 2011 at 1:47 AM, rgap <[email protected]> wrote: > 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]<algogeeks%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- 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.
