Пример #1
0
int main(int argc, char const *argv[]) {
    int *array = new int[12];
    int i;

    // array[0]  = 8;
    // array[1]  = 103;
    // array[2]  = 109;
    // array[3]  = 101;
    // array[4]  = 2;
    // array[5]  = 111;
    // array[6]  = 7;
    // array[7]  = 6;
    // array[8]  = 0;
    // array[9]  = 4;
    // array[10] = 5;
    // array[11] = 10;

    array[0]  = 4;
    array[1]  = 201;
    array[2]  = 7;
    array[3]  = 209;
    array[4]  = 208;
    array[5]  = 210;
    array[6]  = 202;
    array[7]  = 200;
    array[8]  = 5;
    array[9]  = 203;
    array[10] = 6;
    array[11] = 211;

    print_array(array, 12);

    i = rank(12, array, 6, 2);
    std::cout << "\n" << i << "\n";
    array = unrank(12, i, 6, 2);

    print_array(array, 12);
    std::cout << "\n";

    delete[] array;
    return 0;
}
Пример #2
0
    vector<int> numIslands2(int m, int n, vector<pair<int, int>>& positions) {
        vector<int> res;
        if(n == 0 || m == 0) return res;
        vector<int> father(n * m, -1);
        vector<int> rank(n * m, 0);
        int sz = positions.size();
        for(int i = 0; i < sz; i++) {
            int x = positions[i].first;
            int y = positions[i].second;
            int t = x * n + y;
            int ft = find(father, t);
            if(i == 0) {
                res.push_back(1);
                continue;
            }

            int cnt = res.back() + 1;
            for(int k = 0; k < 4; k++) {
                int nx = x + dx[k];
                int ny = y + dy[k];
                int nt = nx * n + ny;
                if(!inBound(nx, ny, m, n)) continue;
                if(father[nt] == -1) continue;
                ft = find(father, t);
                int fnt = find(father, nt);
                if(ft != fnt) {
                    cnt--;
                    if(rank[ft] < rank[fnt]) {
                        father[ft] = fnt;
                    } else if(rank[fnt] < rank[ft]) {
                        father[fnt] = ft;
                    } else {
                        father[ft] = fnt;
                        rank[fnt]++;
                    }
                }
            }
            res.push_back(cnt);
        }

        return res;
    }
Пример #3
0
void DefaultSpmdVectorSpace<Scalar>::initialize(
  const RCP<const Teuchos::Comm<Ordinal> > &comm
  ,const Ordinal localSubDim_in, const Ordinal globalDim
  )
{
#ifdef TEUCHOS_DEBUG
  TEUCHOS_TEST_FOR_EXCEPT( !( localSubDim_in >= 0 ) );
#endif
  comm_ = comm;
  localSubDim_ = localSubDim_in;
  if (!is_null(comm)) {
    numProc_ = size(*comm);
    procRank_ = rank(*comm);
  }
  else {
    numProc_ = 1;
    procRank_ = 0;
  }
  this->updateState(globalDim);
}
Пример #4
0
SchreyerOrder *SchreyerOrder::tensor(const SchreyerOrder *G) const
     // tensor product
{
  // Since this is called only from FreeModule::tensor,
  // we assume that 'this', 'G' have the same monoid 'M'.

  SchreyerOrder *result = new SchreyerOrder(M);
  int *base = M->make_one();

  int next = 0;
  for (int i=0; i<rank(); i++)
    for (int j=0; j<G->rank(); j++)
      {
        M->mult(base_monom(i), G->base_monom(j), base);
        result->append(next++, base);
      }

  M->remove(base);
  return result;
}
Пример #5
0
FreeModule *FreeModule::direct_sum(const FreeModule *G) const
// direct sum
{
    int i;
    if (get_ring() != G->get_ring())
    {
        ERROR("expected free modules over the same ring");
        return 0;
    }
    FreeModule *result = new_free();
    for (i=0; i<rank(); i++)
        result->append(degree(i));
    for (i=0; i<G->rank(); i++)
        result->append(G->degree(i));

    //  if (schreyer != NULL && G->schreyer != NULL)
    //    result->schreyer = schreyer->direct_sum(G->schreyer);

    return result;
}
Пример #6
0
 vector<int> numIslands2(int m, int n, vector<pair<int, int>>& positions) {
     vector<int> parents(m * n, -1);
     vector<int> rank(m * n, 0);
     unordered_set<int> isIsland;
     int count = 0;
     vector<int> res;
     int dx[4] = {1,0,-1,0};
     int dy[4] = {0,1,0,-1};
     for (int i = 0; i < positions.size(); i++) {
         count++;
         int cx = positions[i].first;
         int cy = positions[i].second;
         int cid = cx * n + cy;
         isIsland.insert(cid);
         int cp = find(cid, parents);
         for (int j = 0; j < 4; j++) {
             int nx = cx + dx[j];
             int ny = cy + dy[j];
             int nid = nx * n + ny;
             if (nx >= 0 && nx < m && ny >= 0 && ny < n && isIsland.count(nid) > 0) {
                 cp = find(cid, parents);
                 int np = find(nid, parents);
                 if (np != cp) {
                     count--;
                     if (rank[cp] < rank[np]) {
                         parents[cp] = np;
                     }
                     else if (rank[cp] > rank[np]) {
                         parents[np] = cp;
                     }
                     else {
                         parents[cp] = np;
                         rank[np]++;
                     }
                 }
             }
         }
         res.push_back(count);
     }
     return res;
 }
