12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #include <iostream>
- #include <stdlib.h>
-
- using namespace std ;
-
- void printArray(int *array, int size){
- for(int i = 0; i < size; i++){
- cout << array[i] << " " ;
- }
-
- }
-
- bool is3DSonar1D(int *array, int *hash, int iter_id, int p, int n){
- int *hash = NULL ;
- int p2 = p*p ;
- int dif ;
- for (int h1 = 0; h1 < p; h1++){
- for(int h2 = 0; h2 < p; h2++){
- if(h1 == 0 && h2 == 0)
- continue ;
- //printArray(hash, p2) ;cout << endl ;
- for(int i = 0; i < p; i++){
- if(p*i > n-1)
- break ;
- for(int j = 0; j < p; j++){
- if(i == 0 && j == 0)
- continue ;
- if((i+h1) % p == 0 && (j+h2) % p == 0)
- continue ;
- if(p*i+j > n-1)
- break;
- if( p * ((i + h1) % p) + ((j+h2) % p) > n - 1)
- continue ;
- dif = (array[ p *((i + h1) % p) + ((j+h2) % p)] - array[p*i+j]);
- //cout <<i<< j<< h1 << h2 << "dif" <<dif<<endl ;
- if(dif < 0)
- dif = p2 + dif;
- else
- dif = dif % p2;
- if (hash[dif] ==1){
- // printArray(hash, p2) ;cout << endl ;
- return false ;
- }
- else
- hash[dif]=1 ;
- }
- }
- }
- }
- return true ;
- }
-
- int main(int argc, char **argv){
-
- int start, end, p, n ;
- p = 3 ;
- int counter = 0 ;
- bool sonar = false ;
- start = 3;
- end = 3;
- n = p*p ;
- int *array = new int[n];
- int *hash = (int *) calloc(p2, sizeof(int)) ;
-
- for(int i = 0; i < n; i++)
- array[i] = -1 ;
-
- array[1] = 0;
- array[2] = atoi(argv[1]) ;
- while(end >= start){
- counter++ ;
- sonar = false ;
- if(array[end] + 1 > n-1){
- array[end] = -1;
- end-- ;
- continue ;
- }
- array[end]++;
- if(counter % 2000 == 0){
- cout << "Check Point: " ; printArray(array, end+1); cout << endl;
- counter = 0;
- }
- if (is3DSonar1D(array, p, end+1)){
- //cout <<"Costas";printArray(array, end+1) ; cout <<endl ;
- sonar = true ;
- if(end+1 == n){
- cout <<"Sonar:";printArray(array, end+1);cout << endl;
- }
- }
- if(sonar && end < (n-1)){
- end++ ;
- }
-
- }
-
- return 0 ;
- }
|