int main(){

    int i,j,k,l,test,t=1;

   // freopen("in.txt","r",stdin);

    scanf("%d",&test);

    while(test--){

        scanf("%d",&n);

        int x1,y1,z1,x2,y2,z2,a,b,c,d,e,f;

        for(i=1;i<=n;i++){
            scanf("%d %d %d %d %d %d",&x1,&y1,&z1,&x2,&y2,&z2);
            if(i==1){
                a=x1; b=y1; c=z1; d=x2; e=y2; f=z2;
            }
            a=maxi(a,x1); b=maxi(b,y1); c=maxi(c,z1);
            d=mini(d,x2); e=mini(e,y2); f=mini(f,z2);
        }
        d-=a; e-=b; f-=c;
        int ans=d*e*f;
        if(ans<0) ans=0;
        printf("Case %d: %d\n",t++,ans);

    }

    return 0;
}
void init(int node,int b,int e){
     
     if(b==e){
         m[node].max=1; m[node].prev=m[node].suffv=m[node].maxv=a[b]; m[node].pre=1; m[node].suff=1;
         return ; 
     }
     
     int left,right,mid;
     left=node<<1; right=left+1;
      mid=b+e; mid/=2;
     
     init(left,b,mid); init(right,mid+1,e);
     
     m[node].max=maxi(m[left].max,m[right].max);
     m[node].prev=m[left].prev; m[node].suffv=m[right].suffv;
     if(m[left].suffv==m[right].prev){
         m[node].max=maxi(m[node].max,m[left].suff+m[right].pre);
         if(m[left].pre==(mid-b+1)){
             m[node].pre=m[left].pre+m[right].pre;                    
         }
         else m[node].pre=m[left].pre;
         if(m[right].suff==(e-mid)){
             m[node].suff=m[right].suff+m[left].suff;                     
         }
         else m[node].suff=m[right].suff;                               
     }
     else {
          m[node].pre=m[left].pre;
          m[node].suff=m[right].suff;
     }    
         
     
}
Esempio n. 3
0
/// This function calculates the minimum width for each completion entry in the specified
/// array_list. This width depends on the terminal size, so this function should be called when the
/// terminal changes size.
void pager_t::recalc_min_widths(comp_info_list_t *lst) const {
    for (size_t i = 0; i < lst->size(); i++) {
        comp_t *c = &lst->at(i);
        c->min_width = mini(c->desc_width, maxi((size_t)0, available_term_width / 3 - 2)) +
                       mini(c->desc_width, maxi((size_t)0, available_term_width / 5 - 4)) + 4;
    }
}
Esempio n. 4
0
shTextViewer::shTextViewer (const char *fname)
{   /* Try opening target file. */
    assert (fname);
    mFree = true;
    mLines = NULL;
    mNumLines = 0;
    mMaxWidth = 0;
    char path[PRIME_PATH_LENGTH];
    snprintf (path, sizeof (path)-1, "%s/%s", DATADIR, fname);
    FILE *text = fopen (path, "r");
    if (!text) return;
    /* Count lines and check max width. */
    char *buf = GetBuf ();
    while (fgets (buf, SHBUFLEN, text)) {
        mMaxWidth = maxi (mMaxWidth, strlen (buf));
        ++mNumLines;
    }
    ++mNumLines; /* For adding " --End-- " at the bottom. */
    mMaxWidth = maxi (mMaxWidth, 9 /* --End-- */); /* Ok, this is paranoidal. */
    ++mMaxWidth; /* Compensate for \0. */
    /* Copy file to memory. */
    mLines = (char *) calloc (mNumLines * mMaxWidth, sizeof (char));
    rewind (text);
    int line = 0;
    while (fgets (mLines + line * mMaxWidth, mMaxWidth, text)) {
        ++line;
    }
    strcpy (mLines + line * mMaxWidth, " --End-- ");
    /* Done! Now clean up. */
    fclose (text);
}
Esempio n. 5
0
EDLL void Apaddle::set(float x, float y)
{
	xx=maxi(mini(x, 1.f), 0.f);
	yy=maxi(mini(y, 1.f), 0.f);
	switch(mode)
	{
		case paddleX:
		if(defxx==-1)
			defxx=xx;
		control->set(Acontrol::CONTROLER_01, xx);
		break;

		case paddleY:
		if(defyy==-1)
			defyy=yy;
		control->set(Acontrol::CONTROLER_01, yy);
		break;

		case paddleXY:
		if(defxx==-1)
			defxx=xx;
		if(defyy==-1)
			defyy=yy;
		control->set(Acontrol::CONTROLER_01, xx);
		control->set(Acontrol::CONTROLER_02, yy);
		break;
	}
	repaint();
}
Esempio n. 6
0
EDLL void Apaddle::set(float v)
{
	switch(mode)
	{
		case paddleX:
		case paddleXY:
		{
			float	ox=xx;
			xx=maxi(mini(v, 1.f), 0.f);
			if(defxx==-1)
				defxx=xx;
			if(ox!=xx)
			{
				control->set(Acontrol::CONTROLER_01, xx);
				repaint();
			}
		}
		break;

		case paddleY:
		{
			float	oy=yy;
			yy=maxi(mini(v, 1.f), 0.f);
			if(defyy==-1)
				defyy=yy;
			if(oy!=yy)
			{
				control->set(Acontrol::CONTROLER_01, yy);
				repaint();
			}
		}
		break;
	}
}
ii cal(int b,int e){
	
	if(b==e) return p[b];
	if(b>=e) return 0;
	
	if(vis[b][e]) return dp[b][e];
	vis[b][e]=1;
	
	int i,j,k,l;
	ii ret,sum,sumb;
	
	sum=0; sumb=0;
	ret=-inf;
	
	for(i=b;i<=e;i++){
		sum+=p[i];
		ret=maxi(ret,sum-cal(i+1,e));
		//if(b==1&&e==4) printf("ret- > %d %d %d %lld\n",b,e,i,ret);		
	}
	
	for(j=e;j>=b;j--){
		sumb+=p[j];
		ret=maxi(ret,sumb-cal(b,j-1));		
	}
	
	return dp[b][e]=ret;	
	
}
Esempio n. 8
0
// Linear quantizer for a subband
void
QuantizeSubband ( unsigned int* qu_output, const float* input, const int res, float* errors, const int maxNsOrder )
{
	int    n, quant;
    int    offset  = D [res];
    float  mult    = A [res] * NoiseInjectionCompensation1D [res];
    float  invmult = C [res];
    float  signal;

	for ( n = 0; n < 36 - maxNsOrder; n++) {
		quant = (unsigned int)(mpc_lrintf(input[n] * mult) + offset);

        // limitation to 0...2D
        if ((unsigned int)quant > (unsigned int)offset * 2 ) {
            quant = mini ( quant, offset * 2 );
            quant = maxi ( quant, 0 );
        }
        qu_output[n] = quant;
    }

    for ( ; n < 36; n++) {
        signal = input[n] * mult;
		quant = (unsigned int)(mpc_lrintf(signal) + offset);

        // calculate the current error and save it for error refeeding
        errors [n + 6] = invmult * (quant - offset) - signal * NoiseInjectionCompensation1D [res];

        // limitation to 0...2D
        if ((unsigned int)quant > (unsigned int)offset * 2 ) {
            quant = mini ( quant, offset * 2 );
            quant = maxi ( quant, 0 );
        }
        qu_output[n] = quant;
    }
}
inline short SegMax(Seg* a,unsigned short s,unsigned short t){
	short ans=-32768;
	for(s--,t++;s^t^1;s>>=1,t>>=1){
		if(~s&1) maxi(ans,a[s^1].Max);
		if( t&1) maxi(ans,a[t^1].Max);
	}
	return ans;
}
short lineMax(Node* x,Node* y){
	if(x->top==y->top) return SegMax(x->a,y->loc,x->loc);
	short ans=SegMax(x->a,x->top->loc,x->loc);
	for(x=x->top->pa;x->top!=y->top;x=x->top->pa)
		maxi(ans,SegMax(x->a,x->top->loc,x->loc));
	maxi(ans,SegMax(x->a,y->loc,x->loc));
	return ans;
}
double EuroBewerter::max_call(double t, double T, double* X0, int D,
		double Strike, double r, double delta, double sigma) {
	T = T - t;
	double summe = 0;

	for (int d = 0; d < D; ++d) {
		double d_minus = (log(X0[d] / Strike)
				+ (r - delta - sigma * sigma / 2.) * T) / (sigma * sqrt(T));
		double d_plus = d_minus + sigma * sqrt(T);
		Polynom ganz;
		double eins[1] = { 1. };
		ganz.set(eins, 1);
		double I;
		double max = -100000;
		double min = 10000000;
		for (int dd = 0; dd < D; ++dd)
			if (dd != d) {
//				printf("\nd_plus %f, d_minus %f,", d_plus, d_minus);
//				printf("verschiebefaktor %f\n",
//						sigma * sqrt(T)
//								+ log(X0[d] / X0[dd]) / (sigma * sqrt(T)));
//				double pp[18] = { 0.5, 0.3960985, 0, -0.061485, 0, 0.007456, 0,
//						-5.84946E-4, 0, 2.920034E-5, 0, -9.15823E-7, 0,
//						1.740319E-8, 0, -1.826093E-10, 0, 8.10495E-13 };
				double pp[10] = { 0.50000000000009, 0.38567951086190133, 0,
						-0.05010672697589501, 0, 0.004103597701237448, 0,
						-1.631010612321749E-4, 0, 2.4428290978202304E-6 };
				Polynom p;
				p.set(pp, 10);
				double v = sigma * sqrt(T)
						+ log(X0[d] / X0[dd]) / (sigma * sqrt(T));
				max = v > max ? v : max;
				min = v < min ? v : min;

				p.verschieben(v);
//				printf("I innen%f\n",integralExpQ(&p, maxi(-d_plus, -5. + min), 5. - max));
				ganz.multiply_with(&p);
			}
		I = integralExpQ(&ganz, maxi(-d_plus, -5. + min), 5. - max);
//		printf("I aussen%f\n", I);
		summe += X0[d] * exp(-delta * T) / sqrt(2 * 3.141592654) * I;
	}
	double prod = 1;
	for (int d = 0; d < D; ++d) {
		double d_minus = (log(X0[d] / Strike)
				+ (r - delta - sigma * sigma / 2.) * T) / (sigma * sqrt(T));
		prod *= (1 - (1 - cnd(-d_minus)));
	}

	double zu = -Strike * exp(-r * T) + Strike * exp(-r * T) * prod;
	double ergebnis = (summe + zu) * exp(-r * t); //return erf(0.1);

	double e1 = 0;
	for (int d = 0; d < D; ++d)
		e1 = maxi(e1, call(t, T, X0[d], Strike, r, delta, sigma));
	return maxi(ergebnis, e1);
}
int main(){
	
	int i,j,k,l,test,t=0;
	
//	freopen("in.txt","r",stdin);
	
	while(scanf("%d",&n)==1){
		
		memset(mat,0,sizeof(mat));
		tot=0;
		
		for(i=1;i<=n;i++){
			scanf("%d %d",&j,&k);
			mat[j][k]=1;
			tot=maxi(tot,maxi(j,k));	
		}
		
		for(k=0;k<=tot;k++){
			for(i=0;i<=tot;i++){
				for(j=0;j<=tot;j++){
					mat[i][j]+=(mat[i][k]*mat[k][j]);
				}
			}
		}

		for(k=0;k<=tot;k++){
			for(i=0;i<=tot;i++){
				if(mat[i][k]==0) continue;
				for(j=0;j<=tot;j++){
					if(mat[i][j]==0||mat[k][j]==0) continue;
					if(mat[k][k]>0||mat[i][i]>0||mat[j][j]>0){
						mat[i][j]=-1;
					}
					else if(mat[i][k]==-1||mat[k][j]==-1){
						mat[i][j]=-1;
					}
				}
			}
		}
		
	
		printf("matrix for city %d\n",t++);
	
		for(i=0;i<=tot;i++){
			for(j=0;j<=tot;j++){
				if(j) printf(" ");
				printf("%d",mat[i][j]);
			}
			printf("\n");
		}		
		
		
	}
	
	return 0;
}
Esempio n. 13
0
static void biasSelection(float value)
{
	int track, row;
	struct sync_track** tracks = getTracks();
	TrackViewInfo* viewInfo = getTrackViewInfo();
	int selectLeft = mini(viewInfo->selectStartTrack, viewInfo->selectStopTrack);
	int selectRight = maxi(viewInfo->selectStartTrack, viewInfo->selectStopTrack);
	int selectTop = mini(viewInfo->selectStartRow, viewInfo->selectStopRow);
	int selectBottom = maxi(viewInfo->selectStartRow, viewInfo->selectStopRow);
	
	// If we have no selection and no currenty key bias the previous key

	if (selectLeft == selectRight && selectTop == selectBottom)
	{
		int idx;
		struct sync_track* track;
		struct sync_track** tracks = getTracks();

		if (!tracks || !tracks[getActiveTrack()]->keys)
			return;

		track = tracks[getActiveTrack()];

		idx = sync_find_key(track, getRowPos());
		
		if (idx < 0) 
		{
			idx = -idx - 1;
			selectTop = selectBottom = track->keys[emaxi(idx - 1, 0)].row;
		}
	}
	
	Commands_beginMulti("biasSelection");

	for (track = selectLeft; track <= selectRight; ++track) 
	{
		struct sync_track* t = tracks[track];

		for (row = selectTop; row <= selectBottom; ++row) 
		{
			struct track_key newKey;
			int idx = sync_find_key(t, row);
			if (idx < 0) 
				continue;

			newKey = t->keys[idx];
			newKey.value += value;

			Commands_updateKey(track, &newKey);
		}
	}

	Commands_endMulti();
	updateNeedsSaving();
}
Esempio n. 14
0
/**
   This function calculates the minimum width for each completion
   entry in the specified array_list. This width depends on the
   terminal size, so this function should be called when the terminal
   changes size.
*/
static void recalc_width( std::vector<comp_t *> &lst, const wchar_t *prefix )
{
	for( size_t i=0; i<lst.size(); i++ )
	{
		comp_t *c = lst.at(i);
		
		c->min_width = mini( c->desc_width, maxi(0,termsize.ws_col/3 - 2)) +
			mini( c->desc_width, maxi(0,termsize.ws_col/5 - 4)) +4;
	}
	
}
	kd_tree(point &_x,unsigned _split,kd_tree* _l,kd_tree* _r):split(_split){
		memcpy(&x,&_x,sizeof(point));
		memcpy(&max,&x,sizeof(point));
		memcpy(&min,&x,sizeof(point));
		if (c[0]=_l)
			for (int i=0;i<kD;++i)
				maxi(max.p[i],c[0]->max.p[i]),
				mini(min.p[i],c[0]->min.p[i]);
		if (c[1]=_r)
			for (int i=0;i<kD;++i)
				maxi(max.p[i],c[1]->max.p[i]),
				mini(min.p[i],c[1]->min.p[i]);
	}