Пример #7
0
vector<int> btwEncode(const vector<int> &src) {
    // O(n*lgn*lgn). probably faster than O(n*lgn) version
    int len = src.size();
    vector<int> sa(len), rank(len);
    for(int i=0; i<len; ++i) rank[sa[i] = i] = src[i];
    for(int ll=1, cnt=0; cnt!=len; ll<<=1, cnt=rank[sa.back()]+1) {
        auto cmp = [&](const int l, const int r) {
            if( rank[l]!=rank[r] ) return rank[l] < rank[r];
            return rank[(l+ll)%len] < rank[(r+ll)%len];
        };
        sort(sa.begin(), sa.end(), cmp);
        vector<int> tmp = rank;
        tmp[sa[0]] = 0;
        for(int i=1; i<sa.size(); ++i)
            tmp[sa[i]] = tmp[sa[i-1]] + cmp(sa[i-1], sa[i]);
        rank = tmp;
    }
    vector<int> rst(len);
    for(int i=0; i<len; ++i) rst[i] = src[(sa[i]+len-1)%len];
    return rst;
}
Пример #8
0
void seissol::checkpoint::sionlib::Fault::write(int timestepFault) {  
#ifdef USE_SIONLIB
  if (numSides() == 0)
    return;
  int globalrank,numFiles;
  char fname[1023], *newfname=NULL; 
  sion_int32 fsblksize= utils::Env::get<sion_int32>("SEISSOL_CHECKPOINT_BLOCK_SIZE", 0);
  unsigned long lidentifier;
  lidentifier = identifier();
  m_gComm = comm(); m_lComm = m_gComm;
  globalrank = rank(); numFiles = 0; 
  setpos();
  checkErr(sion_fwrite(&lidentifier, sizeof(unsigned long),1,m_files[odd()]));
  checkErr(sion_fwrite(&timestepFault, sizeof(timestepFault),1,m_files[odd()]));
  for (int i = 0; i < NUM_VARIABLES; i++){
    checkErr(sion_fwrite(data(i),sizeof(real),this->numSides()*this->numBndGP(),m_files[odd()]));
  }
  flushCheckpoint(); 
  //  finalizeCheckpoint();  
#endif
}
Пример #9
0
trieNode childLZTrie (lztrie T, trieNode i, byte c)

   { trieNode j;
     byte tc;
#ifdef QUERYREPORT
     CALLS++;
#endif
     if (i == ROOT) return T->boost[c];
     j = i+1;
     while (!bitget1(T->data,j)) // there is a child here
	{ tc = T->letters[j-rank(T->pdata->bdata,j)];
		// shortcut for leftrankLZTrie: is a child by letter c?
	  if (tc > c) break;
	  if (tc == c) return j;
	  j = findclose(T->pdata,j)+1;
#ifdef QUERYREPORT
          JUMPS++;
#endif
	}
     return NULLT; // no child to go down by c
   }
Пример #10
0
/*
 *  Convert into UCI notation
 */
