UVA 10020 Minimal coverage(最小覆盖问题)

 Minimal coverage 

The Problem

Given several segments of line (int the X axis) with coordinates [Li,Ri]. You are to choose the minimal amount of them, such they would completely cover the segment [0,M].

The Input

The first line is the number of test cases, followed by a blank line.

Each test case in the input should contains an integer M(1<=M<=5000), followed by pairs "Li Ri"(|Li|, |Ri|<=50000, i<=100000), each on a separate line. Each test case of input is terminated by pair "0 0".

Each test case will be separated by a single line.

The Output

For each test case, in the first line of output your programm should print the minimal number of line segments which can cover segment [0,M]. In the following lines, the coordinates of segments, sorted by their left end (Li), should be printed in the same format as in the input. Pair "0 0" should not be printed. If [0,M] can not be covered by given line segments, your programm should print "0"(without quotes).

Print a blank line between the outputs for two consecutive test cases.

Sample Input

2

1
-1 0
-5 -3
2 5
0 0

1
-1 0
0 1
0 0

Sample Output

0

1
0 1


 

题目大意:给你M的值和n条木棒的左右节点,求最少有多少根已知的木棒能覆盖[0,M]这个区间。

典型贪心里的最小覆盖问题,类似题目见:hdu 2088  。

因本人有一点左右不分(尤其是英语),所以直接打的拼音,莫见怪~O(∩_∩)O~

 

#include <iostream>
#include <cstring>
#include <cstdio>
#include<cmath>
#include <algorithm>
using namespace std;
 struct point
 {
     int zuo;
     int you;
   friend bool operator <(const point a,const point b)//运算符'<'重载    
     {    if(a.zuo!=b.zuo)
            return a.zuo<b.zuo;
         else
          return a.you>b.you;
     }

 }a[100010];

int main()
{
  int T,M,i,j,k;
  int cnt;
 scanf("%d",&T);
  while(T--)
  {
     scanf("%d",&M);
      int t=0;
    while(1)
    {
        scanf("%d%d",&a[t].zuo,&a[t].you);
        if(!a[t].zuo&&!a[t].you)
            break;
        if(a[t].you>0||a[t].zuo>M)
             ++t;
    }
    sort(a,a+t);
     if(a[0].zuo>0)
     {
         printf("0\n");
        if(T)
          printf("\n");
         continue;
     }
     int cnt=0,s=-1;
     int flag=0;
     int sign[100010];
    for(i=0;i<t;i++)
    {
        if(a[i].zuo<=cnt)
        {
            if(s==-1)
               sign[++s]=i;
            else
              if(a[i].you>a[sign[s]].you)
                sign[s]=i;
        }
       else
       {
           cnt=a[sign[s]].you;
            sign[++s]=i;
       }
    if(a[sign[s]].you>=M)
       {
        flag=1;
        break;
       }
    }
  if(flag)
  {
      printf("%d\n",s+1);
    for(i=0;i<=s;i++)
        printf("%d %d\n",a[sign[i]].zuo,a[sign[i]].you);
   }
   else
     printf("0\n");
   if(T)
    printf("\n");

  }


    return 0;
}


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 不是一样的。最小函数覆盖最小函数依赖都是关于关系型数据库设计中的概念,但它们的含义是不同的。 最小函数覆盖指的是在一个关系模式中,通过消除冗余的函数依赖得到的最小集合。具体来说,如果在一个关系模式中存在多个函数依赖,其中一些函数依赖是可以由其他函数依赖推导出来的,那么这些函数依赖就可以被称为冗余的。最小函数覆盖就是指通过消除这些冗余的函数依赖,得到的最小集合。 而最小函数依赖则是指在一个关系模式中,通过消除冗余的属性依赖得到的最小集合。具体来说,如果在一个关系模式中存在多个属性依赖,其中一些属性依赖是可以由其他属性依赖推导出来的,那么这些属性依赖就可以被称为冗余的。最小函数依赖就是指通过消除这些冗余的属性依赖,得到的最小集合。 ### 回答2: 最小函数覆盖最小函数依赖是两个不同的概念。 最小函数覆盖指的是在逻辑或者数学模型中,用最少的函数来完整地描述某个问题或者系统。这个概念通常出现在形式化方法和软件工程中,用来精确地描述问题的特征和要求。最小函数覆盖的目的是简化问题,提高模型的可读性和可执行性。 而最小函数依赖则指的是在数据库设计中,通过分析数据之间的依赖关系,找到最小的依赖集合,保证数据的完整性和一致性。最小函数依赖是数据规范化的一部分,通过将数据分解为不重复的关系表,减少数据冗余和更新异常。最小函数依赖的目的是优化数据库的设计和操作效率。 虽然最小函数覆盖最小函数依赖都涉及到“最小”的概念,但它们所描述的对象和应用领域是不同的。最小函数覆盖主要关注问题或者系统的模型描述,而最小函数依赖主要关注数据库的设计和数据依赖关系。因此,最小函数覆盖最小函数依赖是不一样的。 ### 回答3: 最小函数覆盖最小函数依赖不是一样的。 最小函数覆盖Minimal Function Coverage)指的是在软件测试中,通过选择最少的测试用例集合,覆盖到程序中所有的语句、分支和路径。其目的是尽可能地测试到程序中可能出现的各种情况,以提高软件的可靠性和健壮性。 最小函数依赖(Minimal Function Dependency)指的是在关系数据库中,通过消除关系模式中的冗余依赖,得到不再依赖于其他属性的最小关系模式。其目的是提高数据库的性能和数据一致性。 虽然两者在名称上都带有"最小"的概念,但其应用领域和目标不同。最小函数覆盖关注的是软件测试,旨在通过最小的测试用例集合来覆盖到尽量多的程序代码;而最小函数依赖关注的是数据库设计,旨在消除冗余依赖,使得数据库更加高效和规范。 因此,最小函数覆盖最小函数依赖是两个不同的概念。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值