int cal(int ind,int diff){
	
	if(ind==0&&diff==0) return 0;
	if(ind<=0) return -inf;
	
	if(dp[ind][diff]!=-1) return dp[ind][diff];
	
	int ret;
	
	ret=maxi(cal(ind-1,diff-h[ind]),cal(ind-1,diff+h[ind])+h[ind]);
	ret=maxi(ret,cal(ind-1,diff));
	
	return dp[ind][diff]=ret;
}
Esempio n. 17
0
void initialize_phi( Element *EmTemp, double *norm, double dt,double min,int *elem){
  
  double *phi_slope=EmTemp->get_phi_slope();
  double *state_vars=EmTemp->get_state_vars();
  double *prev_state_vars=EmTemp->get_prev_state_vars();
  //double *d_state_vars=EmTemp->get_d_state_vars();
  double delta_p,delta_m;
  double flux_phi,a_p,a_m,b_p,b_m,c_p,c_m,d_p,d_m;  
  //  *norm=0;
  prev_state_vars[0]=state_vars[0];

  if (dabs(state_vars[0])<.5) *elem=*elem+1; 

  a_p=maxi( phi_slope[0] ,0.);
  a_m=mini( phi_slope[0] ,0.);
  b_p=maxi( phi_slope[1] ,0.);
  b_m=mini( phi_slope[1] ,0.);
  c_p=maxi( phi_slope[2] ,0.);
  c_m=mini( phi_slope[2] ,0.);
  d_p=maxi( phi_slope[3] ,0.);
  d_m=mini( phi_slope[3] ,0.);

  if (state_vars[4]>0)
   flux_phi=sqrt(maxi(a_p*a_p , b_m*b_m) + maxi(c_p*c_p , d_m*d_m))-1;
  else if (state_vars[4]<0)
   flux_phi=sqrt(maxi(a_m*a_m , b_p*b_p) + maxi(c_m*c_m , d_p*d_p))-1;
  else
   flux_phi=0;

   //if (state_vars[4]==0) printf("hello I am zero \n");

  state_vars[0]=prev_state_vars[0] - dt*signed_d_f(state_vars[4],min)*flux_phi;

  for(int j=0;j<4;j++)
     if(*(EmTemp->get_neigh_proc()+j) == INIT)   // this is a boundary!
         state_vars[0]=state_vars[4];//1;//prev_state_vars[0];

//  delta_p = sqrt( pow( maxi( phi_slope[0] ,0.) , 2) + pow( mini( phi_slope[1] ,0.) , 2)+
//		  pow( maxi( phi_slope[2] ,0.) , 2) + pow( mini( phi_slope[3] ,0.) , 2));


//  delta_m = sqrt( pow( maxi( phi_slope[1] ,0.) , 2) + pow( mini( phi_slope[0] ,0.) , 2)+
//		  pow( maxi( phi_slope[3] ,0.) , 2) + pow( mini( phi_slope[2] ,0.) , 2));


//  state_vars[0]=prev_state_vars[0] - dt* (maxi(signed_d_f(state_vars[4],min),0.) * delta_p + 
//					  mini(signed_d_f(state_vars[4],min),0.) * delta_m ) + dt * signed_d_f(state_vars[4],min);

  // state_vars[0]=prev_state_vars[0] + dt*( c_sgn(state_vars[4]) -
  // 					  (maxi(c_sgn(state_vars[4]),0.)*delta_p + mini(c_sgn(state_vars[4]),0.)*delta_m ));

  //if((d_state_vars[0]!=0||d_state_vars[6]!=0) && state_vars[4]!=0)
  //printf("this is the place dx=%f dy=%f \n",d_state_vars[0],d_state_vars[6]);
  //  state_vars[0]=prev_state_vars[0] + dt*c_sgn(state_vars[4])*(1-sqrt(pow(d_state_vars[0],2)+pow(d_state_vars[6],2)));

 
  *norm += dabs(state_vars[0]-prev_state_vars[0]);
//    if (dabs(state_vars[0]-prev_state_vars[0])>0) printf("this is the difference .........%f\n", dabs(state_vars[0]-prev_state_vars[0]));
  return;
}
Esempio n. 18
0
/********************************************//**
 * \brief Draw a line on image in a given color
 * \warning NOT FUNCTIONNAL
 * \param img t_img* - image to modify (also output)
 * \param pix1 t_pixel - first point of line
 * \param pix2 t_pixel - second point of line
 * \param RGB CPU_INT32U - color of the line
 * \return t_vect - vector representing the line
 *
 * Needs to be done
 * Helpfull macro to define color is SetRGB(r,g,b), with value between 0 and 255
 ***********************************************/