extern char *moveToUci(char moveString[maxMoveSize], int move)
{
        int from = from(move);
        int to   = to(move);

        *moveString++ = fileToChar(file(from));
        *moveString++ = rankToChar(rank(from));
        *moveString++ = fileToChar(file(to));
        *moveString++ = rankToChar(rank(to));
        if (((move & specialMoveFlag) && rank(from) == rank7 && rank(to) == rank8)
         || ((move & specialMoveFlag) && rank(from) == rank2 && rank(to) == rank1))
                *moveString++ = tolower(promotionPieceToChar[(move>>promotionBits)&3]);
        *moveString = '\0';

        return moveString;
}
Пример #11
0
static void staff(void)
{
	int n, shown = 0;

	printf("<b>Ye Staff</b><br><br>\n");

	printf("<table cellpadding=0 cellspacing=0 border=0>\n");
	printf("<tr><td>Name &nbsp; &nbsp;</td><td>Race &nbsp; &nbsp;</td><td>Rank &nbsp; &nbsp;</td><td>Active</td></tr>\n");
	printf("<tr><td colspan=4><hr></td></tr>");

	for (n = 1; n<MAXCHARS && shown<50; n++)
	{
		if (ch[n].used==USE_EMPTY)
		{
			continue;
		}
		if (!(ch[n].flags & (CF_PLAYER)))
		{
			continue;
		}
		if (ch[n].flags & CF_GOD)
		{
			continue;
		}
		if (!(ch[n].flags & CF_STAFF))
		{
			continue;
		}

		printf("<tr><td><a href=\"/cgi-bin/info.cgi?cn=%d\">%s</a> &nbsp; &nbsp; </td><td>%s &nbsp; &nbsp; </td><td>%s &nbsp; &nbsp; </td><td>%s</td></tr>\n",
		       n, ch[n].name, racename(ch[n].kindred), rank(ch[n].points_tot),
		       (ch[n].used==USE_ACTIVE && !(ch[n].flags & CF_INVISIBLE) ? "Yes" : "No"));
		shown++;
	}
	if (shown==0)
	{
		printf("<tr><td colspan=4>No staffers yet.</td></tr>\n");
	}
	printf("</table><br>\n");
}
Пример #12
0
int main(){
	init();
	initlist();
	long n=0,c,lukynumber,r,order;
	bool isboy;
	int people;
	while(getpresent(c,lukynumber,isboy)){
		++n;
		frcount[n]=c;
		insert(n);
		r=rank(c)+1;
		r+=lukynumber*(isboy?1:-1);
		if(r<0||r>=account)tell(-1);
		else{
			people=select(r);
			tell(people);
			remove(r);
			if(--frcount[people])insert(people);
		}
	}
	return 0;
}
Пример #13
0
TEST(HDF5IO, ReadWrite2D)
{
    const unsigned int rows = 3;
    const unsigned int cols = 4;
    const unsigned int nelements = rows * cols;

    std::vector<float> a(nelements);

    for (unsigned int irow=0; irow < rows; irow++)
        for (unsigned int icol=0; icol < cols; icol++)
            a[irow * cols + icol] = 2 * irow + icol;

    // 2D array
    std::vector<unsigned int> rank(2);
    rank[0] = rows;
    rank[1] = cols;

    std::string filename("/tmp/sxmc_test_2d.hdf5");
    std::string dataset("/a");

    ASSERT_TRUE(write_float_vector_hdf5(filename, dataset, a, rank) >= 0);

    ///////

    std::vector<float> test_a;
    std::vector<unsigned int> test_rank;

    ASSERT_TRUE(read_float_vector_hdf5(filename, dataset, test_a, test_rank) >= 0);

    ASSERT_EQ((unsigned) 2, test_rank.size());
    EXPECT_EQ(rows, test_rank[0]);
    EXPECT_EQ(cols, test_rank[1]);

    ASSERT_EQ(nelements, test_a.size());

    for (unsigned int irow=0; irow < test_rank[0]; irow++)
        for (unsigned int icol=0; icol < test_rank[1]; icol++)
            EXPECT_EQ(2 * irow + icol, a[irow * test_rank[1] + icol]);
}
Пример #14
0
void Daemon::enslave( InputMessage &message, Channel channel ) {
    NOTE();

    OutputMessage response( MessageType::Control );
    if ( _state != State::Free ) {
        response.tag( Code::Refuse );
        std::string description = status();
        response << description;

        channel->send( response );
        channel->close();
        return;
    }

    int i;
    std::string selfName;
    int openChannels;
    message >> i >> selfName >> openChannels;
    channel->receive( message );


    response.tag( Code::OK );
    channel->send( response );

    rank( i );
    name( selfName );
    channels( openChannels );

    std::string address( net().peerAddress( *channel ) );
    Line master = std::make_shared< Peer >(
        0,
        "master",
        address.c_str(),
        std::move( channel )
    );

    connections().lockedInsert( 0, std::move( master ) ); // zero for master
    _state = State::Enslaved;
}
Пример #15
0
   void invoke() {

    if (!has_contiguous_data(lhs)) TRIQS_RUNTIME_ERROR << "mpi scatter of array into a non contiguous view";

    resize_or_check_if_view(lhs, laz.domain().lengths());

    auto c = laz.c;
    auto slow_size = first_dim(laz.ref);
    auto slow_stride = laz.ref.indexmap().strides()[0];
    auto sendcounts = std::vector<int>(c.size());
    auto displs = std::vector<int>(c.size() + 1, 0);
    int recvcount = mpi::slice_length(slow_size - 1, c.size(), c.rank()) * slow_stride;
    auto D = mpi::mpi_datatype<typename A::value_type>();

    for (int r = 0; r < c.size(); ++r) {
     sendcounts[r] = mpi::slice_length(slow_size - 1, c.size(), r) * slow_stride;
     displs[r + 1] = sendcounts[r] + displs[r];
    }

    MPI_Scatterv((void *)laz.ref.data_start(), &sendcounts[0], &displs[0], D, (void *)lhs.data_start(), recvcount, D, laz.root,
                 c.get());
   }
