zoukankan      html  css  js  c++  java
  • CF527D Clique Problem(贪心)

    考场上想的线性(DP),思路没错但还是(WA)穿。。。多看两眼就知道是最大线段不重复覆盖问题
    右端点第一关键字排序

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <algorithm>
    #include <cmath>
    #define R(a,b,c) for(register int a = (b); a <= (c); ++a)
    #define nR(a,b,c) for(register int a = (b); a >= (c); --a)
    #define Fill(a,b) memset(a, b, sizeof(a))
    #define Swap(a,b) ((a) ^= (b) ^= (a) ^= (b))
    #define QWQ
    #ifdef QWQ
    #define D_e_Line printf("
    ---------------
    ")
    #define D_e(x) cout << (#x) << " : " << x << "
    "
    #define Pause() system("pause")
    #define FileOpen() freopen("in.txt", "r", stdin)
    #define FileSave() freopen("out.txt", "w", stdout)
    #define TIME() fprintf(stderr, "
    TIME : %.3lfms
    ", clock() * 1000.0 / CLOCKS_PER_SEC)
    #else
    #define D_e_Line ;
    #define D_e(x) ;
    #define Pause() ;
    #define FileOpen() ;
    #define FileSave() ;
    #define TIME() ;
    #endif
    struct ios {
    	template<typename ATP> inline ios& operator >> (ATP &x) {
    		x = 0; int f = 1; char c;
    		for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
    		while(c >= '0' && c <='9') x = x * 10 + (c ^ '0'), c = getchar();
    		x *= f;
    		return *this;
    	}
    }io;
    using namespace std;
    template<typename ATP> inline ATP Max(ATP a, ATP b) {
    	return a > b ? a : b;
    }
    template<typename ATP> inline ATP Min(ATP a, ATP b) {
    	return a < b ? a : b;
    }
    template<typename ATP> inline ATP Abs(ATP a) {
    	return a < 0 ? -a : a;
    }
    
    #define int long long
    struct nod {
    	int l, r;
    	bool operator < (const nod &com) const {
    		return r != com.r ? r < com.r : l < com.l;
    	}
    } a[2000007];
    #include <climits>
    #undef int
    int main() {
    #define int long long
    	int n;
    	io >> n;
    	R(i,1,n){
    		int x, w;
    		io >> x >> w;
    		a[i] = (nod){ x - w, x + w};
    	}
    	
    	sort(a + 1, a + n + 1);
    	int r = -LLONG_MAX;
    	int ans = 0;
    	R(i,1,n){
    		if(a[i].l < r) continue;
    		++ans;
    		r = a[i].r;
    	}
    	printf("%lld", ans);
    	
    	return 0;
    }
    

  • 相关阅读:
    thinkphp3.1.3验证码优化
    php导出数据为CSV文件DEMO
    python学习笔记十七:base64及md5编码
    linux运维笔记
    [转]如何像Python高手(Pythonista)一样编程
    用gulp清除、移动、压缩、合并、替换代码
    [蓝桥杯][2017年第八届真题]小计算器(模拟)
    [蓝桥杯][2017年第八届真题]发现环(基环树输出环)
    [蓝桥杯][2017年第八届真题]合根植物(并查集)
    省赛训练5-3(四个签到题)
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11738373.html
Copyright © 2011-2022 走看看