51nod 1563 坐标轴上的最大团 (贪心)
来源:互联网 发布:淘宝流量有什么作用 编辑:程序博客网 时间:2024/06/05 15:45
Description
坐标轴上有n个点,每个点有一个权值。第i个点的坐标是
Solution
可以发现其实每一个点可以看做以
Code
#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<iostream>#include<algorithm>#include<queue>#include<vector>#include<set>#define For(i , j , k) for (int i = (j) , _##end_ = (k) ; i <= _##end_ ; ++ i)#define Fordown(i , j , k) for (int i = (j) , _##end_ = (k) ; i >= _##end_ ; -- i)#define Set(a , b) memset(a , b , sizeof(a))#define pb push_back#define mp make_pair#define x first#define y second#define INF (0x3f3f3f3f)#define Mod (1000000007)using namespace std;typedef long long LL;typedef pair<int , int> PII;template <typename T> inline bool chkmax(T &a , T b) { return a < b ? (a = b , 1) : 0; }template <typename T> inline bool chkmin(T &a , T b) { return b < a ? (a = b , 1) : 0; }int _ , __;char c_;inline int read(){ for (_ = 0 , __ = 1 , c_ = getchar() ; !isdigit(c_) ; c_ = getchar()) if (c_ == '-') __ = -1; for ( ; isdigit(c_) ; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48); return _ * __;}inline void file(){#ifndef ONLINE_JUDGE freopen("51nod1563.in" , "r" , stdin); freopen("51nod1563.out" , "w" , stdout);#endif}const int maxn = 200010;struct Line{ int l , r; bool operator < (const Line &line) const { return l < line.l; }}L[maxn];int n , m , xi , wi , last , cnt;int main(){ file(); n = read(); For(i , 1 , n)//转化成线段 { xi = read(); wi = read(); L[i].l = xi - wi; L[i].r = xi + wi; } sort(L + 1 , L + 1 + n);//按左端点排序 for (int i = 1 ; i <= n ; ++ i)//去包含关系 { while (m && L[m].r > L[i].r) -- m; L[++ m] = L[i]; } last = -2000000001; for (int i = 1 ; i <= m ; ++ i)//贪心 if (last <= L[i].l) { last = L[i].r; ++ cnt; } printf("%d\n" , cnt); return 0;}
阅读全文
0 0
- 51nod 1563 坐标轴上的最大团 (贪心)
- 51Nod-1563-坐标轴上的最大团
- [51nod-1563]坐标轴上的最大团
- 51 Nod 1563——坐标轴上的最大团
- 【51Nod1563】坐标轴上的最大团
- 51nod 1524 可除图的最大团【dp】
- 51nod-1524 可除图的最大团
- 51Nod-1524-可除图的最大团
- 51nod 1524 可除图的最大团
- 51nod 1524 可除图的最大团 dp
- 51nod-1524 可除图的最大团(DP)
- 51nod 1524 可除图的最大团(DP)
- 贪心算法和最大团
- 最大团的求法
- 强连通分量,DAG上的最长路,记忆化搜索(最大团,UVA 11324)
- 组队(最大团)
- 最大团(dfs)
- 对最大团的理解
- LeetCode513. Find Bottom Left Tree Value
- Unbuntu16.04+Kaldi本地运行thchs30语料(完整版)
- QNetwork封装的一个get/post类
- python enumerate函数用法
- Linux初探---------基本介绍及常见发行版
- 51nod 1563 坐标轴上的最大团 (贪心)
- php基础
- 写程序学ML:朴素贝叶斯算法原理及实现(三)
- android学习---使用GSON解析JSON格式数据
- 10月1日(周日训练笔记)
- hdu 4027 Can you answer these queries?-特殊的单节点更新
- 日常作业2
- 数据库分片(Sharding)与分区(Partition)的区别
- BZOJ[1192]鬼谷子的钱袋 乱搞