Пример #16
0
/* Determinant of one matrix */
Ref rank_call(ref_list args){
	
	if (args->length != 1){
		set_err(ETYPE, "too many arguments");
		return NULL;	
	}
	
	if (arg_isMatrix(args->list[0]) == false) return NULL;
	
	Matrix m = CAST_REF2MATRIX(args->list[0]);

	float* d = malloc(sizeof (float));	
	if (d == NULL) return NULL;
	*d = rank(m);


	Ref r = new_vref(NULL, d, FLOAT);
	if (r == NULL) free(d);

	return r;
		
} 
Пример #17
0
lztrie createLZTrie(uint *string, byte *letters, uint *id, uint n)
 { 
    lztrie T;
    uint i;
    T          = malloc(sizeof(struct slztrie));
    T->data    = string;
    T->pdata   = createParentheses(string,2*n,true,true);
    T->n       = n;
    T->letters = letters;
    // creates the ids permutation
    T->ids     = createPerm(id, n, PARAMETER_T_IDS);
    // boost first access
    T->boost   = malloc(256*sizeof(trieNode));
    for (i=0;i<256;i++) T->boost[i] = NULLT;
    i = 1; // shortcut for first child of root
    while (i != 2*n-1) { // shortcut for its closing parenthesis
       T->boost[T->letters[i-rank(T->pdata->bdata,i)]] = i;
       // shortcut for leftrankLZTrie
       i = findclose(T->pdata,i)+1;
    }
    return T;
 }
