#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. 复制物料(参考的MMCC想法)

    MMCC这个事务码没用过,也是才听到的,都是业务搞起来的...然后感觉这个东西有点意思,就搞搞咯 网上找的一篇文章,自己修改的.改了默认收货工厂为创建时的工厂,因为这边一直报收货工厂必输...不管是不 ...

  2. ALV Tree demo(WBS元素分层显示)[引用别人的]

    原文地址:http://www.xuebuyuan.com/1666753.html 按层次显示WBS编码及描述,附加节点双击展开事件和Item双击跳转CJ03功能. 因为本人懒,本例代码都是从标准的 ...

  3. 前端面试题2016--CSS

    介绍一下标准的CSS的盒子模型?低版本IE的盒子模型有什么不同的? (1)有两种,IE 盒子模型.W3C 盒子模型:(2)盒模型:内容(content).填充(padding).边界(margin). ...

  4. CSS3新增的选择器和属性

    <!doctype html>无标题文档 一.新增的选择器 CSS3新增的属性选择器 {除ie6外的大部分浏览器支持) 序号 选择器 含义 实例 1 E[att^="val&qu ...

  5. ionic 通过PouchDB + SQLite来实现app的本地存储(Local Storage)

    首先声明,本教程参考国外网站(http://gonehybrid.com/how-to-use-pouchdb-sqlite-for-local-storage-in-your-ionic-app/) ...

  6. discuz后台登陆 口令卡添加

    1.通过根目录文件admin.php 找到 $admincp->init(); 2.指向  dz/source/class/discuz/discuz_admincp.php 这个方法funct ...

  7. Jaxb annotation使用

    JAXB(Java Architecture for XML Binding) 是一个业界的标准,是一项可以根据XML Schema产生Java类的技术.该过程中,JAXB也提供了将XML实例文档反向 ...

  8. linux php redis 扩展安装

    安装redis服务端 1 进入软件的下载路径 cd /soft wget http://download.redis.io/redis-stable.tar.gz tar -zxvf redis-st ...

  9. How to Develop blade and soul Skills

    How to Develop Skills Each skill can be improved for variation effects. Some will boost more strengt ...

  10. Scala 学习笔记(五)

    def main(args : Array[String]): Unit = { def add(x:Int,y:Int):Int = { return x+y; } def subtract:(In ...