void trace_back(int i, int j, int s[][100]) { if(i==j) {printf("A%d",i);return;} printf("("); trace_back(i,s[i][j],s); printf(","); trace_back(s[i][j]+1, j, s); printf(")"); }
/* LAS-3377 data analysis */ int evt_chamb_las(){ double f1, f2; int i; chamber_p chamb; plane_p plane; ray_p ray; chamb = &las_vdc; ray = &chamb->ray; for(i=0; i<chamb->npl; i++){ plane = &chamb->plane[i]; chamb_clust(plane); chamb_drift(plane); chamb_pos(plane); } /* Temporary for E154 03-MAY-2006 */ i = chamb->npl; chamb->npl = 4; chamb_ray(chamb); chamb->npl = i; dr_set(LAS_RAYID,ray->rayid); dr_set(LAS_CHI2[0],chamb->chi2); dr_set(LAS_NCOMB[0],chamb->ncomb); if(ray->rayid==RAYID_NOERR){ /* trace-back by matrix (with the VDC coordingate space) */ dr_set(LAS_DP[0],trace_back(ray, las_xmat, n_las_xmat, 0)); dr_set(LAS_AI[0],trace_back(ray, las_amat, n_las_amat, 0)/1000.); dr_set(LAS_GRAD_X[0], ray->dir.x/ray->dir.z); dr_set(LAS_GRAD_Y[0], ray->dir.y/ray->dir.z); /* rotation of axes as z=central-ray */ ray_rotate_z(ray,dr_get(LAS_VDC_TILT[2])); ray_rotate_y(ray,dr_get(LAS_VDC_TILT[1])); ray_rotate_x(ray,dr_get(LAS_VDC_TILT[0])); /* output of tracking information */ if(las_n_outputray) chamb_outputray(chamb,&fd_las_outputray,FNAMLASRAY,&las_n_outputray); /* output of ray information */ dr_set(LAS_RAY_X[0], ray->org.x); dr_set(LAS_RAY_Y[0], ray->org.y); dr_set(LAS_RAY_TH[0],atan(ray->dir.x)); dr_set(LAS_RAY_PH[0],atan(ray->dir.y)); /* projection to virtual planes */ chamb_intersection(chamb); } return(0); }
vector<int> postorderTraversal(TreeNode *root) { vector<int> res; TreeNode dummy(INT_MIN); dummy.left = root; TreeNode *curr = &dummy; while (curr) { if (!curr->left) { curr = curr->right; } else { TreeNode *node = curr->left; while (node->right && node->right != curr) { node = node->right; } if (!node->right) { node->right = curr; curr = curr->left; } else { vector<int> v = trace_back(curr->left, node); res.insert(res.end(), v.begin(), v.end()); node->right = nullptr; curr = curr->right; } } } return res; }
int main() { int size[100], total, i=0, m[100][100], s[100][100],j; memset(m,0,sizeof(m)); memset(s,0,sizeof(s)); memset(size,0,sizeof(size)); printf("Please enter the number of matrix:\n"); scanf("%d", &total); printf("Please enter a series of number.\nThe first number is the row of the first matrix, others are column of each matrix respectively:\n"); while(i<=total) scanf("%d", &size[i++]); matrix_chain(size, total, m, s); printf("The result is:\n"); trace_back(1, total, s); printf(" %d\n", m[1][total]); printf("\n"); return 0; }
void __except_throw_func(const Type *type, Object obj, const char *file, const char *func, int line) { info_node *node; while (list != NULL && (list->caught == CAUGHT || list->status >= IN_FINALLY)) { if (list->next == NULL) trace_back(file, func, line); if (list->obj == obj) list->obj = NULL; pop_current(); } if (list == NULL) { fprintf(stderr, "Uncaught exception: in file '%s' in func '%s' at line '%d'\n\ (%s): '%s'\n", file, func, line, type->name, M(obj, toString)); __delete_func(obj, 0, 0); __exit_end_func(-1); exit(42); }
/* GR-3377 data analysis */ int evt_chamb_gr(){ int i; chamber_p chamb; plane_p plane; ray_p ray; ray_t ray2; double d; double shift; chamb = &gr_vdc; ray = &chamb->ray; if(!dr_exists(dr_get(GR_RAYID[0]))){ for(i=0; i<chamb->npl; i++){ plane = &chamb->plane[i]; chamb_clust(plane); chamb_drift(plane); chamb_pos(plane); } chamb_ray(chamb); dr_set(GR_RAYID,ray->rayid); dr_set(GR_CHI2[0],chamb->chi2); dr_set(GR_NCOMB[0],chamb->ncomb); if(ray->rayid==RAYID_NOERR){ // fprintf(stderr, "GRAD_X = %g\n", ray->dir.x); dr_set(GR_GRAD_X[0],ray->dir.x); dr_set(GR_GRAD_Y[0],ray->dir.y); /* rotation of axes as z=central-ray */ ray_rotate_z(ray,dr_get(GR_VDC_TILT[2])); ray_rotate_y(ray,dr_get(GR_VDC_TILT[1])); ray_rotate_x(ray,dr_get(GR_VDC_TILT[0])); /* output of tracking information */ if(gr_n_outputray) chamb_outputray(chamb,&fd_gr_outputray,FNAMGRRAY,&gr_n_outputray); /* output of ray information */ dr_set(GR_RAY_X[0], ray->org.x); dr_set(GR_RAY_Y[0], ray->org.y); dr_set(GR_RAY_TH[0],atan(ray->dir.x)); dr_set(GR_RAY_PH[0],atan(ray->dir.y)); } }else{ ray->org.x = dr_get(GR_RAY_X[0]); ray->org.y = dr_get(GR_RAY_Y[0]); ray->org.z = 0.0; ray->dir.x = tan(dr_get(GR_RAY_TH[0])); ray->dir.y = tan(dr_get(GR_RAY_PH[0])); ray->dir.z = 1.0; ray->rayid = dr_int(dr_get(GR_RAYID[0])); } if(ray->rayid==RAYID_NOERR){ /* projection to virtual planes */ chamb_intersection(chamb); if(dr_is_true(dr_get(ANALYZE_GR_MATRIX))){ /* trace-back by matrix x and y are in mm in the VDC cordinate system (GR_X[0] and GR_Y[0]) th and ph are in rad in the central ray cordinate system (GR_TH[0] and GR_PH[0]) */ ray2.org.x = dr_get(GR_X[0]); ray2.org.y = dr_get(GR_Y[0]); ray2.dir.x = dr_get(GR_TH[0]); ray2.dir.y = dr_get(GR_PH[0]); dr_set(GR_XC[0], trace_back(&ray2, gr_xmat, n_gr_xmat, 1)); dr_set(GR_AI[0], trace_back(&ray2, gr_amat, n_gr_amat, 1)); dr_set(GR_BI[0], trace_back(&ray2, gr_bmat, n_gr_bmat, 1)); dr_set(GR_YC[0], trace_back(&ray2, gr_ymat, n_gr_ymat, 1)); dr_set(GR_PHC[0],trace_back(&ray2, gr_phmat, n_gr_phmat, 1)); } } return(0); }
int main(int argn, char **argv) { uint32_t depend_id = 0; char *tail; static struct option long_options[] = { {"depend_id", 1, 0, 'd'}, {0, 0, 0, 0} }; xed_tables_init(); // The state of the machine -- required for decoding xed_state_t dstate; xed_state_zero(&dstate); xed_state_init(&dstate, XED_MACHINE_MODE_LEGACY_32, XED_ADDRESS_WIDTH_32b, XED_ADDRESS_WIDTH_32b); while (1) { int option_index = 0; int c = getopt_long(argn, argv, "d:", long_options, &option_index); if (c == -1) break; switch (c) { case 0: if (long_options[option_index].flag != 0) break; printf ("option %s", long_options[option_index].name); if (optarg) printf(" with arg %s", optarg); printf("\n"); break; case 'd': depend_id = strtol(optarg, &tail, 0); break; default: abort(); } } //trace_record_t rec; if(optind >= argn) { printf("usage: %s [-d id] trace_file\n", argv[0]); return -1; } FILE *fp = fopen(argv[optind++],"r"); if(!fp) { printf("cannnot open %s! errno=%d\n", argv[optind-1], errno); return -1; } if(depend_id == 0) print_all_records(fp); else trace_back(fp, depend_id); fclose(fp); return 0; }