#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. Migrating an ASP.NET MVC application to ADFS authentication

    I recently built an ASP.NET application at work to help track internal use of our products. It's bee ...

  2. LINUX磁盘分区、格式化、挂载、卸载全程详解

    1.一切皆文件 Linux系统有一个理念:“一切皆文件”,所以计算机的硬件在linux中也是以“文件”的形式存在于/dev目录中.   图为CentOS 6.5系统中/dev目录的部分内容.不同的计算 ...

  3. 使用C++11的一点总结

          C++11已不是新鲜技术,但对于我来说,工作中用得还不够多(前东家长时间使用gcc3.4.5,虽然去年升了4.8.2,但旧模块维护还是3.4.5居多:新东家用的是4.4.6,不能完整支持C ...

  4. 远程线程DLL注入64位进程

    int main() { BOOL bFlag = FALSE; char *szDllName = "MSGDLL.dll"; //bFlag = EnablePrivilege ...

  5. asp.netajax开发应用心得-accordation控件的事件处理

    今天,再次运行以前的项目时,发现按钮的单击事件不起作用了,加了断点之后发现根本没有触发该事件.... 按照网上找到的答案,有的说把控件删掉重新拖拽一个进去,虽然以前也遇到过控件失效,重新拖拽有效的时候 ...

  6. php生成图片缩略图,支持png透明

    注:此功能依赖GD2图形库 PHP生成缩略图类   <?php /* * desc: Resize Image(png, jpg, gif) * author: 十年后的卢哥哥(http://w ...

  7. HDU 4944 FSF’s game(2014 Multi-University Training Contest 7)

    思路:  ans[n]=  ans[n-1] + { (n,1),(n,2).....(n,n)}  现在任务 是 计算  { (n,1),(n,2).....(n,n)}(k=n的任意因子) 很明显 ...

  8. 【转载】桥接Microsoft Word和浏览器

    原文链接地址: http://www.infoq.com/cn/articles/convert-microsoft-word-to-html?utm_campaign=rightbar_v2& ...

  9. VS一次删除多个窗体后报错

    今天在做项目的时候,需要删除多个窗体,删除了之后,VS报了个错误: 命名空间“项目名称”中不存在类型或命名空间名称“文件夹”(是否缺少程序集引用?) 具体原因不清楚,就算恢复窗体后还是一样的错误,无法 ...

  10. 在MAC上搭建cordova3.4.0的IOS和android开发环境

    Hello,大家好,今天给大家说说在mac上搭建cordova3.4.0的iOS和Android开发环境,首先下载cordova,地址:https://cordova.apache.org/#down ...