Пример #18
0
int main(int argc, char* argv[])
{
  uint32_t n; // length of set
  uint32_t k; // length of permutation
  uint32_t* p; // input permutation (must be length k)
  uint64_t r; // rank
  
  if (argc < 2 || argc > 3)
  {
    printf("Usage: %s n <k>\n", argv[0]);
    return 1;
  }
  
  n = strtoul(argv[1], (char**)NULL, 10);
  
  if (argc == 3)
  {
    k = strtoul(argv[2], (char**)NULL, 10);
  }
  else
  {
    k = n;
  }
  
  if (k > n)
  {
    printf("Error: value of k must be less than or equal to n.\n");
    return 1;
  }
  
  p = read_permutation(k);
  
  r = rank(n, k, p);
  printf("%" PRIu64 "\n", r);
  
  free(p);
  
  return 0;
}
Пример #19
0
bool AMExternalScanDataSourceAB::loadFromDb(AMDatabase *db, int id)
{
	// if we're not inside the constructor, verify that we have the same rank as the stored version
	if(!insideConstructor_) {
		QVariant storedRank = db->retrieve(id, dbTableName(), "rank");
		if(!storedRank.isValid() || rank() != storedRank.toInt() ) {
			AMErrorMon::report(AMErrorReport(this, AMErrorReport::Serious, -1, "Not allowed to change the rank of an External Scan Data analysis block by re-loading it from the database."));
			return false;
		}
	}

	// load parameters from the db in the normal way.
	if(!AMStandardAnalysisBlock::loadFromDb(db, id))
		return false;

	AMDataSource::name_ = dbLoadOutputDataSourceName_;

	AMDatabase* sourceDb = AMDatabase::database(dbLoadConnectionName_);
	if(!sourceDb) {
		AMErrorMon::report(AMErrorReport(this, AMErrorReport::Serious, -2, "Couldn't locate the database containing the external scan data to load."));
		return false;
	}

	if(scan_) {	// don't want refreshData() to use an old scan object. This will ensure it loads a new one.
		scan_->release(this);
		scan_ = 0;
	}
	// from this point on, we've actually made permanent modifications to our parameters. Which means that we need to change the state to invalid if anything goes wrong from here. This will be taken care of by refreshData().
	sourceDb_ = sourceDb;
	sourceScanId_ = dbLoadScanId_;
	sourceDataSourceName_ = dbLoadSourceDataSourceName_;

	if(!refreshData()) {
		return false;
	}

	return true;
}
Пример #20
0
lztrie loadLZTrie (FILE *f)

   { lztrie T;
     uint i;
     T = malloc (sizeof(struct slztrie));
     if (fread (&T->n,sizeof(uint),1,f) != 1)
	{ fprintf (stderr,"Error: Cannot read LZTrie from file\n");
	  exit(1);
	}
     T->data = malloc (((2*T->n+W-1)/W)*sizeof(uint));
     if (fread (T->data,sizeof(uint),(2*T->n+W-1)/W,f) != (2*T->n+W-1)/W)
	{ fprintf (stderr,"Error: Cannot read LZTrie from file\n");
	  exit(1);
	}
     T->pdata = createParentheses (T->data,2*T->n,true);
     T->nbits = bits(T->n-1);
     T->letters = malloc (T->n*sizeof(byte));
     if (fread (T->letters,sizeof(byte),T->n,f) != T->n)
	{ fprintf (stderr,"Error: Cannot read LZTrie from file\n");
	  exit(1);
	}
     T->id = malloc (((T->n*T->nbits+W-1)/W)*sizeof(uint));
     if (fread (T->id,sizeof(uint),(T->n*T->nbits+W-1)/W,f) != 
		 (T->n*T->nbits+W-1)/W)
	{ fprintf (stderr,"Error: Cannot read LZTrie from file\n");
	  exit(1);
	}
	// boost first access
     T->boost = malloc (256*sizeof(trieNode));
     for (i=0;i<256;i++) T->boost[i] = NULLT;
     i = 1; // shortcut for first child of root
     while (i != 2*T->n-1) // shortcut for its closing parenthesis
        { T->boost[T->letters[i-rank(T->pdata->bdata,i)]] = i;
                // shortcut for leftrankLZTrie
          i = findclose(T->pdata,i)+1;
        }
     return T;
   }
