第4章节-贪心算法-习题.pptVIP

  • 42
  • 0
  • 约9.34千字
  • 约 38页
  • 2018-02-03 发布于浙江
  • 举报
第4章节-贪心算法-习题

* 算法实现题4-21 区间相交问题 数据结构: struct interval{   int start;   int end; }; 比较函数: bool cmp(interval a, interval b) {   if (a.endb.end) return true;   else return false; } * 算法实现题4-21 区间相交问题 在int main() 中:   int n;   int a,b;   cinn;   interval inte[100];   for (int i=0; in; i++){     cinab;     if (ab) swap(a, b);     inte[i].start=a;     inte[i].end=b;   }   sort(inte, inte+n, cmp);   coutn-GreedySelector(n, inte)endl; start 1 5 20 7 6 70 70 99 101 9 end 100 6 210 8 7 100 99 100 102 18 * 算法实现题4-21 区间相交问题 贪心选择: int GreedySelector(int n, interval inte[ ]) {   int count = 1;   int j=0; //区间的起点   fo

文档评论(0)

1亿VIP精品文档

相关文档