题目:http://poj.org/problem?id=2376

  英文题强行看不懂,只看的懂输入输出,输入n,m,下接n行每行一个区间两个数左端点 l,有端点 r

  给出n个闭区间,求选择最少的区间能够完全覆盖[1,m]

  经典的区间覆盖问题,按左端点升序排序

  首先当前卡点为1,选择小于等于当前卡点的,尽量往右边扩

  直到大于当前卡点,再将卡点设为右边能扩展到的最大值

  统计答案,注意闭区间和左端点最小区大于 1 的情况

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<queue>
#include<stack>
#define fre(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout)
typedef long long LL;
typedef double db;
using namespace std; const int oo=,TL=,N=;
struct line
{
int l,r;
}
a[N];
inline bool cmp(line x,line y)
{
return x.l<y.l;
}
int main()
{
int n,m,i,k,x,ans=,j;
scanf("%d%d",&n,&m);
for (i=;i<=n;i++) scanf("%d%d",&a[i].l,&a[i].r);
sort(a+,a++n,cmp);
for (k=x=i=j=;i<=n;j=i)
{
while (a[i].l<=k&&i<=n&&x<m) x=max(x,a[i++].r);
ans++;
if ((k=x+)>m||i==j) break;
}
printf("%d\n",k<=m?-:ans);
return ;
}

  本来以为水贪心可以一边A,结果交了七八遍全WA

  就到网上去下标程拍,修改了2次之后把标程给拍WA了,自己A掉了(233333333333)

  网上的题解也是错的一大片啊~欢迎 Hack

版权所有,转载请联系作者,违者必究

联系方式:http://www.cnblogs.com/hadilo/p/5932395.html

POJ2376_Cleaning Shifts_C++的更多相关文章

随机推荐

  1. C# winform 右下角弹出窗口结果

    using System.Runtime.InteropServices; [DllImport("user32")] private static extern bool Ani ...

  2. CryptAPI 数字签名 与 Openssl 验证签名

    这段时间要实现一个认证协议,分为客户端和服务器端,客户端使用windows操作系统,服务器端使用linux操作系统,在客户端下(windows),使用windows证书库中的签名证书对消息进行签名(使 ...

  3. windows 2003 上安装windows liver writer

    下载"resource hacker"软件,修改exe文件,找到config--config0-0 替换为: <?xml version="1.0" en ...

  4. LintCode "Continuous Subarray Sum"

    A variation to a classical DP: LCS. class Solution { public: /** * @param A an integer array * @retu ...

  5. poj2352消防站

    题目大意:有n个点的一棵树,每个点有两个值:w和c.现在要在其中若干点建立消防站,使得每个点到最近的消防站的距离不超过该点的c值,i点建立消防站的费用为w.求最小费用. 分析:本题显然是树型Dp.定义 ...

  6. Hierarchy Viewer

    http://blog.csdn.net/ddna/article/details/5527072 Hierarchy Viewer是随AndroidSDK发布的工具,位置在tools文件夹下,名为h ...

  7. TortoiseSVN 同步分支

    对比工具可以使用 winmerge 和 beyond compare ,winmerge免费小巧,beyond compare功能更强大.这两款工具都比TortoiseSVN自带的对比工具要好一些. ...

  8. fork()详解

    参照: http://blog.csdn.net/jason314/article/details/5640969 http://coolshell.cn/articles/7965.html

  9. 纯c++实现之滚动窗口

    别在MFC了,先分析下,上图 我们以左上角为坐标原点,用position_width和position_height来保存当前显示坐标. 根据msdn说明,滚动条默认情况下的值在0~100之间. 根据 ...

  10. DBA_Oracle Database 11g 面向 DBA 和开发人员的重要特性

     2015-01-23 Created By BaoXinjian