void solve(){ int i,j,x; for(i=1;i<=n;++i){f[i]=i-1;used[i]=false;} for(i=0;i<m;++i){ if(used[p[i]]){ x=find(p[i]); use(x+1,i+1); uni(x,x+1); if(used[x+2])uni(x+1,x+2); }else{ use(p[i],i+1); uni(p[i],p[i]+1); if(used[p[i]-1])uni(p[i]-1,p[i]); } } inittree(); memset(r,0,sizeof(r)); for(i=n;i>0;--i){ if(used[i]){ for(j=head[find(i)];j;j=next[j]) r[remove(p[j-1])]=j; while(used[i] && i)--i; } } for(i=n;i;--i)if(r[i])break; printf("%d\n",i); for(j=1;j<=i;++j){ if(j>1)printf(" "); printf("%d",r[j]); } printf("\n"); }
/* This is the function called from R or S: */ static void Trunmed(R_xlen_t n,/* = length(data) */ int k,/* is odd <= n */ const double *data, double *median, /* (n) */ int *outlist,/* (k+1) */ int *nrlist,/* (2k+1) */ double *window,/* (2k+1) */ int end_rule, int print_level) { int k2 = (k - 1)/2, /* k == *kk == 2 * k2 + 1 */ j; inittree (n, k, k2, data, /* initialize these: */ window, (int *)outlist, (int *)nrlist, (int) print_level); /* window[], outlist[], and nrlist[] are all 1-based (indices) */ if(print_level) { Rprintf("After inittree():\n"); R_PRINT_4vec(); } runmedint(n, k, k2, data, median, window, outlist, nrlist, end_rule, print_level); }
int main () { tree *t; t=inittree(); bianli(t); return 0; }
static Bool Init(ModeInfo * mi) { int i; firestruct *fs = &fire[MI_SCREEN(mi)]; /* default settings */ fs->eject_r = 0.1 + NRAND(10) * 0.03; fs->dt = 0.015; fs->eject_vy = 4; fs->eject_vl = 1; fs->ridtri = 0.1 + NRAND(10) * 0.005; fs->maxage = 1.0 / fs->dt; vinit(fs->obs, DEF_OBS[0], DEF_OBS[1], DEF_OBS[2]); fs->v = 0.0; fs->alpha = DEF_ALPHA; fs->beta = DEF_BETA; /* initialise texture stuff */ if (do_texture) inittextures(mi); else { fs->ttexture = (XImage*) NULL; fs->gtexture = (XImage*) NULL; } if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tnum_part=%d\n\ttrees=%d\n\tfog=%s\n\tshadows=%s\n\teject_r=%.3f\n\tridtri=%.3f\n", MI_NAME(mi), fs->np, fs->num_trees, fs->fog ? "on" : "off", fs->shadows ? "on" : "off", fs->eject_r, fs->ridtri); } /* initialise particles and trees */ for (i = 0; i < fs->np; i++) { setnewpart(fs, &(fs->p[i])); } if (fs->num_trees) if (!inittree(mi)) { return False; } /* if no fire particles then initialise rain particles */ if (!fs->np) { vinit(fs->min,-7.0f,-0.2f,-7.0f); vinit(fs->max,7.0f,8.0f,7.0f); for (i = 0; i < NUMPART; i++) { setnewrain(fs, &(fs->r[i])); } } return True; }
/* this is a recursive routine. */ int isrt(treefmt *node, double key) { int rslt; treefmt *newnode; if (key < node->key) { if (node->left != NULL) { rslt = isrt(node->left, key); return(rslt); } /* not leaf node left */ else { newnode = (treefmt *) inittree(); newnode->key = key; node->left = (treefmt *) newnode; return(0); } /* else leaf node less than */ } /* key less than */ else if (key > node->key) { if (node->rght != NULL) { rslt = isrt(node->rght, key); return(rslt); } /* not leaf node rght */ else { newnode = (treefmt *) inittree(); newnode->key = key; node->rght = (treefmt *) newnode; return(0); } /* else leaf node greater than */ } /* key greater than */ return(-1); /* duplicate key */ } /* isrt */
int build(chess *q, tree **t, int start) { //printw("Entered build"); //getch(); tree *p; int i, k; if(q->depth >= DEPTH) { //printw("Ent if q->depth"); //getch(); push(q, &q->s, p->loc, &p->loc[4]); move1(q, p->loc, &p->loc[4], "exp"); q->depth--; k = eval(q); undoredo(q, "undowithoutredo"); return k; } inittree(t); p = *t; initmoveslist(p); generatemoves(q, p); printmlist(p); insertnodes(&p, p->ml, q->depth); if(start == 0) { start = 1; } else { push(q, &q->s, p->loc, &p->loc[4]); move1(q, p->loc, &p->loc[4], "exp"); } for(i = 0; i < p->numchildren; i++) { q->depth++; p->children[i]->score = build(q, &p->children[i], start); if((q->depth % 2) == 1) { p->score = min(p->score, p->children[i]->score); } else { p->score = max(p->score, p->children[i]->score); } } p->score = -p->score; if(p->parent == NULL) { return p->score; } undoredo(q, "undowithoutredo"); q->depth--; }
int main(int argc, char *argv[]) { FILE *srcfile, *destfile; char *end, *sfile; int i, passflags, codelen, nfiles; printf("6502 Cross Assembler, version 0.7\n"); inittree(); codebuf=(unsigned char *)malloc(512); i=1; codeorig=0; machine=0; passflags=0; sfile=NULL; while(*argv[i]=='-' && i<argc) { switch(argv[i][1]) { case 'o': codeorig=strtol(argv[i+1], &end, 16); i++; break; case 'l': passflags|=1; break; case 't': passflags|=4; break; case 's': sfile=argv[i]+2; break; case 'm': switch(argv[i][2]) { case 'c': machine=8; break; case 'r': machine=16; break; default: machine=0; } break; } i++; } codelen=0; nfiles=0; if(sfile != NULL) listfile=fopen(sfile, "w"); else listfile=stdout; while(i<argc) { printf("Assembling file %s:\n", argv[i]); srcfile=fopen(argv[i++], "r"); codelen=processfile(srcfile, codelen, passflags); fclose(srcfile); nfiles++; } destfile=fopen("asmout", "wb"); fwrite(codebuf, sizeof(unsigned char), destadr, destfile); fclose(destfile); printf("Assembly complete, processed %d files, output size %d bytes\n", nfiles, codelen); deletetree(symboltab); return(0); }
static Bool Init(ModeInfo * mi) { int i; firestruct *fs = &fire[MI_SCREEN(mi)]; /* default settings */ fs->eject_r = 0.1 + NRAND(10) * 0.03; fs->dt = 0.015; fs->eject_vy = 4; fs->eject_vl = 1; fs->ridtri = 0.1 + NRAND(10) * 0.005; fs->maxage = 1.0 / fs->dt; vinit(fs->obs, DEF_OBS[0], DEF_OBS[1], DEF_OBS[2]); fs->v = 0.0; fs->alpha = DEF_ALPHA; fs->beta = DEF_BETA; /* initialise texture stuff */ if (do_texture) inittextures(mi); else { fs->ttexture = (XImage*) NULL; fs->gtexture = (XImage*) NULL; } if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tnum_part=%d\n\ttrees=%d\n\tfog=%s\n\tshadows=%s\n\teject_r=%.3f\n\tridtri=%.3f\n", MI_NAME(mi), fs->np, fs->num_trees, fs->fog ? "on" : "off", fs->shadows ? "on" : "off", fs->eject_r, fs->ridtri); } glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); /* makes particles blend with background */ if (!MI_IS_WIREFRAME(mi)||(!fs->np)) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } /* fog stuff */ glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_EXP); glFogfv(GL_FOG_COLOR, fogcolor); glFogf(GL_FOG_DENSITY, 0.03); glHint(GL_FOG_HINT, GL_NICEST); /* initialise particles and trees */ for (i = 0; i < fs->np; i++) { setnewpart(fs, &(fs->p[i])); } if (fs->num_trees) if (!inittree(mi)) { return False; } /* if no fire particles then initialise rain particles */ if (!fs->np) { vinit(fs->min,-7.0f,-0.2f,-7.0f); vinit(fs->max,7.0f,8.0f,7.0f); for (i = 0; i < NUMPART; i++) { setnewrain(fs, &(fs->r[i])); } } return True; }
/* * Yymain initializes each of the utility * clusters and then starts the processing * by calling yyparse. */ yymain() { #ifdef OBJ /* * initialize symbol table temp files */ startnlfile(); #endif /* * Initialize the scanner */ #ifdef PXP if (bracket == 0) { #endif if (getline() == -1) { Perror(filename, "No lines in file"); pexit(NOSTART); } #ifdef PXP } else yyline = 0; #endif #ifdef PI # ifdef OBJ magic(); # endif OBJ #endif line = 1; errpfx = 'E'; /* * Initialize the clusters * initstring(); */ inithash(); inittree(); #ifdef PI initnl(); #endif /* * Process the input */ yyparse(); #ifdef PI # ifdef OBJ /* * save outermost block of namelist */ savenl(NLNIL); magic2(); # endif OBJ # ifdef DEBUG dumpnl(NLNIL); # endif #endif #ifdef PXP prttab(); if (onefile) { extern int outcol; if (outcol) pchr('\n'); flush(); if (eflg) { writef(2, "File not rewritten because of errors\n"); pexit(ERRS); } (void) signal(SIGHUP, SIG_IGN); (void) signal(SIGINT, SIG_IGN); copyfile(); } #endif pexit(eflg ? ERRS : AOK); }
int main(int ac,char **av) { int i; fprintf(stderr,"Fire V1.5\nWritten by David Bucciarelli ([email protected])\n"); /* Default settings */ WIDTH=640; HEIGHT=480; np=800; eject_r=0.1; dt=0.015; eject_vy=4; eject_vl=1; shadows=1; ridtri=0.1; maxage=1.0/dt; if(ac==2) np=atoi(av[1]); if(ac==4) { WIDTH=atoi(av[2]); HEIGHT=atoi(av[3]); } glutInitWindowPosition(0,0); glutInitWindowSize(WIDTH,HEIGHT); glutInit(&ac,av); glutInitDisplayMode(GLUT_RGB|GLUT_DEPTH|GLUT_DOUBLE); glutCreateWindow("Fire"); reshape(WIDTH,HEIGHT); inittextures(); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_FOG); glFogi(GL_FOG_MODE,GL_EXP); glFogfv(GL_FOG_COLOR,fogcolor); glFogf(GL_FOG_DENSITY,0.1); #ifdef FX glHint(GL_FOG_HINT,GL_NICEST); #endif p=malloc(sizeof(part)*np); for(i=0;i<np;i++) setnewpart(&p[i]); inittree(); glutKeyboardFunc(key); glutSpecialFunc(special); glutDisplayFunc(drawfire); glutIdleFunc(drawfire); glutReshapeFunc(reshape); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
int main(int argc, char* argv[]) { // initialise random Random::Random(); int ncycle = 10; int burnin = 100; int every = 10; int until = 1000; int mlsize = -1; int keep = 0; string datafile = ""; string initfile = ""; string treefile = ""; string name = ""; string path = "./"; string prepath = ""; string directory = ""; RRMode rr = gtr; RASMode ras = gam; int discrate = 0; // 0 : continuous int empfreq = 0; // 1 : global freq, 2: site specific freq int ncat = 1; // 0 : cat, -1 max, otherwise, fixed number of modes int statcenter = 1; int qmode = 0; // 0 : serial submission // 1 : parallel submission // 2 : qsub submission // 3 : qprep submission // read arguments try { if (argc == 1) { throw(0); } int i = 1; while (i < argc) { string s = argv[i]; if (s == "-d") { i++; datafile = argv[i]; } else if (s == "-t") { i++; treefile = argv[i]; } else if (s == "-i") { i++; initfile = argv[i]; } else if (s == "-keep") { keep = 1; } else if (s == "-poisson") { rr = poisson; } else if (s == "-jtt") { rr = jtt; } else if (s == "-wag") { rr = wag; } else if (s == "-gtr") { rr = gtr; } else if (s == "-empfreq") { empfreq = 1; } else if (s == "-siteempfreq") { empfreq = 2; } else if (s == "-uni") { ras = uni; } else if (s == "-gamma") { ras = gam; } else if (s == "-invgamma") { ras = invgam; } else if (s == "-discrate") { discrate = 4; i++; string temp = argv[i]; if (IsInt(temp)) { discrate = Int(temp); } else { i--; } } else if (s == "-cat") { ncat = 0; } else if (s == "-max") { ncat = -1; } else if (s == "-ncat") { i++; ncat = atoi(argv[i]); } else if (s == "-statfree") { statcenter = 1; } else if (s == "-statflat") { statcenter = 0; } else if (s == "-mlsize") { i++; mlsize = atoi(argv[i]); } else if (s == "-ncycle") { i++; ncycle = atoi(argv[i]); } else if (s == "-p") { i++; path = argv[i]; } else if ((s == "-qsub") || (s == "-qprep")) { if (s == "-qsub") { qmode = 2; } if (s == "-qprep") { qmode = 3; } i++; prepath = argv[i]; i++; directory = argv[i]; } else if (s == "-bg") { qmode = 1; } else if ( (s == "-x") || (s == "-extract") ) { i++; s = argv[i]; if (! IsInt(s)) { throw(0); } burnin = atoi(argv[i]); i++; s = argv[i]; if (IsInt(s)) { every = atoi(argv[i]); i++; s = argv[i]; if (IsInt(s)) { until = atoi(argv[i]); } else { i--; } } else { i--; } } else { if (i != (argc -1)) { throw(0); } name = argv[i]; } i++; } if (name == "") { cerr << "give it a name ! \n"; throw(0); } } catch(...) { cerr << "ml : wrong command\n"; exit(1); } if (mlsize == -1) { mlsize = until; } ofstream* qsub_os = 0; if (qmode > 1) { qsub_os = new ofstream((name + ".qsub").c_str()); } if ((treefile == "") && (initfile == "") && (datafile == "")) { if (qmode>1) { path = prepath + directory; } Chain chain(name, 0, path); chain.ML(ncycle, burnin, every, until, mlsize, keep); exit(1); } int Ntree = 1; Tree* tree = 0; if (treefile == "") { // assumes only one tree; but should be specified by the initfile if (initfile == "") { cerr << "error: should specify a tree\n"; exit(1); } } else { ifstream is(treefile.c_str()); is >> Ntree; tree = new Tree[Ntree]; for (int n=0; n<Ntree; n++) { tree[n].ReadFromStream(is, 1); } } MCParameters* mParam = new MCParameters(); if (datafile != "") { mParam->ReadDataFromFile(datafile); } if (initfile != "") { mParam->InitFromFile(initfile); } else { mParam->Init(rr,empfreq, ncat, statcenter, ras, discrate); } if (! mParam->DataOK) { cerr << "error: should specify a datafile\n"; exit(1); } if (! Ntree) { string currentname = name; if (qmode == 0) { Chain chain(mParam, currentname, path); chain.ML(ncycle, burnin, every, until, mlsize, keep); } else if (qmode == 1) { Chain chain(mParam, currentname, path); ostringstream launch; launch << "../ml "; if (path != "./") { launch << "-p " << path << ' '; } launch << "-x " << burnin << ' ' << every << ' ' << until; launch << " -ncycle " << ncycle << " -mlsize " << mlsize << ' '; if (keep) { launch << " -keep "; } launch << name << " &"; cerr << launch.str() << '\n'; system(launch.str().c_str()); } else { path = prepath + directory; Chain chain(mParam, currentname, path); ofstream os((currentname + ".launch").c_str()); os << prepath << "ml "; os << " -x " << burnin << ' ' << every << ' ' << until; os << " -ncycle " << ncycle; os << " -mlsize " << mlsize; if (keep) { os << " -keep "; } os << " -p " << path << ' ' << currentname << '\n'; (*qsub_os) << "qsub -o /baie/home/usertest/out -e /baie/home/usertest/err" << currentname << ".launch\n"; } } else { for (int n=0; n<Ntree; n++) { // prune the tree of all supernumerary species, and init the parameter Tree inittree(&tree[n]); TaxaParameters taxaparam(&inittree); for (int i=0; i<taxaparam.Ntaxa; i++) { string species = taxaparam.GetSpeciesName(i); int found = 0; int j=0; while ( (!found) && (j<mParam->Ntaxa) ) { found = (species == mParam->SpeciesNames[j]); j++; } if (! found) { // cerr << species << " not found : eliminate..."; // cerr.flush(); inittree.Eliminate(species); // cerr << "ok\n"; // cerr.flush(); } } inittree.Simplify(); // inittree.Phylip(cerr,0,0,1,0); // cerr << "\n"; // cerr.flush(); mParam->GetCurrentState()->SetTree(inittree); mParam->GetCurrentState()->SetBranchLengths(Random); ostringstream s; s << name << "_" << n; string currentname = s.str(); if (qmode == 0) { Chain chain(mParam, currentname, path); chain.ML(ncycle, burnin, every, until, mlsize, keep); } else if (qmode == 1) { Chain chain(mParam, currentname, path); ostringstream launch; launch << "../ml "; if (path != "./") { launch << "-p path "; } launch << "-x " << burnin << ' ' << every << ' ' << until; launch << " -ncycle " << ncycle << " -mlsize " << mlsize << ' '; if (keep) { launch << "-keep "; } launch << name << " &"; cerr << launch.str() << '\n'; cerr.flush(); system(launch.str().c_str()); } else { path = prepath + directory; Chain chain(mParam, currentname, path); ofstream os((currentname + ".launch").c_str()); os << prepath << "ml "; os << " -x " << burnin << ' ' << every << ' ' << until; os << " -ncycle " << ncycle; os << " -mlsize " << mlsize; if (keep) { os << " -keep "; } os << " -p " << path << ' ' << currentname << '\n'; (*qsub_os) << "qsub -e " << path << currentname << ".err -o " << path << currentname << ".out " << currentname << ".launch\n"; } } } if (qmode>1) { qsub_os->close(); string chmod = "chmod +x " + name + ".qsub"; system(chmod.c_str()); } if (qmode == 2) { string submit = "./" + name + ".qsub"; system(submit.c_str()); } }
int main(int argc, char **argv) { int sz; /* number of normal numbers to produce */ unsigned int i; /* loop countedr */ double mean; /* mean of the normal distribution */ double stdev; /* standard deviation */ rufmt *ru; /* erandu structure */ actfmt *aa; /* Box-Muller transform structure */ treefmt *root; /* root node of the tree */ if (argc != 4) putstx(*argv); /* must have 3 arguments */ mean = atof(*(argv+1)); /* sample mean */ if (mean < -1000.0) { fprintf(stderr,"Mean parameter %s " "is too small\n", *(argv+1)); putstx(*argv); exit(1); } /* mean too small */ if (mean > 1000.0) { fprintf(stderr,"Mean parameter %s " "is too large\n", *(argv+1)); putstx(*argv); exit(1); } /* mean too large */ stdev = atof(*(argv+2)); /* standard deviation */ if (stdev < 0) { fprintf(stderr,"Stdev parameter %s " "is too small\n", *(argv+2)); putstx(*argv); exit(1); } /* stdev too small */ if (stdev > 1000) { fprintf(stderr,"Stdev parameter %s " "is too large\n", *(argv+2)); putstx(*argv); exit(1); } /* stdev too large */ sz = atoi(*(argv+3)); /* population size */ if (sz < 36) { fprintf(stderr,"Size parameter %s " "is too small\n", *(argv+3)); putstx(*argv); exit(1); } /* sz too small */ if (sz > 100000) { fprintf(stderr,"Size parameter %s " "is too large\n", *(argv+3)); putstx(*argv); exit(1); } /* sz too large */ ru = (rufmt *) eranduinit(); /* initialize erandu to date/time */ /* allocate memory for the actual sample structure */ aa = (actfmt *) malloc(sizeof(actfmt)); if (aa == NULL) { fprintf(stderr,"main: out of memory " "allocating the aa structure\n"); exit(1); } /* out of memory */ root = (treefmt *) inittree(); /**********************************/ /* create n samples */ /**********************************/ i = sz >> 1; while (i--) { boxmul(ru,mean,stdev,aa); /* Box-Muller Transform */ /* the Box-Muller Transform gives two numbers n1 and n2 */ /* tally by number to create histogram */ isrt(root,aa->n1); /* insert n1 into the tree */ isrt(root,aa->n2); /* insert n2 into the tree */ } /* for each sample */ /**********************************/ /* traverse tree */ /**********************************/ if (root->rght != NULL) traverse(root->rght); /************************************************************/ /* free memory */ /************************************************************/ if (root->rght != NULL) rmtree(root->rght); free(root); free(aa); free(ru->state); free(ru); return(0); } /* main */
int main(int ac, char **av) { int i; fprintf(stderr, "Fire V1.5\nWritten by David Bucciarelli ([email protected])\n"); /* Default settings */ np = 800; eject_r = -0.65; dt = 0.015; eject_vy = 4; eject_vl = 1; shadows = 1; ridtri = 0.25; maxage = 1.0 / dt; if (ac == 2) { np = atoi(av[1]); if (np <= 0 || np > 1000000) { fprintf(stderr, "Invalid input.\n"); exit(-1); } } if (ac == 4) { WIDTH = atoi(av[2]); HEIGHT = atoi(av[3]); } glutInitWindowSize(WIDTH, HEIGHT); glutInit(&ac, av); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); if (!(win = glutCreateWindow("Fire"))) { fprintf(stderr, "Error opening a window.\n"); exit(-1); } reshape(WIDTH, HEIGHT); inittextures(); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_EXP); glFogfv(GL_FOG_COLOR, fogcolor); glFogf(GL_FOG_DENSITY, 0.1); assert(np > 0); p = (part *) malloc(sizeof(part) * np); assert(p); for (i = 0; i < np; i++) setnewpart(&p[i]); inittree(); glutKeyboardFunc(key); glutSpecialFunc(special); glutDisplayFunc(drawfire); glutIdleFunc(idle); glutReshapeFunc(reshape); glutMainLoop(); return (0); }