double cal1(double len) { int i; double d1, d2, k, t1, tx, ty; d1 = len, d2 = dis(A, B); k = d1 / d2; M1.x = (B.x - A.x) * k + A.x; M1.y = (B.y - A.y) * k + A.y; t1 = len / P; double left, right, mid1, mid2; left = 0, right = dis(C, D); for (i = 1; i <= 100; i++) { mid1 = (2 * left + right) / 3; mid2 = (left + 2 * right) / 3; tx = cal2(mid1); ty = cal2(mid2); if (tx > ty) { left = mid1; } else { right = mid2; } } return t1 + cal2(left); }
void spfa() { int tem,i,state; queue<int>que; que.push(0); dis[0]=0; while(!que.empty()) { tem=que.front(); que.pop(); hash[tem]=0; for(i=1;i<=n;i++) { state=(tem|(1<<(i-1))); if(0 != ((1<<(i-1))&tem)) { continue; } if(dis[state] > dis[tem]+cal2(sum[tem],i)) { dis[state]=dis[tem]+cal2(sum[tem],i); pre[state]=i; if(0 == hash[state]) { hash[state]=1; que.push(state); } } else if(dis[state] == dis[tem]+cal2(sum[tem],i)) { if(i < pre[state]) { pre[state]=i; } } } } }
int main() { int i,k,f,g,l; scanf("%d",&test); for(i=0;i<test;i++) { style=i; out[i]=10000; scanf("%d %d",&m,&n); for(j=0;j<m;j++) scanf("%s",inp[j]); for(j=0;j<m;j++) { for(k=0;k<n;k++) { sub[j][k]=10000; if(inp[j][k]=='C') choc++; else if(inp[j][k]=='T') { sor[0]=j; sor[1]=k; } else if(inp[j][k]=='W') { tar[0]=j; tar[1]=k; } } } f=sor[0]; g=sor[1]; h=tar[0]; j=tar[1]; printf("%d\n",choc); chocSub=choc; chocBak=choc; sub[f][g]=0; cal2(f,g,0); choc=chocBak; sub[f][g]=0; cal1(f,g,0); choc=chocBak; sub[f][g]=0; cal3(f,g,0); choc=chocBak; sub[f][g]=0; cal4(f,g,0); printf("%d %d\n",sub[h][j],out[i]); for(j=0;j<m;j++) { for(k=0;k<n;k++) { printf("%d\t",sub[j][k]); sub[j][k]=10000; } printf("\n"); } choc=0; } return 0; }
int main(int argc,char** argv) { int x; while(scanf("%d",&x)!=EOF) { if(x<0) { printf("x shouled not less than 0\n"); } else { printf("cal(%d)=%d\tcal2(%d)=%d\n",x,cal(x),x,cal2(x)); } } return 0; }
void cal1(int f,int g,int side) { int i,k,bak; if(sub[f][g]<10000) bak=sub[f][g]; else bak=-1; if(chocSub!=choc) { chocSub=choc; for(i=0;i<m;i++) for(k=0;k<n;k++) if(i!=f || k!=g) sub[i][k]=10000; } printf("One %d %d %d %c %d\n",f,g,sub[f][g],inp[f][g],choc); if(inp[f+1][g]!='#' && f+1<m) { if(inp[f+1][g]=='C') { if(sub[f+1][g]==10000 && choc>0) choc--; sub[f+1][g]=sub[f][g]+1; if(chocSub!=choc) { cal1(f+1,g,1); if(bak>0) sub[f][g]=bak; cal2(f+1,g,1); if(bak>0) sub[f][g]=bak; cal3(f+1,g,1); if(bak>0) sub[f][g]=bak; cal4(f+1,g,1); } else { if(side==0) { cal1(f+1,g,1); if(bak>0) sub[f][g]=bak; cal2(f+1,g,1); if(bak>0) sub[f][g]=bak; cal3(f+1,g,1); if(bak>0) sub[f][g]=bak; cal4(f+1,g,1);} else if(side==1) { cal2(f+1,g,1); if(bak>0) sub[f][g]=bak; cal3(f+1,g,1); if(bak>0) sub[f][g]=bak; cal1(f+1,g,1); } else if(side==4) { cal2(f+1,g,1); if(bak>0) sub[f][g]=bak; cal3(f+1,g,1); if(bak>0) sub[f][g]=bak; cal4(f+1,g,1); } } } else if(inp[f+1][g]=='W') { if(choc==0 && sub[f+1][g]>sub[f][g]+1) { sub[f+1][g]=sub[f][g]+1; } else if(choc!=0) { sub[f+1][g]=sub[f][g]+1; cal1(f+1,g,1); if(bak>0) sub[f][g]=bak; cal2(f+1,g,1); if(bak>0) sub[f][g]=bak; cal3(f+1,g,1); if(bak>0) sub[f][g]=bak; cal4(f+1,g,1); } } else if(inp[f+1][g]=='.' && (sub[h][j]==10000 || choc!=0)) { sub[f+1][g]=sub[f][g]+1; cal1(f+1,g,1); if(bak>0) sub[f][g]=bak; cal2(f+1,g,1); if(bak>0) sub[f][g]=bak; cal3(f+1,g,1); if(bak>0) sub[f][g]=bak; cal4(f+1,g,1); } else if(inp[f+1][g]=='T') { sub[f+1][g]=sub[f][g]+1; cal1(f+1,g,1); if(bak>0) sub[f][g]=bak; cal2(f+1,g,1); if(bak>0) sub[f][g]=bak; cal3(f+1,g,1); if(bak>0) sub[f][g]=bak; cal4(f+1,g,1); } } if(out[style]>sub[h][j] && choc==0) out[style]=sub[h][j]; }
int calculate(int i, int door) { if (door == 1)return cal1(i); else if (door == 2)return cal2(i); }
int Calibration::read(QString filename) { std::ifstream fichier((char*)filename.toStdString().c_str(), std::ios::in); if (!fichier) { qWarning() << "Cannot read calibration file " << filename; return 0; } clear(); std::string ligne; // déclaration d'une chaîne qui contiendra la ligne lue unsigned int etape_calcul = 0; while(std::getline(fichier,ligne)) // tant que l'on arrive pas a la fin du fichier { // take ending off the line ligne.erase(ligne.find_last_not_of(" \n\r\t")+1); if(!ligne.empty()) { // pivot + focale + axis + ccd rotation if(ligne.size() == 91) { etape_calcul = 1; } // sources if(ligne.size() == 70) { etape_calcul = 2; } if(!ligne.empty()) { switch(etape_calcul) { case 1: { char *buffer1 = strdup((char*)ligne.c_str()); QString id_BCAM = QString::fromStdString(strtok(buffer1," ")); QString tps_calib = QString::fromStdString(strtok( NULL, " " )); char *x_pivot = strtok( NULL, " " ); char *y_pivot = strtok( NULL, " " ); char *z_pivot = strtok( NULL, " " ); char *x_axis = strtok( NULL, " " ); char *y_axis = strtok( NULL, " " ); char *z_axis = strtok( NULL, " " ); char *dist_ccd_pivot = strtok( NULL, " " ); char *ccd_rotation = strtok( NULL, " " ); Point3d pv(atof(x_pivot), atof(y_pivot), atof(z_pivot)); Point3d ax(atof(x_axis), atof(y_axis),atof(z_axis)); float focale = atof(dist_ccd_pivot); float angle_rotation = atof(ccd_rotation); Calib1 cal1(id_BCAM, tps_calib, pv, ax, focale, angle_rotation); add(cal1); } break; case 2: { char *buffer2 = strdup((char*)ligne.c_str()); QString id_BCAM_2 = QString::fromStdString(strtok(buffer2," ")); QString tps_calib_2 = QString::fromStdString(strtok( NULL, " " )); char *x1_flash = strtok( NULL, " " ); char *y1_flash = strtok( NULL, " " ); char *x2_flash = strtok( NULL, " " ); char *y2_flash = strtok( NULL, " " ); char *z_flash = strtok( NULL, " " ); Point3d spt1(atof(x1_flash), atof(y1_flash), atof(z_flash)); Point3d spt2(atof(x2_flash), atof(y2_flash), atof(z_flash)); Calib2 cal2(id_BCAM_2, spt1, spt2); add(cal2); } break; } } } } //affichage du contenu de la base de donnees qui contient le fichier de calibration /*for(int i=0; i<base_donnees.Get_liste_calib1().size(); i++) { base_donnees.Get_liste_calib1().at(i).Affiche(); } for(int j=0; j<base_donnees.Get_liste_calib2().size(); j++) { base_donnees.Get_liste_calib2().at(j).Affiche(); }*/ fichier.close(); this->filename = filename; return 1; }
bool Run_Test1(bool verbose, int *subtest, int *nsubtests) { // We have 5 subtests *nsubtests = 5; #ifdef VERBOSE if(verbose) { cout << "=================================================" << endl; cout << "Running Test 1" << endl; cout << "=================================================" << endl; } #endif // Create a list of ColorAttribute. ColorAttributeList cal; // Add some ColorAttribute to it. ColorAttribute c1(255, 0, 0), c2(255,255,0), c3(0, 255, 0), c4(0,0,255); if(verbose) cout << "Before 1st addition: " << cal << endl; cal.AddColorAttribute(c1); if(verbose) cout << "After 1st addition: " << cal << endl; cal.AddColorAttribute(c2); if(verbose) cout << "After 2nd addition: " << cal << endl; cal.AddColorAttribute(c3); if(verbose) cout << "After 3rd addition: " << cal << endl; cal.AddColorAttribute(c4); if(verbose) cout << "After 4th addition: " << cal << endl << endl; if(cal.GetNumColorAttributes() != 4) return false; // Test the copy constructor. *subtest = 2; ColorAttributeList cal2(cal); if(verbose) { cout << "Original:" << cal << endl; cout << "Copy:" << cal2 << endl << endl; } if(cal != cal2) return false; // Test ClearColorAttribute. *subtest = 3; if(verbose) cout << "Before clear:" << cal2 << endl; cal2.ClearColorAttributes(); if(verbose) cout << "After clear:" << cal2 << endl << endl; if(cal2.GetNumColorAttributes() != 0) return false; // Test RemoveColorAttribute. *subtest = 4; ColorAttributeList calRem(cal); if(verbose) cout << "Before removal:" << calRem << endl; bool retval = true; for(int i = 0; i < 4 && !retval; ++i) { calRem.RemoveColorAttribute(0); if(verbose) cout << calRem << endl; switch(i) { case 0: retval = (calRem[0] == c2); break; case 1: retval = (calRem[0] == c3); break; case 2: retval = (calRem[0] == c4); break; case 3: retval = true; break; } } if(verbose) cout << "After all removals: " << calRem << endl << endl; if(!retval) return false; // Try writing the ColorAttribute to a list and reading them back. *subtest = 5; BufferConnection buf; cal.Write(buf); ColorAttributeList reader; reader.Read(buf); if(verbose) { cout << "Writer: " << cal << endl; cout << "Reader: " << reader << endl; } if(!(cal == reader)) return false; return true; }