int main(int argc, char *argv[]) { int T; scanf("%d", &T); while (T--) { int i, min = 1e9, n, sum, tmpSum = 0, st = 0, ed = 0; memset(list, 0, sizeof(list)); scanf("%d%d", &n, &sum); for (i = 0; i < n; i++) { scanf("%d", &list[i]); } tmpSum = list[0]; while (st < n && ed < n) { if (tmpSum >= sum) { min = mini(min, (st-ed+1)); tmpSum -= list[ed++]; } else { tmpSum += list[++st]; } } while (tmpSum >= sum && ed < n) { min = mini(min, (st-ed+1)); tmpSum -= list[ed++]; } if (min == 1e9) { min = 0; } printf("%d\n", min); } return 0; }
int main(){ scanf("%u%u%u",&N,&M,&K); int u,v,w,i,k,s,t; scanf("%u%u",&s,&t); S=V+s; T=V+t; while(M--){ scanf("%u%u%u",&u,&v,&w); V[u].addedge(V+v,w); V[v].addedge(V+u,w); } for(node* u=V;u<V+N;++u) for(k=K;k>=0;--k) u->dist[k]=INF; std::priority_queue<situ> h; situ x,y; edge *e; S->dist[K]=0; h.push((situ){S,K}); while(!h.empty()){ x=h.top();h.pop(); if(y.k=x.k) for(e=x.v->son;e;e=e->next){ y.v=e->ed; if(mini(y.v->dist[y.k],x.v->dist[x.k]+e->w)) h.push(y); --y.k; if(mini(y.v->dist[y.k],x.v->dist[x.k])) h.push(y); ++y.k; } else for(e=x.v->son;e;e=e->next){ y.v=e->ed; if(mini(y.v->dist[y.k],x.v->dist[x.k]+e->w)) h.push(y); } } int Ans=INF; for(k=K;k>=0;--k) mini(Ans,T->dist[k]); printf("%d\n",Ans); }
int main(){ //make graph int M,N,i,j,ii;scanf("%d%d",&M,&N); for (i=1;i<=N;++i) addedge(&S,car+i,1,0); int time; for (i=1;i<=N;++i) for (j=1;j<=M;++j){ scanf("%d",&time); for (ii=1;ii<=N;++ii) addedge(car+i,&worker[j][ii],1,time*ii); } for (j=1;j<=M;++j) for (ii=1;ii<=N;++ii) addedge(&worker[j][ii],&T,1,0); //calc cost flow int Ans=0; S.dist=0;S.fro=NULL; for(;;){ std::queue<node*> q; node *x,*y; edge *e; //clear for (i=1;i<=N;++i) car[i].dist=inf; for (j=1;j<=M;++j) for (ii=1;ii<=N;++ii) worker[j][ii].dist=inf; T.dist=inf; for (q.push(&S);!q.empty();q.pop()) for (e=(x=q.front())->son;e;e=e->next) if (e->cap&&mini((y=e->ed)->dist,x->dist+e->cost)) {y->fro=e;if (y->dist<T.dist) q.push(y);} if (T.dist==inf) break; int c=inf; for (e=T.fro;e;e=e->pre->fro) mini(c,e->cap); for (e=T.fro;e;e=e->pre->fro) e->cap-=c,E[(e-E)^1].cap+=c,Ans+=c*e->cost; } //print Ans printf("%.2f\n",(float)Ans/N); }
// 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; } }
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; }
int main() { freopen("form.in","r",stdin); freopen("form.out","w",stdout); scanf("%d%d",&N,&M); null=new Splay; nullinit(); seq=null; for (i=1;i<=N;++i) { scanf("%d",&a[i]); b[i]=a[i]; mini(dist,abs(seq->closest(b[i])->data-b[i])); seq->ins(b[i]); } h[0]=N-1; for (i=1;i<N;++i) h[i]=abs(b[i]-a[i+1]),hh[i]=t[i]=i; t[N]=0; for (i=N-1;i;--i) down(i); char opt[14]; int cnt=0; while (M--) { scanf("%s",opt); switch (opt[4]) { case 'R': scanf("%d%d",&i,&k); chan(t[i],abs(b[i]-k)); b[i]=k; if (i<N) inse(abs((b[i])-a[i+1]),i); mini(dist,abs(k-seq->closest(k)->data)); seq->ins(k); break; case 'G': ++cnt; printf("%d\n",h[1]); break; case 'S': ++cnt; printf("%d\n",dist); break; } } }
/// 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; } }
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(); }
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; } }
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; }
void EM_error( int pos, char *message, ... ) { va_list ap; IntList lines = linePos; int num = lineNum; anyErrors = TRUE; while( lines && lines->i >= pos ) { lines = lines->rest; num--; } fprintf( stderr, "('%s'):", *fileName ? mini(fileName) : "chuck" ); sprintf( g_lasterror, "('%s'):", *fileName ? mini(fileName) : "chuck" ); if(lines) fprintf(stderr, "line(%d).char(%d):", num, pos-lines->i ); if(lines) { sprintf( g_buffer, "line(%d).char(%d):", num, pos-lines->i ); strcat( g_lasterror, g_buffer ); } fprintf(stderr, " " ); strcat( g_lasterror, " " ); va_start(ap, message); vfprintf(stderr, message, ap); vsprintf( g_buffer, message, ap ); va_end(ap); fprintf(stderr, "\n"); strcat( g_lasterror, g_buffer ); }
static void unpremultiplyAlpha(unsigned char* image, int w, int h, int stride) { int x,y; // Unpremultiply for (y = 0; y < h; y++) { unsigned char *row = &image[y*stride]; for (x = 0; x < w; x++) { int r = row[0], g = row[1], b = row[2], a = row[3]; if (a != 0) { row[0] = (int)mini(r*255/a, 255); row[1] = (int)mini(g*255/a, 255); row[2] = (int)mini(b*255/a, 255); } row += 4; } } // Defringe for (y = 0; y < h; y++) { unsigned char *row = &image[y*stride]; for (x = 0; x < w; x++) { int r = 0, g = 0, b = 0, a = row[3], n = 0; if (a == 0) { if (x-1 > 0 && row[-1] != 0) { r += row[-4]; g += row[-3]; b += row[-2]; n++; } if (x+1 < w && row[7] != 0) { r += row[4]; g += row[5]; b += row[6]; n++; } if (y-1 > 0 && row[-stride+3] != 0) { r += row[-stride]; g += row[-stride+1]; b += row[-stride+2]; n++; } if (y+1 < h && row[stride+3] != 0) { r += row[stride]; g += row[stride+1]; b += row[stride+2]; n++; } if (n > 0) { row[0] = r/n; row[1] = g/n; row[2] = b/n; } } row += 4; } } }
EDLL void Apaddle::paint(Abitmap *bitmap) { switch(type) { case paddleLINE: { dword cf=((lineColor>>1)&0x007f7f7f)|0xff000000; int s=pos.w>>1; double a=PI*1.4-yy*PI*1.7; int px=(int)(cos(a)*s+s); int py=(int)(-sin(a)*s+s); bitmap->linea((int)(cos(a+PI*0.5)+s), (int)(-sin(a+PI*0.5)+s), px, py, cf, 0.8f); bitmap->linea((int)(cos(a-PI*0.5)+s), (int)(-sin(a-PI*0.5)+s), px, py, cf, 0.8f); bitmap->line(s, s, px, py, lineColor); } break; default: if(bmp) { switch(mode) { case paddleX: { int nx=bmp->w/ow; int ny=bmp->h/oh; int nb=nx*ny; int n=mini((int)(xx*(float)nb), nb-1); bitmap->set(0, 0, (n%nx)*ow, (n/nx)*oh, ow, oh, bmp, bitmapDEFAULT, bitmapDEFAULT); } break; case paddleY: { int nx=bmp->w/ow; int ny=bmp->h/oh; int nb=nx*ny; int n=mini((int)(yy*(float)nb), nb-1); bitmap->set(0, 0, (n%nx)*ow, (n/nx)*oh, ow, oh, bmp, bitmapDEFAULT, bitmapDEFAULT); } break; case paddleXY: { int nbx=bmp->w/ow; int nby=bmp->h/oh; int nx=mini((int)(xx*(float)nbx), nbx-1); int ny=mini((int)(yy*(float)nby), nby-1); bitmap->set(0, 0, nx*ow, ny*oh, ow, oh, bmp, bitmapDEFAULT, bitmapDEFAULT); } break; } } break; } controlPaint(bitmap, pos.w, pos.h); }
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(); }
/** 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; } }
/* Determine basis size */ int BasisSize() /*======================================================================= */ { /* Loop variables */ int L1, jK1, K1, M1, pS1, qS1, pI1, qI1, pI1b, qI1b; /* Min and max values for loop variables */ int K1max, M1max, qS1max, qI1max, qI1bmax; int iRow = 0; double I = Sys.I; double Ib = Sys.Ib; for (L1=0;L1<=Lemax;L1++) { if (isodd(L1) && (L1>Lomax)) continue; for (jK1=jKmin;jK1<=1;jK1+=2) { K1max = mini(Kmax,L1); for (K1=0;K1<=K1max;K1+=deltaK) { if ((K1==0)&(parity(L1)!=jK1)) continue; M1max = mini(Mmax,L1); for (M1=-M1max;M1<=M1max;M1++) { for (pS1=pSmin;pS1<=1;pS1++) { qS1max = 1 - abs(pS1); for (qS1=-qS1max;qS1<=qS1max;qS1+=2) { for (pI1 = -pImax;pI1<=pImax;pI1++) { qI1max = (int)(2*I) - abs(pI1); for (qI1=-qI1max;qI1<=qI1max;qI1+=2) { for (pI1b = -pIbmax;pI1b<=pIbmax;pI1b++) { if ((MeirovitchSymm) && (Sys.DirTilt==0)&&((pI1+pI1b+pS1-1)!=M1)) continue; qI1bmax = (int)(2*Ib) - abs(pI1b); for (qI1b=-qI1bmax;qI1b<=qI1bmax;qI1b+=2) { /*mexPrintf("%3d %3d %3d %3d %2d %2d %2d %2d %2d %2d\n",L1,jK1,K1,M1,pS1,qS1,pI1,qI1,pI2,qI2);*/ iRow++; } /* qI1b */ } /* pI1b */ } /* qI1 */ } /* pI1 */ } /* qS1 */ } /* pS1 */ } /* M1 */ } /* K1 */ } /* jK1 */ } /* L1 */ return iRow; /* number of rows */ }
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]); }
/********************************************//** * \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; }
int main() { int i,j,k,l,test,t=1; freopen("in.txt","r",stdin); scanf("%d",&test); while(test--) { scanf("%d %d %d %d",&n,&r,&p,&q); ii two,five; two=cal(n,2); two-=cal(r,2); two-=cal(n-r,2); five=cal(n,5); five-=cal(r,5); five-=cal(n-r,5); cal1(p); two+=(a[0]*q); five+=(a[1]*q); printf("Case %d: %lld\n",t++,mini(two,five)); } return 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 (); }
void Alarm::con() { connect(timer,SIGNAL(timeout()),this,SLOT(clockChange())); timer->start(1000); connect(uptimer,SIGNAL(timeout()),this,SLOT(dialogUp())); uptimer->start(20); connect(dtimer,SIGNAL(timeout()),this,SLOT(down())); dtimer->start(20); connect(button,SIGNAL(clicked()),dtimer,SIGNAL(timeout())); connect(button,SIGNAL(clicked()),this,SLOT(mini())); connect(itimer,SIGNAL(timeout()),this,SLOT(comToCur())); itimer->start(20); connect(restoreAct,SIGNAL(triggered(bool)),uptimer,SIGNAL(timeout())); connect(this,SIGNAL(isCurrentTime()),uptimer,SIGNAL(timeout())); connect(itimer,SIGNAL(timeout()),this,SLOT(comToCur())); itimer->start(10); connect(quitAct,SIGNAL(triggered(bool)),this,SLOT(close())); };
ADLL bool AftpClient::sendFile(char *filename, Afile *f) { bool r=false; section.enter(__FILE__,__LINE__); if(status==statusCONNECTED) { int size=(int)f->getSize(); if(buffer->bufsize<size) { delete(buffer); buffer=new Abuffer("buffer", (size&1023)+4096); } buffer->clear(); { byte data[1024]; while(size) { int s=mini(size, sizeof(data)); f->read(data, s); buffer->write(data, s); size-=s; } } strcpy(this->filename, filename); status|=statusSTOR; start(); } section.leave(); return r; }
int cal(int w,int h){ if(v[w][h]) return dp[w][h]; v[w][h]=1; int i,j,k,l,ret=w*h; for(i=1;i<=n;i++){ if(nodes[i].wd>w||nodes[i].hgt>h) continue; ret=mini(ret,cal(w-nodes[i].wd,nodes[i].hgt)+cal(w,h-nodes[i].hgt)); ret=mini(ret,cal(nodes[i].wd,h-nodes[i].hgt)+cal(w-nodes[i].wd,h)); } return dp[w][h]=ret; }
unsigned long usec_delay_between_polls() const { unsigned long readback_delay = ULONG_MAX; if (this->readback_time_usec > 0) { // How long until the readback? long long now = get_time(); if (now >= this->readback_time_usec) { // Oops, it already passed! Return something tiny. readback_delay = 1000; } else { readback_delay = (unsigned long)(this->readback_time_usec - now); } } unsigned long polling_delay = ULONG_MAX; if (polling_due_to_readable_fd) { // We're in polling mode // Don't return a value less than our polling interval polling_delay = NAMED_PIPE_FLASH_DURATION_USEC; } // Now return the smaller of the two values // If we get ULONG_MAX, it means there's no more need to poll; in that case return 0 unsigned long result = mini(readback_delay, polling_delay); if (result == ULLONG_MAX) { result = 0; } return result; }
// 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; }
int max(char board[][7], int depth, int alpha, int beta) { if(depth==0) { return appx_score(board); } else if(check_win(board)==1) return -100000-depth; else if(check_win(board)==2) return 0; else { int temp=0, ctr=0; int col_order[7]={3,2,4,1,5,0,6}; int score_order[7]={-100000, -100000, -100000, -100000, -100000, -100000, -100000}; for(int i=0; i<7; i++) { if(is_free(i, board)) { update_board(i+1, 'c', board); score_order[ctr]=appx_score(board); col_order[ctr]=i; update_board(i+1, 'a', board); ctr=ctr+1; } } for(int x=0; x<ctr; x++) { for(int y=0; y<ctr-x-1; y++) { if(score_order[y]<score_order[y+1]) { int temp2 = col_order[y+1]; int temp1 = score_order[y+1]; col_order[y+1] = col_order[y]; col_order[y] = temp2; score_order[y+1] = score_order[y]; score_order[y] = temp1; } } } for(int j=0; j<ctr; j++) { if(alpha<beta) { update_board(col_order[j]+1, 'c', board); temp=mini(board, depth-1, alpha, beta); if(temp>alpha) alpha=temp; update_board(col_order[j]+1, 'a', board); } else return alpha; } return alpha; //beta becomes alpha } }
bool Asnap::sequence(int nctrl, float value) { ipos=(int)value; ipos=maxi(mini(ipos, 15), 0); ctrlPaint=true; father->notify(this, nyCHANGE); return true; }
void Asnap::set(int v) { ipos=maxi(mini(v, 15), 0); if(defpos==-1) defpos=ipos; control->set(Acontrol::KEY, (float)ipos); repaint(); }
void Awmp::action(double time, double dtime, double beat, double dbeat) { AwmpBack *back=(AwmpBack *)this->back; Abitmap *b=back->out->getBitmap(); Asample *in=back->in; TimedLevel tl; if(in->getCountConnect()) { sword smp[2*1024]; sword smp2[2][1024]; double freq[2][1024]; int avaible; int sget; int i; in->enter(__FILE__,__LINE__); avaible=in->avaible(); avaible-=in->skip(maxi((avaible-4096)>>1, 0)); sget=in->getBuffer(smp, NULL, NULL, NULL, 1024); in->leave(); for(i=0; i<1024; i++) { int n=i<<1; tl.waveform[0][i]=((smp[n])>>8)+128; tl.waveform[1][i]=((smp[n+1])>>8)+128; smp2[0][i]=smp[n]; smp2[1][i]=smp[n+1]; } Asample::calcFFT(smp2[0], freq[0]); Asample::calcFFT(smp2[1], freq[1]); for(i=0; i<1024; i++) { int n=i>>2; int p=i&3; double m=(0.5+sqrt((float)i)); double m0=(4.0-(double)p)*0.25; double m1=1.0-m0; tl.frequency[0][i]=(byte)(mini((freq[0][n]*m0+freq[0][n+1]*m1)*m, 255.0)); tl.frequency[1][i]=(byte)(mini((freq[0][1]*m0+freq[1][n+1]*m1)*m, 255.0)); } tl.timeStamp=0; }
void Map::BBexp(int i, int j, int puiss) { int X(0); bool u; (*(carte[i][j])).pObjet(0); (*((*(bcarte[i][j])).getPerso())).bexp(); if (((*J1).getID() != 0) && ((*J1).geti() == i) && ((*J1).getj() == j)){ (*J1).pervie(); } if (((*J2).getID() != 0) && ((*J2).geti() == i) && ((*J2).getj() == j)){ (*J2).pervie(); } if (((*J3).getID() != 0) && ((*J3).geti() == i) && ((*J3).getj() == j)){ (*J3).pervie(); } if (((*J4).getID() != 0) && ((*J4).geti() == i) && ((*J4).getj() == j)){ (*J4).pervie(); } u = true; X = i+1; while (u && (X < mini(12, (i + 1 + puiss)))) { u = detruire(X, j); (*hori).render(X*45, j*45, *gRenderer); X += 1; } u = true; X = i-1; while (u && (X > maxi(-1, (i - puiss-1)))) { u = detruire(X, j); (*hori).render(X * 45, j * 45, *gRenderer); X =X -1; } u = true; X = j+1; while (u && (X < mini(12, (j+ 1 + puiss)))) { u = detruire(i, X); (*vert).render(i * 45, X * 45, *gRenderer); X += 1; } u = true; X = j-1; while (u && (X >maxi(-1, (j - puiss-1)))) { u = detruire(i, X); (*vert).render(i * 45, X * 45, *gRenderer); X = X-1; } }