Пример #21
0
int main() {
    auto src = std::vector<int> { 6, 4, 4, 2, 2, 3, 3, 3, 3 };
    auto const N = src.size();
    
    auto ord = std::vector<int> {};
    ord.reserve(N);
    iota_n(std::back_inserter(ord), N, 0);
    
    auto rnk = std::vector<double> {};
    rnk.reserve(N);
    iota_n(std::back_inserter(rnk), N, 0.0);
  
    std::cout << "unsorted data \n\n";
    std::cout << "i --> s o r \n";
    std::cout << "=========== \n";
    for (std::size_t i = 0; i < N; ++i) 
        std::cout << i << " --> " << src[i] << " " << ord[i] << " " << rnk[i] << "\n";
  
    order(begin(src), end(src), begin(ord));
    rank(begin(src), end(src), begin(ord), begin(rnk));

    std::cout << "sorted data \n\n";
    std::cout << "i --> s o r \n";
    std::cout << "=========== \n";
    for (std::size_t i = 0; i < N; ++i) 
        std::cout << i << " --> " << src[i] << " " << ord[i] << " " << rnk[i] << "\n";


/*
    // show sorted indices and tie-adjusted ranks                                              //
    cout << "i --> v I R \n============= \n";
    for (size_t i=0; i<orig.size(); i++) 
      cout << i << " --> " << orig[i] << " " << idxs[i] << " " << rnks[i] << endl;
    cout << "i --> v I R\n";
*/
                                                                                //

}
vector<int> buildSuffixArray(const vector<int> &str, int endOfString=-1) {
    // sa: i -> start position of str
    // O(n*lgn*lgn). probably faster than O(n*lgn) version
    int len = str.size();
    vector<int> sa(len+1), rank(len+1);
    for(int i=0; i<len; ++i) rank[sa[i] = i] = str[i];
    rank[sa.back() = len] = endOfString;
    for(int ll=1, cnt=0; cnt!=len; ll<<=1, cnt=rank[sa.back()]) {
        auto cmp = [&](const int l, const int r) {
            if( rank[l]!=rank[r] ) return rank[l] < rank[r];
            int lv = (l+ll < len) ? rank[l+ll] : 0;
            int rv = (r+ll < len) ? rank[r+ll] : 0;
            return lv < rv;
        };
        sort(sa.begin(), sa.end(), cmp);
        vector<int> tmp = rank;
        tmp[sa[0]] = 0;
        for(int i=1; i<sa.size(); ++i)
            tmp[sa[i]] = tmp[sa[i-1]] + cmp(sa[i-1], sa[i]);
        rank = tmp;
    }
    return sa;
}
Пример #23
0
double PriceOptimizer::sales_model(double price, int t) {
  double _t = double(t) / T;
  double _rank = double(rank(price, competitor_prices)) / competitor_prices.size();
  std::vector<double> x = {
    1,
    double(_rank),
    price - *std::min_element(competitor_prices.begin(), competitor_prices.end()),
    price,
    double(_t),
    double(_t * _t),
    double(_t * _rank),
    std::sqrt(_t),
    double((1 - _t) * (1 - _t) * (1 - _t)),
    double(_t * (1 - _t) * (1 - _t)),
    double(_t * _t * (1 - _t)),
    double(_t * _t * _t),
    double((1 - _rank) * (1 - _rank) * (1 - _rank)),
    double(_rank * (1 - _rank) * (1 - _rank)),
    double(_rank * _rank * (1 - _rank)),
    double(_rank * _rank * _rank)
  };
  return predict_linear_regression(x, sales_model_coef);
}
Пример #24
0
bool AMDataSource::axisValues(int axisNumber, int startIndex, int endIndex, double *outputValues) const
{
    AMErrorMon::debug(0, AMDATASOURCE_AXISVALUES_BASE_IMPLEMENTATION_CALLED, QString("AMDataSource: Warning: Data source '%1' is using the base implementation of AMDataSource::axisValues(), which is very inefficient. Re-implement axisValues() to improve performance.  (This warning will only be given once.)").arg(name()));

    if (!isValid())
        return false;

    if (axisNumber >= rank())
        return false;

#ifdef AM_ENABLE_BOUNDS_CHECKING
    if (startIndex < 0 || startIndex >= size(axisNumber))
        return false;

    if (endIndex < 0 || endIndex >= size(axisNumber))
        return false;
#endif

    for (int i = 0, size = endIndex-startIndex+1; i < size; i++)
        outputValues[i] = double(axisValue(axisNumber, i+startIndex));

    return true;
}
Пример #25
0
main(){ //Principal
       system("color A");
       system("title Jogo da Velha");
       
       developers();clrscr();  //Apresentação do trabalho
       intr(); //Mostra a animação 
int op,ani;
while(1){ //Loop infinito até o jogado escolher sair
vlgx=0;vlgy=0,emp=0,beginJg=0;
       op=menu(); // Chama a função menu que retornará a opção escolhida pelo usuário.  
       clrscr();  
       if(op==0){game();} //Se opção for igual a 0 entra no jogo
             if(op==1){rank();} //Se opção for igual a 1 entra no ranking
                if(op==2){config();}//Se opção for igual a 2 entra em configuração
                     if(op==3){ //Se opção for igual a 3 então mostra uma pequena animação e fecha o jogo.
                               
                       for(ani=0;ani<25;ani++){        
                        gotoxy(35,1+ani);       
                        printf("Finish the game!");Sleep(100);clrscr();}
                               return 0;}
                     }
       system("pause>>null");  
}
Пример #26
0
void
exec(const char* fn, const void* buf, size_t n)
{
  (void)fn;
  if(n == dims[0]*dims[1]*dims[2]*sizeof(float)) {
    float rng[2];
    range((const float*)buf, n/sizeof(float), &rng[0], &rng[1]);
    TRACE(nek, "[%zu] range: [%14.7g %14.7g]", rank(), rng[0], rng[1]);

    if(quant == NULL) {
      quant = calloc(dims[0]*dims[1]*dims[2], sizeof(uint16_t));
    }
    if(fld != 4) { /* 4 is always blank, it seems. */
      memset(quant, 0, dims[0]*dims[1]*dims[2]*sizeof(uint16_t));
      quantize((const float*)buf, n/sizeof(float), rng[0], rng[1], quant);
      char fname[256];
      snprintf(fname, 256, "%zu.fld%zu.png", ts, fld);
      writepng(fname, quant, dims[0], dims[1]);
    }

    next_field();
  }
}
Пример #27
0
FreeModule *FreeModule::tensor(const FreeModule *G) const
// tensor product
{
    if (get_ring() != G->get_ring())
    {
        ERROR("expected free modules over the same ring");
        return 0;
    }
    FreeModule *result = new_free();
    int *deg = degree_monoid()->make_one();

    for (int i=0; i<rank(); i++)
        for (int j=0; j<G->rank(); j++)
        {
            degree_monoid()->mult(degree(i), G->degree(j), deg);
            result->append(deg);
        }

    degree_monoid()->remove(deg);
    if (schreyer != NULL && G->schreyer != NULL)
        result->schreyer = schreyer->tensor(G->schreyer);
    return result;
}
int main()
{
    std::vector<Element> elements;
    elements.reserve(30);
    for (size_t i = 0; i < elements.capacity(); ++i)
    {
        elements.push_back(Element(rand() % 90));
    }

    for (size_t i = 0; i < elements.size(); ++i)
    {
        elements[i].dsID = i;
    }

    Rank rank(elements);
    Parent parent(elements);

    boost::disjoint_sets<Rank*, Parent*> sets(&rank, &parent);

    for (size_t i = 0; i < elements.size(); ++i)
    {
        sets.make_set(elements.at(i));
    }

    for (size_t i = 0; i < elements.size(); ++i)
    {
        // Union between this element and one randomly chosen from the rest
        size_t j = rand() % elements.size();
        sets.union_set(elements[i], elements[j]);
    }

    std::cout << "Found " << sets.count_sets(elements.begin(), elements.end()) << " sets:" << std::endl;

    sets.compress_sets(elements.begin(), elements.end());

    std::cout << std::endl << "After path compression:" << std::endl;
}
Пример #29
0
lztrie createLZTrie (uint *string, byte *letters, uint *id, uint n)

   { lztrie T;
     uint i;
     T = malloc (sizeof(struct slztrie));
     T->data = string;
     T->pdata = createParentheses (string,2*n,true);
     T->n = n;
     T->nbits = bits(n-1);
     T->letters = letters;
     T->id = malloc (((n*T->nbits+W-1)/W)*sizeof(uint));
     for (i=0;i<n;i++)
	bitput (T->id,i*T->nbits,T->nbits,id[i]);
	// boost first access
     T->boost = malloc (256*sizeof(trieNode));
     for (i=0;i<256;i++) T->boost[i] = NULLT;
     i = 1; // shortcut for first child of root
     while (i != 2*n-1) // shortcut for its closing parenthesis
        { T->boost[T->letters[i-rank(T->pdata->bdata,i)]] = i;
                // shortcut for leftrankLZTrie
          i = findclose(T->pdata,i)+1;
        }
     return T;
   }
Пример #30
0
// Devolve o enteiro do texto que ocupa a posicion dada, e fixa o estado 
// para poder seguir obtendo os seguintes enteiros con displayNext();
uint displayCSAFirst(ticsa *myicsa, uint position) {

	register uint positionAux, index;
	register uint T_AInv = myicsa->T_AInv;
	
	positionAux = myicsa->samplesAInv[position / T_AInv];
	for(index = 0; index < position%T_AInv; index++) {
		#ifdef PSI_HUFFMANRLE
			positionAux=getHuffmanPsiValue(&(myicsa->hcPsi),positionAux);
		#endif			 
		#ifdef PSI_GONZALO
			positionAux=getGonzaloPsiValue(&(myicsa->gcPsi),positionAux);
		#endif
		#ifdef PSI_DELTACODES
			positionAux=getDeltaPsiValue(&(myicsa->dcPsi),positionAux);
		#endif		
	}
	
	// Fijamos a variable global para a chamada a displayNext
	myicsa->displayCSAState = positionAux;
	
	//	return rank1(D, Dir, positionAux) - 1;
	return rank(myicsa->bD, positionAux) - 1;
}