t_vect highlight_line(t_img * img,t_pixel pix1,t_pixel pix2,CPU_INT32U RGB)
{
    t_vect v;
    CPU_FP32 a, b, y_calc;
    CPU_INT16S i,j;

    t_simplearea area_of_draw;

    if((pix2.x - pix1.x) != 0)
    {
        a = ((CPU_FP32)pix2.y - (CPU_FP32)pix1.y) / (((CPU_FP32)pix2.x - (CPU_FP32)pix1.x));
    }else
    {
        a = 1000000;
    }


    b = (CPU_FP32)pix1.y - a * (CPU_FP32)pix1.x;

    //printf("y = %.2f x + %.2f\n",a,b);

    area_of_draw.BotLeft.x = mini(pix1.x,pix2.x);
    area_of_draw.BotLeft.y = mini(pix1.y,pix2.y);
    area_of_draw.TopRight.x = maxi(pix1.x,pix2.x);
    area_of_draw.TopRight.y = maxi(pix1.y,pix2.y);


    for(i=area_of_draw.BotLeft.y;i<= area_of_draw.TopRight.y ;i++)
    {
        for(j=area_of_draw.BotLeft.x ; (j<= area_of_draw.TopRight.x );j++)
        {
                //check if point belong to the line between pix1 and pix 2
                y_calc = a * j + b;
                if(((CPU_INT16S)y_calc -abs(a)/1.5 <= i)&&((CPU_INT16S)y_calc +abs(a)/1.5 >= i))
                {
                    img->Red[i][j] = GetRed(RGB);
                    img->Green[i][j] = GetGreen(RGB);
                    img->Blue[i][j] = GetBlue(RGB);
                }else
                {
                    //nothing
                }


        }
    }
    v.x = 5;
    v.y = a * v.x + b;
    return v;
}
Esempio n. 19
0
int main()
{
	int i;
	int j;
	int k;
	int l;
	int m;
	int n;
	int t;
	int x;
	int y;
	int a[102];
	int b[102];k=1;
	int lcs[102][102];
	while(scanf("%d %d",&n,&m) && (n || m))
	{
		for(i=0;i<n;i++) scanf("%d",&a[i]);
		for(i=0;i<m;i++) scanf("%d",&b[i]);
		memset(lcs,0,sizeof(lcs));
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=m;j++)
			{
				if(a[i-1]==b[j-1]) lcs[i][j] = lcs[i-1][j-1]+1;
				else lcs[i][j] = maxi(lcs[i-1][j],lcs[i][j-1]);
			}
		}
		printf("Twin Towers #%d\nNumber of Tiles : %d\n\n",k++,lcs[n][m]);
	}
	return 0;
}
Esempio n. 20
0
/// Check if there are buffers associated with the job, and select on them for a while if available.
///
/// \param j the job to test
///
/// \return 1 if buffers were available, zero otherwise
static int select_try(job_t *j) {
    fd_set fds;
    int maxfd = -1;

    FD_ZERO(&fds);

    const io_chain_t chain = j->all_io_redirections();
    for (size_t idx = 0; idx < chain.size(); idx++) {
        const io_data_t *io = chain.at(idx).get();
        if (io->io_mode == IO_BUFFER) {
            const io_pipe_t *io_pipe = static_cast<const io_pipe_t *>(io);
            int fd = io_pipe->pipe_fd[0];
            // fwprintf( stderr, L"fd %d on job %ls\n", fd, j->command );
            FD_SET(fd, &fds);
            maxfd = maxi(maxfd, fd);
            debug(3, L"select_try on %d", fd);
        }
    }

    if (maxfd >= 0) {
        int retval;
        struct timeval tv;

        tv.tv_sec = 0;
        tv.tv_usec = 10000;

        retval = select(maxfd + 1, &fds, 0, 0, &tv);
        if (retval == 0) {
            debug(3, L"select_try hit timeout");
        }
        return retval > 0;
    }

    return -1;
}
Esempio n. 21
0
/**
   Arraylist test
*/
static void al_test( int sz)
{
	long i;	
	array_list_t l;

	

	al_init( &l );
	
	al_set_long( &l, 1, 7L );
	al_set_long( &l, sz, 7L );
	
	if( al_get_count( &l ) != maxi( sz+1, 2 ) )
		err( L"Wrong number of elements in array list" );
	
	for( i=0; i<al_get_count( &l ); i++ )
	{
		long val = al_get_long( &l, i );
		if( (i == 1) || (i==sz))
		{
			if( val != 7 )
				err( L"Canary changed to %d at index %d", val, i );
		}
		else
		{
			if( val != 0 )
				err( L"False canary %d found at index %d", val, i );
		}
	}
}
Esempio n. 22
0
     /* Displays loaded file to the screen. This procedure */
