-
第四章作业
include include include using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> intervals(n); for (int i = 0; i < n; ++i) { cin >> i -
算法第四章作业
1、 策略:将所有区间按右端点从小到大排序,然后依次检查每个区间;如果当前区间的左端点大于上一个选择的点,则在该区间的右端点放置一个新点。 证明:每次选择当前能覆盖最多未覆盖区间的点,即右端点最小的区间的最右端。由于按右端点排序后,该点能覆盖所有与之相交的区间,且是覆盖后续区间的最佳选择,因此该算法 -
算法第四章作业
1.贪心策略: 先将将所有的区间,按照区间的 右端点从小到大 的顺序进行排序 之后初始化:记录最后一个选中的点的位置为 −∞,选点的总数为 0。 依次遍历排序后的每一个区间: 如果当前区间的左端点>最后一个选中的点,就选择当前区间的右端点作为新的点,选点总数 + 1,同时更新最后一个选中的点为当前区 -
高级语言程序设计课程第十次个人作业
这个作业属于哪个课程:https://edu.cnblogs.com/campus/fzu/gjyycx 这个作业要求在哪里: https://edu.cnblogs.com/campus/fzu/gjyycx/homework/15596 学号:102500328 姓名:刘宇桓 编写一个程序,将一 -
算法第四章作业
区间选点问题:用最少的点覆盖所有区间。 贪心策略 1:将所有区间按右端点从小到大排序; 2:选择第一个区间的右端点作为第一个选点; 3:依次遍历后续区间,若当前区间的左端点大于已选的最后一个点,则选择当前区间的右端点作为新的选点,重复此过程直到覆盖所有区间。 贪心选择性质的证明 贪心选择性质:“每一 -
实验6
task4 源代码: #include <stdio.h> #define N 10 typedef struct { char isbn[20]; // isbn号 char name[80]; // 书名 char author[80]; // 作者 double sales_price; // -
实验6
实验任务1: 源代码: contestant.hpp: #pragma once #include <iomanip> #include <iostream> #include <string> struct Contestant { long id; // 学号 std::string name; -
高级语言程序设计课程第十次个人作业
这个作业属于哪个课程:https://edu.cnblogs.com/campus/fzu/gjyycx 这个作业要求在哪里: https://edu.cnblogs.com/campus/fzu/gjyycx/homework/15596 学号:102500411 姓名:陈鸿彬 作业内容 (1)编 -
实验六
实验任务一 源代码: #pragma once #include <iomanip> #include <iostream> #include <string> struct Contestant { long id; // 学号 std::string name; // 姓名 std::strin -
实验6
实验任务五 源代码: #include <stdio.h> #define N 10 typedef struct { char isbn[20]; char name[80]; char author[80]; double sales_price; int sales_count; } Book -
实验6
实验任务4 1 #include <stdio.h> 2 #define N 10 3 4 typedef struct { 5 char isbn[20]; // isbn号 6 char name[80]; // 书名 7 char author[80]; // 作者 8 double sale -
实验6
任务1:源代码: 1 #pragma once 2 #include <iomanip> 3 #include <iostream> 4 #include <string> 5 6 struct Contestant { 7 long id; // 学号 8 std::string name; // -
实验作业6
实验4 1 #include <stdio.h> 2 #define N 10 3 4 typedef struct { 5 char isbn[20]; // isbn号 6 char name[80]; // 书名 7 char author[80]; // 作者 8 double sales_ -
实验6
实验任务4 1 #include <stdio.h> 2 #define N 10 3 4 typedef struct { 5 char isbn[20]; // isbn号 6 char name[80]; // 书名 7 char author[80]; // 作者 8 double sale -
实验6
实验任务4 源代码 1 #include <stdio.h> 2 #define N 10 3 4 typedef struct { 5 char isbn[20]; 6 char name[80]; 7 char author[80]; 8 double sales_price; 9 int sa -
第四章作业
1.选点问题的贪心策略、证明及时间复杂度 “选点问题”通常指区间选点问题(如:在数轴上选最少的点,使每个区间至少包含一个点),其贪心策略、证明及复杂度如下: -贪心策略: 将所有区间按右端点升序排序,依次遍历区间:若当前区间未被已选点覆盖,则选择该区间的右端点作为选点。 -贪心选择性质证明: 假设最 -
实验六
1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 3 #define N 10 4 5 typedef struct { 6 char isbn[20]; // isbn号 7 char name[80]; // 书名 8 char aut -
实验六 文件I/O与异常处理
实验6 文件I/O与异常处理 实验任务1 源码 task1.cpp #include <algorithm> #include <iostream> #include <stdexcept> #include <vector> #include "contestant.hpp" #include " -
NUIST-OOP-LAB06
实验6 文件I/O与异常处理 一、实验目的 会用标准 I/O 流 ( iostream / fstream ) 完成控制台和文件的读/写,并处理读/写过程中的异常。 会用操控符及流成员函数控制数据格式。 会用 throw/try/catch 及标准库异常类处理异常,并能解释异常处理流程。 能综合应用 -
实验六
task4 1 #include <stdio.h> 2 #include <stdlib.h> 3 #define N 10 4 5 typedef struct { 6 char isbn[20]; 7 char name[80]; 8 char author[80]; 9 double sal