本文整理汇总了C++中rank函数的典型用法代码示例。如果您正苦于以下问题:C++ rank函数的具体用法?C++ rank怎么用?C++ rank使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rank函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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(×tepFault, 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
}
示例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
}
示例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;
}
示例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 </td><td>Race </td><td>Rank </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> </td><td>%s </td><td>%s </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");
}
示例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;
}
示例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]);
}
示例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;
}
示例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());
}
示例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;
}