void /* should have no reason to modify member variables.  */
shTextViewer::show (bool bottom)
{
    int height = I->getMaxLines () - 1;
    int first = 0;
    if (bottom)  first = maxi (mNumLines - height, 0);
    I->newTempWin ();

    shInterface::SpecialKey sp;
    while (sp != shInterface::kEscape) {
        /* Show content. */
        I->clearWin (shInterface::kTemp);
        I->setWinColor (shInterface::kTemp, kGray);
        int lines_drawn = mini (mNumLines - first, height);
        for (int i = first; i < first + lines_drawn; ++i) {
            print (i - first, i);
        }
        /* Show help at bottom. */
        I->setWinColor (shInterface::kTemp, kWhite);
        I->winPrint (shInterface::kTemp, height, 0,
"    SPACE  ENTER  ESCAPE          ARROWS  PAGE UP  PAGE DOWN");
        I->setWinColor (shInterface::kTemp, kGray);
        I->winPrint (shInterface::kTemp, height, 9, ",");
        I->winPrint (shInterface::kTemp, height, 16, ",");
        I->winPrint (shInterface::kTemp, height, 24, " - exit");
        I->winPrint (shInterface::kTemp, height, 40, ",");
        I->winPrint (shInterface::kTemp, height, 49, ",");
        I->winPrint (shInterface::kTemp, height, 60, " - navigation");
        I->refreshWin (shInterface::kTemp);
        I->getSpecialChar (&sp);
        /* Navigation. */
        switch (sp) {
        case shInterface::kHome:
            first = 0;
            break;
        case shInterface::kEnd:
            first = mNumLines - height;
            break;
        case shInterface::kUpArrow:
            if (first > 0) --first;
            break;
        case shInterface::kDownArrow:
            if (first + height < mNumLines) ++first;
            break;
        case shInterface::kPgUp: case shInterface::kLeftArrow:
            first -= height / 2;
            if (first < 0) first = 0;
            break;
        case shInterface::kPgDn: case shInterface::kRightArrow:
            first += height / 2;
            if (first + height > mNumLines) first = mNumLines - height;
            break;
        case shInterface::kEnter: case shInterface::kSpace:
            sp = shInterface::kEscape;
            break;
        default: break;
        }
    }
    I->delTempWin ();
}
ii chck(ii x){

	ii i,j;
	ii k=-1;

	ii sum=0;
	j=m;
	temp[m]=n;

	for(i=n;i>=1;i--){		
		if(sum+a[i]>x||i<j){
			temp[j-1]=i;
			j--;
			if(j<1) return -1;
			sum=a[i];
			if(sum>x) return -1;
		}
		else sum+=a[i];
		k=maxi(k,sum);
	}

	if(i>=1) return -1;

	for(i=1;i<=m;i++){
		br[i]=temp[i];
	}
	
	return k;
	
}
Esempio n. 24
0
int pq_put( priority_queue_t *q,
            void *e )
{
    int i;

    if( q->size == q->count )
    {
        void **old_arr = q->arr;
        int old_size = q->size;
        q->size = maxi( 4, 2*q->size );
        q->arr = (void **)realloc( q->arr, sizeof(void*)*q->size );
        if( q->arr == 0 )
        {
            oom_handler( q );
            q->arr = old_arr;
            q->size = old_size;
            return 0;
        }
    }

    i = q->count;
    while( (i>0) && (q->compare( q->arr[(i-1)/2], e )<0 ) )
    {
        q->arr[i] = q->arr[(i-1)/2];
        i = (i-1)/2;
    }
    q->arr[i]=e;

    q->count++;

    return 1;

}
Esempio n. 25
0
/// Print values of all resource limits.
static void print_all(int hard, io_streams_t &streams) {
    int i;
    int w = 0;

    for (i = 0; resource_arr[i].desc; i++) {
        w = maxi(w, fish_wcswidth(resource_arr[i].desc));
    }

    for (i = 0; resource_arr[i].desc; i++) {
        struct rlimit ls;
        rlim_t l;
        getrlimit(resource_arr[i].resource, &ls);
        l = hard ? ls.rlim_max : ls.rlim_cur;

        const wchar_t *unit =
            ((resource_arr[i].resource == RLIMIT_CPU)
                 ? L"(seconds, "
                 : (get_multiplier(resource_arr[i].resource) == 1 ? L"(" : L"(kB, "));

        streams.out.append_format(L"%-*ls %10ls-%lc) ", w, resource_arr[i].desc, unit,
                                  resource_arr[i].switch_char);

        if (l == RLIM_INFINITY) {
            streams.out.append(L"unlimited\n");
        } else {
            streams.out.append_format(L"%d\n", l / get_multiplier(resource_arr[i].resource));
        }
    }
}
int main()
{
	int a[] = {2,14,10,8,9,53,1};
	int i, ret;

	for(i=sizeof(a)/sizeof(a[0])-1;i>=1;i--) {
		printf("i %d i-1 %d\n", i, i-1);
		if(a[i] > a[i-1]) {
			k[i-1] = a[i];
		} else {
			/*find out in the right max array*/
			if(ret=search(max, a[i-1], sizeof(a)/sizeof(a[0])-1, i+1))	
				k[i-1] = ret;
			else	
				k[i-1] = -1;
		}
		max[i] = maxi(a[i], a[i-1]);
	}

	k[sizeof(a)/sizeof(a[0])-1] = -1;
	for(i=0;i<(sizeof(a)/sizeof(a[0]))-1;i++)
		printf("%d ,", k[i]);
	printf("\n");

	return 0;
}
Esempio n. 27
0
// input : Energy *erg, calibrated energy *werg
// output: spread energy *res, spread weighted energy *wres
// SPRD describes the spreading function as calculated in psy_tab.c
static void
SpreadingSignal ( const float* erg, const float* werg, float* res,
				  float* wres )
{
    int           n;
    int           k;
    int           start;
    int           stop;
    const float*  sprd;
    float         e;
    float         ew;


    for (k=0; k<PART_LONG; ++k, ++erg, ++werg) { // Source (masking partition)
        start = maxi(k-5, 0);           // minimum affected partition
        stop  = mini(k+7, PART_LONG-1); // maximum affected partition
        sprd  = SPRD[k] + start;         // load vector
        e     = *erg;
        ew    = *werg;

        for (n=start; n<=stop; ++n, ++sprd) {
            res [n] += *sprd * e;       // spreading signal
            wres[n] += *sprd * ew;      // spreading weighted signal
        }
    }

    return;
}
Esempio n. 28
0
/// Calculate layout information for the given prompt. Does some clever magic to detect common
/// escape sequences that may be embeded in a prompt, such as color codes.
static prompt_layout_t calc_prompt_layout(const wchar_t *prompt) {
    size_t current_line_width = 0;
    size_t j;

    prompt_layout_t prompt_layout = {};
    prompt_layout.line_count = 1;

    for (j = 0; prompt[j]; j++) {
        if (prompt[j] == L'\x1b') {
            // This is the start of an escape code. Skip over it if it's at least one character
            // long.
            size_t escape_len = escape_code_length(&prompt[j]);
            if (escape_len > 0) {
                j += escape_len - 1;
            }
        } else if (prompt[j] == L'\t') {
            current_line_width = next_tab_stop(current_line_width);
        } else if (prompt[j] == L'\n' || prompt[j] == L'\f') {
            // PCA: At least one prompt uses \f\r as a newline. It's unclear to me what this is
            // meant to do, but terminals seem to treat it as a newline so we do the same.
            current_line_width = 0;
            prompt_layout.line_count += 1;
        } else if (prompt[j] == L'\r') {
            current_line_width = 0;
        } else {
            // Ordinary decent character. Just add width. This returns -1 for a control character -
            // don't add that.
            current_line_width += fish_wcwidth_min_0(prompt[j]);
            prompt_layout.max_line_width = maxi(prompt_layout.max_line_width, current_line_width);
        }
    }
    prompt_layout.last_line_width = current_line_width;
    return prompt_layout;
}
Esempio n. 29
0
/**
   Check if there are buffers associated with the job, and select on
   them for a while if available. 
   
   \param j the job to test

   \return 1 if buffers were avaialble, zero otherwise
*/
static int select_try( job_t *j )
{
	fd_set fds;
	int maxfd=-1;
	io_data_t *d;

	FD_ZERO(&fds);
	
	for( d = j->io; d; d=d->next )
	{
		if( d->io_mode == IO_BUFFER )
		{
			int fd = d->param1.pipe_fd[0];
//			fwprintf( stderr, L"fd %d on job %ls\n", fd, j->command );
			FD_SET( fd, &fds );
			maxfd = maxi(maxfd, fd);
			debug( 3, L"select_try on %d\n", fd );
		}
	}
	
	if( maxfd >= 0 )
	{
		int retval;
		struct timeval tv;
		
		tv.tv_sec=0;
		tv.tv_usec=10000;
		
		retval =select( maxfd+1, &fds, 0, 0, &tv );
		return retval > 0;
	}

	return -1;
}
Esempio n. 30
0
int matrixPivot(Image<T>& M, const int y)
{
GVX_TRACE(__PRETTY_FUNCTION__);
  ASSERT(M.isSquare()); const int siz = M.getWidth();
  ASSERT(y < siz);

  // find the element with largest absolute value in the column y and
  // below row y:
  int bestj = siz+1; T maxi(0);
  for (int j = y; j < siz; j ++)
    {
      const T tmp = std::abs(M.getVal(y, j));
      if (tmp > maxi) { maxi = tmp; bestj = j; }
    }

  // if we did not find any non-zero value, let the caller know:
  if (bestj == siz + 1) return -1;

  // if our pivot is at the given y, do nothing and return that y:
  if (bestj == y) return y;

  T* M_arr = M.getArrayPtr();

  // otherwise, exchange rows y and bestj in M, and return bestj:
  for (int i = 0; i < siz; i ++)
    {
      std::swap(M_arr[i + bestj*siz],
                M_arr[i + y*siz]);
    }

  return bestj;
}