Example #1
0
 combination unranking(uint64_t num, uint16_t k, uint16_t n)
 {
     std::vector<uint16_t> c;
     uint16_t max = n;
     
     for (uint16_t i = k; i >= 1; i--)
     {
         if (num <= 0) {
             c.push_back(i-1);
         } else {
             for (; max >= 1;)
             {
                 uint64_t c_max_i = cnr(max, i);
                 if (num >= c_max_i) {
                     c.push_back(max);
                     
                     num -=  c_max_i;
                     max --;
                     break;
                 } else {
                     max --;
                 }
             }
         }
     }
     
     std::sort(c.begin(), c.end());
     
     return c;
 }
static void TopLeft(
	double			&top,
	double			&left,
	const THmgphy	&T,
	int				gW,
	int				gH,
	double			trim )
{
	vector<Point>	cnr( 4 );

	cnr[0] = Point(      trim,      trim );
	cnr[1] = Point( gW-1-trim,      trim );
	cnr[2] = Point( gW-1-trim, gH-1-trim );
	cnr[3] = Point(      trim, gH-1-trim );

	T.Transform( cnr );

	top  = BIGD;
	left = BIGD;

	for( int k = 0; k < 4; ++k ) {
		top  = fmin( top,  cnr[k].y );
		left = fmin( left, cnr[k].x );
	}
}
Example #3
0
 uint64_t ranking(const combination& c)
 {
     std::vector<uint16_t> v(c);
     std::sort(v.begin(), v.end());
     uint64_t n = 0;
     // sum of C(v[k - 1], k)
     for (size_t i = 1; i <= v.size(); i ++) {
         n += cnr(v[i - 1], i);
     }
     return n;
 }
Example #4
0
void main(void)
{
     int      n, r;
     char     line[100];

     printf("\nCombinatorial Coefficient by Addition");
     printf("\n=====================================");
     printf("\n\nN ---> ");
     gets(line);
     n = atoi(line);
     printf(    "R ---> ");
     gets(line);
     r = atoi(line);

     printf("\nC(%d,%d) = %lu", n, r, cnr(n,r));
}
Example #5
0
// Fill in the range of coords [x0,xL); [y0,yL) in the scape
// that the given tile will occupy. This tells the painter
// which region to fill in.
//
// We expand the tile by one pixel to be conservative, and
// transform the tile bounds to scape coords. In no case are
// the scape coords to exceed [0,ws); [0,hs).
//
static void ScanLims(
	int				&x0,
	int				&xL,
	int				&y0,
	int				&yL,
	int				ws,
	int				hs,
	const TAffine	&T,
	int				wi,
	int				hi )
{
	double	xmin, xmax, ymin, ymax;

	xmin =  BIGD;
	xmax = -BIGD;
	ymin =  BIGD;
	ymax = -BIGD;

	vector<Point>	cnr( 4 );

// generous box (outset 1 pixel) for scanning

	cnr[0] = Point( -1.0, -1.0 );
	cnr[1] = Point(   wi, -1.0 );
	cnr[2] = Point(   wi,   hi );
	cnr[3] = Point( -1.0,   hi );

	T.Transform( cnr );

	for( int k = 0; k < 4; ++k ) {
		xmin = fmin( xmin, cnr[k].x );
		xmax = fmax( xmax, cnr[k].x );
		ymin = fmin( ymin, cnr[k].y );
		ymax = fmax( ymax, cnr[k].y );
	}

	x0 = max( 0, (int)floor( xmin ) );
	y0 = max( 0, (int)floor( ymin ) );
	xL = min( ws, (int)ceil( xmax ) );
	yL = min( hs, (int)ceil( ymax ) );
}