int course(int i, int j) { int u, t, k; if (i == j) { com[i][j] = 0; return 0; } if (i == j - i) { com[i][j] = i; return (r[i] * r[i+1] * r[i+2]); } u = course(i, i) + course(i + 1, j) + r[i] * r[i + 1] * r[j + 1]; com[i][j] = i; for (k = i + 1; k < j; k ++) { t = course(i, k) + course(k + 1, j) + r[i] * r[k + 1] * r[j + 1]; if (t < u) { u = t; com[i][j] = k; } } return u; }
inline return_type apply(Point const& p, PointOfSegment const& sp1, PointOfSegment const& sp2) const { // http://williams.best.vwh.net/avform.htm#XTE return_type d1 = m_strategy.apply(sp1, p); return_type d3 = m_strategy.apply(sp1, sp2); if (geometry::math::equals(d3, 0.0)) { // "Degenerate" segment, return either d1 or d2 return d1; } return_type d2 = m_strategy.apply(sp2, p); return_type crs_AD = course(sp1, p); return_type crs_AB = course(sp1, sp2); return_type crs_BA = crs_AB - geometry::math::pi<return_type>(); return_type crs_BD = course(sp2, p); return_type d_crs1 = crs_AD - crs_AB; return_type d_crs2 = crs_BD - crs_BA; // d1, d2, d3 are in principle not needed, only the sign matters return_type projection1 = cos( d_crs1 ) * d1 / d3; return_type projection2 = cos( d_crs2 ) * d2 / d3; #ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK std::cout << "Course " << dsv(sp1) << " to " << dsv(p) << " " << crs_AD * geometry::math::r2d << std::endl; std::cout << "Course " << dsv(sp1) << " to " << dsv(sp2) << " " << crs_AB * geometry::math::r2d << std::endl; std::cout << "Course " << dsv(sp2) << " to " << dsv(p) << " " << crs_BD * geometry::math::r2d << std::endl; std::cout << "Projection AD-AB " << projection1 << " : " << d_crs1 * geometry::math::r2d << std::endl; std::cout << "Projection BD-BA " << projection2 << " : " << d_crs2 * geometry::math::r2d << std::endl; #endif if(projection1 > 0.0 && projection2 > 0.0) { return_type XTD = m_radius * geometry::math::abs( asin( sin( d1 / m_radius ) * sin( d_crs1 ) )); #ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK std::cout << "Projection ON the segment" << std::endl; std::cout << "XTD: " << XTD << " d1: " << d1 << " d2: " << d2 << std::endl; #endif // Return shortest distance, projected point on segment sp1-sp2 return return_type(XTD); } else { #ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK std::cout << "Projection OUTSIDE the segment" << std::endl; #endif // Return shortest distance, project either on point sp1 or sp2 return return_type( (std::min)( d1 , d2 ) ); } }
int main() { memset(r, 0, sizeof(int) * 100); memset(com, 0, sizeof(int) * 100 * 100); int n, i, j; printf("How many matrixes?"); scanf("%d", &n); printf("How size every matrixe?"); for (i = 1; i <= n + 1; i ++) { scanf("%d", &r[i]); } printf("The least calculate quantity: %d", course(1, n)); for (i = 1; i <= n; i ++) { printf("\n"); for (j = 1; j <= n; j ++) { printf("%d ", com[i][j]); } } return 0; }
bool JsonTranslator::read_file() { QFile loadFile("../json_test.json"); if (!loadFile.open(QIODevice::ReadOnly)) { qWarning("Couldn't open file."); return false; } QByteArray saveData = loadFile.readAll(); QJsonDocument loadDoc(QJsonDocument::fromJson(saveData) ); QJsonObject root = loadDoc.object(); QMessageBox msgbox; QString simple = root["simpleString"].toString(); msgbox.setText(simple); msgbox.exec(); // read listOfVotelists QJsonArray jListOfVotelists = root["listOfVotelists"].toArray(); for (int listIndex = 0; listIndex < jListOfVotelists.size(); ++listIndex) { QJsonArray jVotelist = jListOfVotelists[listIndex].toArray(); std::list<QString> votelist; for (int voteIndex = 0; voteIndex < jVotelist.size(); ++voteIndex) { QString vote = jVotelist[voteIndex].toString(); votelist.push_back(vote); } this->listOfVotelists.push_back(votelist); } // read listOfCoursesAndMaxMembers QJsonArray jListOfCoursesAndMaxMembers = root["listOfCoursesAndMaxMembers"].toArray(); for (int listIndex = 0; listIndex < jListOfCoursesAndMaxMembers.size(); ++listIndex) { QJsonObject jCourse = jListOfCoursesAndMaxMembers[listIndex].toObject(); QString courseName = jCourse.keys()[0]; unsigned maxMembers = jCourse.value(courseName).toInt(); std::tuple<QString, unsigned> course (courseName, maxMembers); this->listOfCoursesAndMaxMembers.push_back(course); } return true; }
decart_position ctrl::get_local_position() const { FIXME(Oooooooooooooo) geo_base_3 base = ::get_base(); return decart_position(base(geo_point_3(pos(),0)),cg::cpr(course(),0,0)); };
void TCXParser::courses() { while (_reader.readNextStartElement()) { if (_reader.name() == "Course") { _tracks.append(TrackData()); course(_tracks.back()); } else _reader.skipCurrentElement(); } }
bool to_course( const std::string& line, course& c ) { std::istringstream stm(line) ; if( std::getline( stm, c.course_name, delimiter ) && std::getline( stm, c.course_code, delimiter ) && std::getline( stm, c.number_of_credits, delimiter ) && std::getline( stm, c.professor_name, delimiter ) ) return true ; c = course() ; return false ; }
inline return_type apply(Point const& p, PointOfSegment const& sp1, PointOfSegment const& sp2) const { // http://williams.best.vwh.net/avform.htm#XTE return_type d1 = m_strategy.apply(sp1, p); // Actually, calculation of d2 not necessary if we know that the projected point is on the great circle... return_type d2 = m_strategy.apply(sp2, p); return_type crs_AD = course(sp1, p); return_type crs_AB = course(sp1, sp2); return_type XTD = m_radius * geometry::math::abs(asin(sin(d1 / m_radius) * sin(crs_AD - crs_AB))); #ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK std::cout << "Course " << dsv(sp1) << " to " << dsv(p) << " " << crs_AD * geometry::math::r2d << std::endl; std::cout << "Course " << dsv(sp1) << " to " << dsv(sp2) << " " << crs_AB * geometry::math::r2d << std::endl; std::cout << "XTD: " << XTD << " d1: " << d1 << " d2: " << d2 << std::endl; #endif // Return shortest distance, either to projected point on segment sp1-sp2, or to sp1, or to sp2 return return_type((std::min)((std::min)(d1, d2), XTD)); }
Building::Building(double length, double width, double floorHeight) :length(length), width(width), floorHeight(floorHeight) { /*this->length = length; this->width = width; this->floorHeight = floorHeight;*/ //���������� ����� ����� � ����� � ���������� ��� � �������� ��� ��������� ���� � ���� ��� ����������� std::ifstream course("courseDollar.txt"); if (!course.is_open()) MessageBox(0, L"File Is Not Found", L"ERROR", MB_OK | MB_ICONERROR); else { char buff[5]; course >> buff; this->DOLLAR = (double)(atoi(buff) / 100); } }
size_t city::add_cars(size_t count) { flow_stat fs = this->_flow_stat; // start the flow to make rooms for the new cars this->flow_start(); size_t added_car = 0; // try as much as city can contain in one round count = min(count, this->get_size_streets() * 2 * CONST_STREET_LINES_NO - this->_car_no); FOR(i,0,count, ++) { size_t retry = 0; while(retry++ < this->_cluster_streets.size()) { // random select a cluster vector<street_ptr>& c = this->_cluster_streets[get_rand(0, this->_cluster_streets.size())]; // fail-safe if(!c.size()) continue; // random select a street street_ptr s = c[get_rand(0, c.size())]; // create a new car with unique ID car_ptr cc(new car("CAR-" + std::to_string(this->_car_no++))); // random direction cc->direction(course(int(round(frand())))); // random between [ 3.6km/h , 90km/h ] cc->max_speed(1 + get_rand(0, 25)); // try to bound the car if(s->bound_car(cc, inverse_course(cc->direction())) && ++added_car) break; else { this->_car_no--; } } } // resume the flow status switch(fs) { case STOP: this->flow_stop(); break; case PAUSE: this->flow_pause(); break; case START: break; default: throw runtime_error("invalid flow stat!"); } return added_car; }
Operation::Operation(){ /***课程列表初始化***/ ifstream fin; fin.open("Course.txt", ios::in); string cno, cname; float ccredit; while(!fin.eof()){ fin >> cno >> cname >> ccredit; Course course(cno, cname, ccredit); cvec.push_back(course); } fin.close(); /*初始化学生信息和选课成绩信息*/ fin.open("Student.txt", ios::in); while(!fin.eof()){ string sno, sname; string sex; Gender ssex; int sage, n; fin >> sno >> sname >> sex >> sage >> n; ssex = (sex == "男") ? MALE : FEMALE; Student stu(sno, sname, ssex, sage); string cno; float cscore; for(int i = 0; i < n; i++){ fin >> cno >> cscore; stu.score += cscore; vector<Course>::iterator it; for(it = cvec.begin(); it != cvec.end(); it++){ if(it->cno == cno){ stu.credit += it->ccredit; Score score(*it, stu, cscore); scvec.push_back(score); break; } } } if(sno.length() == 0 || sname.length() == 0) continue; svec.push_back(stu); } fin.close(); }
int report(hddm_x::HDDM &xrec) { hddm_x::CourseList course = xrec.courses(); int total_courses = course.size(); int total_enrolled = 0; int total_credits = 0; int total_passed = 0; hddm_x::CourseList::iterator iter; for (iter = course.begin(); iter != course.end(); ++iter) { if (iter->result().pass()) { if (iter->year() > 1992) { total_credits += iter->credits(); } ++total_passed; } } std::cout << course().name() << " enrolled in " << total_courses << " courses " << "and passed " << total_passed << " of them, " << std::endl << "earning a total of " << total_credits << " credits." << std::endl; return 0; }
int main() { std::ofstream ofs("exam2.hddm"); hddm_x::ostream ostr(ofs); hddm_x::HDDM xrec; // ostr.setCompression(hddm_x::k_z_compression); for (int n=0; n<1000000; ++n) { hddm_x::StudentList student = xrec.addStudents(); student().name("Humphrey Gaston"); hddm_x::EnrolledList enrolled = student().addEnrolleds(); enrolled().year(2005); enrolled().semester(2); hddm_x::CourseList course = enrolled().addCourses(3); course(0).credits(3); course(0).title("Beginning Russian"); course(0).addResults(); course(0).result().grade("A-"); course(0).result().pass(true); course(1).credits(1); course(1).title("Bohemian Poetry"); course(1).addResults(); course(1).result().grade("C"); course(1).result().pass(1); course(2).credits(4); course(2).title("Developmental Psychology"); course(2).addResults(); course(2).result().grade("B+"); course(2).result().pass(true); ostr << xrec; xrec.clear(); } ofs.close(); exit(0); // try reading it back in from the output file just written std::ifstream ifs("exam2.hddm"); hddm_x::istream istr(ifs); int count=0; while (ifs.good()) { istr >> xrec; if (count/100000*100000 == count) { std::cout << "event " << count << std::endl; report(xrec); } ++count; } std::cout << "finished after " << count << " events read." << std::endl; return 0; }
/** Periodic function */ void meteo_stick_periodic(void) { // Read ADC #ifdef MS_PRESSURE_SLAVE_IDX ads1220_periodic(&meteo_stick.pressure); #endif #ifdef MS_DIFF_PRESSURE_SLAVE_IDX ads1220_periodic(&meteo_stick.diff_pressure); #endif #ifdef MS_TEMPERATURE_SLAVE_IDX ads1220_periodic(&meteo_stick.temperature); #endif // Read PWM #ifdef MS_HUMIDITY_PWM_INPUT meteo_stick.humidity_period = pwm_input_period_tics[MS_HUMIDITY_PWM_INPUT]; meteo_stick.current_humidity = get_humidity(meteo_stick.humidity_period); #endif #if USE_MS_EEPROM if (meteo_stick.eeprom.data_available) { // Extract calibration data if (!mtostk_populate_cal_from_buffer(&meteo_stick.calib, (uint8_t *)(meteo_stick.eeprom.rx_buf + 3))) { // Extraction failed // Force number of calibration to 0 for all sensors int i; for (i = 0; i < MTOSTK_NUM_SENSORS; i++) { meteo_stick.calib.params[i].num_temp = 0; } } } else if (meteo_stick.eeprom.spi_trans.status == SPITransDone) { // Load reading request (reading 1Kb from address 0x0) eeprom25AA256_read(&meteo_stick.eeprom, 0x0, 1024); } #endif // Log data #if LOG_MS if (pprzLogFile != -1) { if (!log_ptu_started) { #if USE_MS_EEPROM if (meteo_stick.eeprom.data_available) { // Print calibration data in the log header sdLogWriteLog(pprzLogFile, "# Calibration data (UUID: %s)\n#\n", meteo_stick.calib.uuid); int i, j, k; for (i = 0; i < MTOSTK_NUM_SENSORS; i++) { sdLogWriteLog(pprzLogFile, "# Sensor: %d, time: %d, num_temp: %d, num_coeff: %d\n", i, meteo_stick.calib.params[i].timestamp, meteo_stick.calib.params[i].num_temp, meteo_stick.calib.params[i].num_coeff); if (meteo_stick.calib.params[i].timestamp == 0) { continue; // No calibration } for (j = 0; j < meteo_stick.calib.params[i].num_temp; j++) { sdLogWriteLog(pprzLogFile, "# Reference temp: %.2f\n", meteo_stick.calib.params[i].temps[j]); sdLogWriteLog(pprzLogFile, "# Coeffs:"); for (k = 0; k < meteo_stick.calib.params[i].num_coeff; k++) { sdLogWriteLog(pprzLogFile, " %.5f", meteo_stick.calib.params[i].coeffs[j][k]); } sdLogWriteLog(pprzLogFile, "\n"); } } sdLogWriteLog(pprzLogFile, "#\n"); sdLogWriteLog(pprzLogFile, "P(adc) T(adc) H(ticks) P_diff(adc) P(hPa) T(C) H(\%) CAS(m/s) FIX TOW(ms) WEEK Lat(1e7rad) Lon(1e7rad) HMSL(mm) GS(cm/s) course(1e7rad) VZ(cm/s)\n"); log_ptu_started = TRUE; } #else sdLogWriteLog(pprzLogFile, "P(adc) T(adc) H(ticks) P_diff(adc) P(hPa) T(C) H(\%) CAS(m/s) FIX TOW(ms) WEEK Lat(1e7rad) Lon(1e7rad) HMSL(mm) GS(cm/s) course(1e7rad) VZ(cm/s)\n"); log_ptu_started = TRUE; #endif } else {
//add course, parameter is name, or course object void CourseManager::addCourse(const std::string &name) { Course course(name); courseList.push_back(course); }
void CourseManager::AddCourseByName(std::string &name) { Course course(name); vecCourse_.push_back(course); }