• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ rank函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中rank函数的典型用法代码示例。如果您正苦于以下问题:C++ rank函数的具体用法?C++ rank怎么用?C++ rank使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了rank函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

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;
}
开发者ID:chamini2,项目名称:rubiks_cube,代码行数:42,代码来源:test9.cpp


示例2: numIslands2

    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;
    }
开发者ID:HaochenLiu,项目名称:My-LeetCode-CPP,代码行数:42,代码来源:305-2.cpp


示例3: SchreyerOrder

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;
}
开发者ID:ChristineJost,项目名称:M2,代码行数:20,代码来源:schorder.cpp


示例4: ERROR

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;
}
开发者ID:doughdemon,项目名称:M2,代码行数:20,代码来源:freemod.cpp


示例5: numIslands2

 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;
 }
开发者ID:hsiangkuotang,项目名称:LeetCode,代码行数:41,代码来源:305.cpp


示例6: btwEncode

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;
}
开发者ID:sunset1995,项目名称:ACM_ICPC_codebook,代码行数:21,代码来源:String_BWT.cpp


示例7: identifier

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
}
开发者ID:m-ahsan-nazer,项目名称:SeisSol,代码行数:21,代码来源:Fault.cpp


示例8: childLZTrie

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
   }
开发者ID:peper,项目名称:pizza,代码行数:21,代码来源:lztrie.c


示例9: from

/*
 *  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;
}
开发者ID:kervinck,项目名称:floyd,代码行数:19,代码来源:format.c


示例10: staff

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");
}
开发者ID:dylanyaga,项目名称:openMerc,代码行数:40,代码来源:info.c


示例11: main

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;
}
开发者ID:AlanYume,项目名称:ACM-ICPC,代码行数:22,代码来源:happybirthday.cpp


示例12: TEST

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]);
}
开发者ID:bonventre,项目名称:sxmc,代码行数:39,代码来源:test_hdf5.cpp


示例13: NOTE

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;
}
开发者ID:spito,项目名称:dp,代码行数:39,代码来源:daemon.cpp


示例14: invoke

   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());
   }
开发者ID:JaksaVucicevic,项目名称:triqs,代码行数:22,代码来源:mpi.hpp


示例15: rank_call

/* 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;
		
} 
开发者ID:werew,项目名称:minicas,代码行数:23,代码来源:mod_matrix.c


示例16: createLZTrie

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;
 }
开发者ID:peper,项目名称:pizza,代码行数:22,代码来源:lztrie.c


示例17: main

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;
}
开发者ID:samwgoldman,项目名称:rank_permutations,代码行数:39,代码来源:rank.c


示例18: dbTableName

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;
}
开发者ID:Cpppro,项目名称:acquaman,代码行数:38,代码来源:AMExternalScanDataSourceAB.cpp


示例19: loadLZTrie

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;
   }
开发者ID:peper,项目名称:pizza,代码行数:38,代码来源:lztrie.c


示例20: main

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";
*/
                                                                                //

}
开发者ID:CCJY,项目名称:coliru,代码行数:38,代码来源:main.cpp



注:本文中的rank函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ raptor_free_iostream函数代码示例发布时间:2022-05-30
下一篇:
C++ rangelim函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap