#include <bits/stdc++.h>
using namespace std;
const int Maxn=;
struct Info{int l,r;}P[Maxn];
int n,Cnt,F[Maxn];
map<int,int> M;
inline bool Cmp(Info A,Info B) {return A.r<B.r;}
inline int Max(int x,int y) {return x>y?x:y;}
inline void Swap(int &x,int &y) {int t=x;x=y;y=t;}
int main()
{ scanf("%d",&n); Cnt=;
for (int i=;i<=n;i++)
{
scanf("%d%d",&P[i].l,&P[i].r);
if (P[i].l>P[i].r) Swap(P[i].l,P[i].r);
M[P[i].l]=,M[P[i].r]=;
}
for (map<int,int>::iterator it=M.begin();it!=M.end();it++) it->second=++Cnt;
for (int i=;i<=n;i++) P[i].l=M[P[i].l],P[i].r=M[P[i].r];
sort(P+,P+n+,Cmp); int j=;
for (int i=;i<=Cnt;i++)
{
while (j<=n && P[j].r==i)
{
F[i]=Max(F[i],F[P[j].l]+);
j++;
}
F[i]=Max(F[i],F[i-]);
}
printf("%d\n",F[Cnt]);
return ;
}

线段覆盖1

 #include <bits/stdc++.h>
using namespace std;
const int Maxn=;
struct Info{int l,r;}P[Maxn];
int n,Cnt,F[Maxn];
map<int,int> M;
inline bool Cmp(Info A,Info B) {return A.r<B.r;}
inline int Max(int x,int y) {return x>y?x:y;}
inline void Swap(int &x,int &y) {int t=x;x=y;y=t;}
int main()
{ scanf("%d",&n); Cnt=;
for (int i=;i<=n;i++)
{
scanf("%d%d",&P[i].l,&P[i].r);
if (P[i].l>P[i].r) Swap(P[i].l,P[i].r);
M[P[i].l]=,M[P[i].r]=;
}
for (map<int,int>::iterator it=M.begin();it!=M.end();it++) it->second=++Cnt;
for (int i=;i<=n;i++) P[i].l=M[P[i].l],P[i].r=M[P[i].r];
sort(P+,P+n+,Cmp); int j=;
for (int i=;i<=Cnt;i++)
{
while (j<=n && P[j].r==i)
{
F[i]=Max(F[i],F[P[j].l]+);
j++;
}
F[i]=Max(F[i],F[i-]);
}
printf("%d\n",F[Cnt]);
return ;
}

线段覆盖2

 #include <bits/stdc++.h>
using namespace std;
const int Maxn=;
struct Info{int l,r,w;}P[Maxn];
int n,Cnt,F[Maxn];
map<int,int> M;
inline bool Cmp(Info A,Info B) {return A.r<B.r;}
inline int Max(int x,int y) {return x>y?x:y;}
inline void Swap(int &x,int &y) {int t=x;x=y;y=t;}
int main()
{ scanf("%d",&n); Cnt=;
for (int i=;i<=n;i++)
{
scanf("%d%d%d",&P[i].l,&P[i].r,&P[i].w);
if (P[i].l>P[i].r) Swap(P[i].l,P[i].r);
M[P[i].l]=,M[P[i].r]=;
}
for (map<int,int>::iterator it=M.begin();it!=M.end();it++) it->second=++Cnt;
for (int i=;i<=n;i++) P[i].l=M[P[i].l],P[i].r=M[P[i].r];
sort(P+,P+n+,Cmp); int j=;
for (int i=;i<=Cnt;i++)
{
while (j<=n && P[j].r==i)
{
F[i]=Max(F[i],F[P[j].l]+P[j].w);
j++;
}
F[i]=Max(F[i],F[i-]);
}
printf("%d\n",F[Cnt]);
return ;
}

线段覆盖3

 #include <bits/stdc++.h>
#define LL long long
using namespace std;
const int Maxn=;
const int Inf=0x3f3f3f3f;
struct Info{int l,r,w;}P[Maxn];
int n,Cnt,a[Maxn<<];
LL F[];
inline bool Cmp(Info A,Info B) {return A.r<B.r;}
inline int Min(int x,int y) {return x>y?y:x;}
inline LL Max(LL x,LL y) {return x>y?x:y;}
inline void Swap(int &x,int &y) {int t=x;x=y;y=t;}
inline void Get_Int(int &x)
{
x=; register char ch=getchar(); int f=;
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();} x*=f;
}
int main()
{ Get_Int(n);
for (int i=;i<=n;i++)
{
Get_Int(P[i].l),Get_Int(P[i].r),Get_Int(P[i].w);
if (P[i].l>P[i].r) Swap(P[i].l,P[i].r);
a[i*-]=P[i].l,a[i*]=P[i].r;
}
sort(a+,a+n*+); Cnt=;
for (int i=;i<=*n;i++) if (a[i]!=a[Cnt]) a[++Cnt]=a[i];
for (int i=;i<=n;i++) P[i].l=lower_bound(a+,a+Cnt+,P[i].l)-a,P[i].r=lower_bound(a+,a+Cnt+,P[i].r)-a; sort(P+,P+n+,Cmp); int j=;
for (int i=;i<=Cnt;i++)
{
while (j<=n && P[j].r==i)
{
F[i]=Max(F[i],F[P[j].l]+(LL)P[j].w);
j++;
}
F[i]=Max(F[i],F[i-]);
}
printf("%lld\n",F[Cnt]);
return ;
}

线段覆盖4

 #include <bits/stdc++.h>
#define LL long long
using namespace std;
const int Maxn=;
const int Inf=0x3f3f3f3f;
struct Info{int l,r,w;}P[Maxn];
int n,Cnt,a[Maxn<<];
LL F[Maxn<<];
inline bool Cmp(Info A,Info B) {return A.r<B.r;}
inline int Min(int x,int y) {return x>y?y:x;}
inline LL Max(LL x,LL y) {return x>y?x:y;}
inline void Swap(int &x,int &y) {int t=x;x=y;y=t;}
inline void Get_Int(int &x)
{
x=; register char ch=getchar(); int f=;
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();} x*=f;
}
int main()
{ Get_Int(n);
for (int i=;i<=n;i++)
{
Get_Int(P[i].l),Get_Int(P[i].r),Get_Int(P[i].w);
if (P[i].l>P[i].r) Swap(P[i].l,P[i].r);
a[i*-]=P[i].l,a[i*]=P[i].r;
}
sort(a+,a+n*+); Cnt=;
for (int i=;i<=*n;i++) if (a[i]!=a[Cnt]) a[++Cnt]=a[i];
for (int i=;i<=n;i++) P[i].l=lower_bound(a+,a+Cnt+,P[i].l)-a,P[i].r=lower_bound(a+,a+Cnt+,P[i].r)-a; sort(P+,P+n+,Cmp); int j=;
for (int i=;i<=Cnt;i++)
{
while (j<=n && P[j].r==i)
{
F[i]=Max(F[i],F[P[j].l]+(LL)P[j].w);
j++;
}
F[i]=Max(F[i],F[i-]);
}
printf("%lld\n",F[Cnt]);
return ;
}

线段覆盖5

不会贪心只会DP,Code都类似只不过中间用STL离散化被卡常了..

CodeVS 线段覆盖1~5的更多相关文章

  1. 【BZOJ-3589】动态树 树链剖分 + 线段树 + 线段覆盖(特殊的技巧)

    3589: 动态树 Time Limit: 30 Sec  Memory Limit: 1024 MBSubmit: 405  Solved: 137[Submit][Status][Discuss] ...

  2. codevs 3012 线段覆盖 4 & 3037 线段覆盖 5

    3037 线段覆盖 5  时间限制: 3 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 数轴上有n条线段,线段的两端都 ...

  3. codevs 1214 线段覆盖

    1214 线段覆盖 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold   题目描述 Description 给定x轴上的N(0<N<100)条线段,每个线段 ...

  4. codevs 1214 线段覆盖/1643 线段覆盖 3

    1214 线段覆盖/1214 线段覆盖  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold       题目描述 Description 给定x轴上的N(0< ...

  5. codevs 1643 线段覆盖 3

    1643 线段覆盖 3  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 在一个数轴上有n条线段,现要选取其中 ...

  6. CODEVS 3027 线段覆盖2

    首先,先看题.....(虽然比较简单 3027 线段覆盖 2    时间限制: 1 s  空间限制: 128000 KB 题目描述 Description 数轴上有n条线段,线段的两端都是整数坐标,坐 ...

  7. codevs 3027线段覆盖2

    传送门 3027 线段覆盖 2  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold   题目描述 Description 数轴上有n条线段,线段的两端都是整数坐标, ...

  8. codevs 3012 线段覆盖4

    传送门 3012 线段覆盖 4  时间限制: 1 s  空间限制: 64000 KB  题目等级 : 黄金 Gold   题目描述 Description 数轴上有n条线段,线段的两端都是整数坐标,坐 ...

  9. codevs 1214线段覆盖

    1214 线段覆盖  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold   题目描述 Description 给定x轴上的N(0<N<100)条线段,每 ...

随机推荐

  1. Android 常用布局视图

    常用包 http://square.github.io/ EventBus Scroller 滚动 拖拽 # android.support.design.widget.CollapsingToolb ...

  2. js判断是手机还是电脑访问网站

    js判断是手机还是电脑访问网站                               <script type="text/javascript"> <!- ...

  3. biweb添加新的模块

    1.例如添加一个新闻模块,首先去纯净的项目的根目录复制出一个news文件夹到项目外 2.打开dreamweaver, 编辑 ->查找和替换 例如 新模块 叫 我的新闻,英文名叫mynews,则进 ...

  4. 解决因为使用了官方xbean-2.4.0.jar 的库造成的性能问题

    最近我们游戏经常收到玩家投诉卡进度条的问题.而且后台显示执行队列和CPU使用率异常高 根据调用的JDB分析出 使用xbean 时候会调用以下代码 在设置xmlobject 时候会有一个 GlobalL ...

  5. Python笔记总结week6

    关于创建.调用模块 1.我们创建一个模块commons.py,  并且在文件中写以下三个函数: def login(): print('登录') def logout(): print('退出') d ...

  6. html快速入门(基础教程+资源推荐)

    1.html究竟是什么? 从字面上理解,html是超文本标记语言hyper text mark-up language的首字母缩写,指的是一种通用web页面描述语言,是用来描述我们打开浏览器就能看到的 ...

  7. C#读取Excel文件

    //excel模板的路径 string strSource = Application.StartupPath + "\\" + "ExcelTemplet" ...

  8. 关于java中创建文件,并且写入内容

    以下内容完全为本人原创,如若转载,请注明出自:http://www.cnblogs.com/XiOrang/ 前两天在项目中因为要通过http请求获取一个比较大的json数据(300KB左右)并且保存 ...

  9. c# 获取 本周、本月、本季度、本年 的开始时间或结束时间

    #region 获取 本周.本月.本季度.本年 的开始时间或结束时间 /// <summary> /// 获取结束时间 /// </summary> /// <param ...

  10. 【Python⑤】python序列---list和tuple

    sequence 序列 sequence(序列)是一组有顺序的对象的集合.序列可以包含一个或多个元素,也可以没有任何元素. 我们之前所说的基本数据类型,都可以作为序列的对象.对象还可以是另一个序列.序 ...