CodeVS 线段覆盖1~5
#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的更多相关文章
- 【BZOJ-3589】动态树 树链剖分 + 线段树 + 线段覆盖(特殊的技巧)
3589: 动态树 Time Limit: 30 Sec Memory Limit: 1024 MBSubmit: 405 Solved: 137[Submit][Status][Discuss] ...
- codevs 3012 线段覆盖 4 & 3037 线段覆盖 5
3037 线段覆盖 5 时间限制: 3 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 数轴上有n条线段,线段的两端都 ...
- codevs 1214 线段覆盖
1214 线段覆盖 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给定x轴上的N(0<N<100)条线段,每个线段 ...
- codevs 1214 线段覆盖/1643 线段覆盖 3
1214 线段覆盖/1214 线段覆盖 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给定x轴上的N(0< ...
- codevs 1643 线段覆盖 3
1643 线段覆盖 3 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 在一个数轴上有n条线段,现要选取其中 ...
- CODEVS 3027 线段覆盖2
首先,先看题.....(虽然比较简单 3027 线段覆盖 2 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description 数轴上有n条线段,线段的两端都是整数坐标,坐 ...
- codevs 3027线段覆盖2
传送门 3027 线段覆盖 2 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 数轴上有n条线段,线段的两端都是整数坐标, ...
- codevs 3012 线段覆盖4
传送门 3012 线段覆盖 4 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 黄金 Gold 题目描述 Description 数轴上有n条线段,线段的两端都是整数坐标,坐 ...
- codevs 1214线段覆盖
1214 线段覆盖 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给定x轴上的N(0<N<100)条线段,每 ...
随机推荐
- Linux 系统把英文修改成中文界面
1.一般安装后的linux系统都是英文的界面,网上查了一下各种说法都有,我只做了如下的配置就好了,下载个中文包,改一下i18n就完事了,并没有那么复杂 下面上图文: 目前是英文的界面 2.下载个中文包 ...
- 建站随手记:about server stack
建站需要,随手记: Server Stack: ----------- 标准的mezzanine的Stack设置 前端:Nginx wsgi:gunicorn cms tool: mezzanine ...
- SAP连接电脑串口读数(电子称,磅等数据读取)
这是几年前做的了,一直都不想分享出来,后来想想为了能够给大家点想法,献出来了... 这是一个电脑读称的方法,一般用COMM口连接的电子设备都可参考. 如果是对串口参数不确定的,可以网上找个串口测试工具 ...
- 深入浅出Mybatis系列(二)---配置简介(mybatis源码篇)
上篇文章<深入浅出Mybatis系列(一)---Mybatis入门>, 写了一个Demo简单体现了一下Mybatis的流程.本次,将简单介绍一下Mybatis的配置文件: 上次例子中,我们 ...
- 安装numpy
为了运行机器学习书上的实例,安装numpy.照着网上教程安装的,网上教程 1)下载numpy包 下载地址:https://pypi.python.org/pypi/numpy/#downloads 自 ...
- 企业项目开发--分布式缓存Redis
第九章 企业项目开发--分布式缓存Redis(1) 注意:本章代码将会建立在上一章的代码基础上,上一章链接<第八章 企业项目开发--分布式缓存memcached> 1.为什么用Redis ...
- 在EC2上搭建L2TP over IPSec VPN服务器
注意(:wq保存文件 putty登陆用户名为ec2-user) 安装与配置: 环境介绍: OS:CentOS 6.4 x86_64 Minimal 1. 修改 /etc/sysctl.conf,新增如 ...
- HashMap 遍历
Map<String, String> _map = new HashMap<String,String>(); 1.方法一 for (Entry<String, Str ...
- Git 分支
Git 保存的不是文件的变化或者差异,而是一系列不同时刻的文件快照,某一次的提交指向这处时刻的文件快照,看起来就像每次提交都保存了当时的文件,连续的提交形成一条长链 分支 指向某一个特定的提交,不同的 ...
- C++小项目:directx11图形程序(四):d3dclass
主菜终于来了.这个d3dclass主要做的工作是dx11图形程序的初始化工作,它将创建显示表面交换链,d3d设备,d3d设备上下文,渲染目标表面,深度模板缓存:设置视口,生成投影矩阵. D3D设备:可 ...