题意:给定n个线段,问能不能把x,y,z个长度为1,2,3的线段不重合地放进去。

思路:首先如果n个线段长度比要放的长度之和小,则无解,否则先考虑放2和3,如果2和3放下了1肯定可以放下(这是显然的)。于是我们贪心先把n个线段放满长度为3的线段,然后再考虑删去长度为3的线段来放长度为2的线段,删的时候要选择删去以后空闲的线段长度最多的删,比如某个线段本身有1的空闲线段,这时如果删去一条放在上面的长度为3的线段,则空闲线段变为4,这种情况优先删,其它情况次之。实现上采用优先队列,保存每个线段的长度为3的线段个数和空闲线段长度(只有0和1两种可能),然后按照前面说的优先级重载小于号就ok了,非常方便。

 #pragma comment(linker, "/STACK:10240000,10240000")

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <ctime>
#include <cctype>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <numeric>
#include <stdexcept>
#include <utility> using namespace std; #define mem0(a) memset(a, 0, sizeof(a))
#define mem_1(a) memset(a, -1, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define define_m int m = (l + r) >> 1
#define rep_up0(a, b) for (int a = 0; a < (b); a++)
#define rep_up1(a, b) for (int a = 1; a <= (b); a++)
#define rep_down0(a, b) for (int a = b - 1; a >= 0; a--)
#define rep_down1(a, b) for (int a = b; a > 0; a--)
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x) & (-(x)))
#define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
#define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
#define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
#define pchr(a) putchar(a)
#define pstr(a) printf("%s", a)
#define sstr(a) scanf("%s", a)
#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d%d", &a, &b)
#define sint3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define pint(a) printf("%d\n", a)
#define test_print1(a) cout << "var1 = " << a << endl
#define test_print2(a, b) cout << "var1 = " << a << ", var2 = " << b << endl
#define test_print3(a, b, c) cout << "var1 = " << a << ", var2 = " << b << ", var3 = " << c << endl
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a) typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi; const int dx[] = {, , -, , , , -, -};
const int dy[] = {-, , , , , -, , - };
const int maxn = 4e5 + ;
const int md = 1e9 + ;
const int inf = 1e9 + ;
const LL inf_L = 1e18 + ;
const double pi = acos(-1.0);
const double eps = 1e-; template<class T>T gcd(T a, T b){return b==?a:gcd(b,a%b);}
template<class T>bool max_update(T &a,const T &b){if(b>a){a = b; return true;}return false;}
template<class T>bool min_update(T &a,const T &b){if(b<a){a = b; return true;}return false;}
template<class T>T condition(bool f, T a, T b){return f?a:b;}
template<class T>void copy_arr(T a[], T b[], int n){rep_up0(i,n)a[i]=b[i];}
int make_id(int x, int y, int n) { return x * n + y; } struct Node {
int cnt3, rest;
bool operator < (const Node &that) const {
return that.rest && that.cnt3 || that.cnt3 > cnt3 && !(rest && cnt3);
}
constructInt2(Node, cnt3, rest);
}; pii node[maxn];
int a[maxn], tot, s, t, x, y, z, m;
int Left[maxn], Right[maxn];
int main() {
//freopen("in.txt", "r", stdin);
while (cin >> s >> t) {
cin >> x >> y >> z;
cin >> m;
rep_up0(i, m) {
sint2(node[i].first, node[i].second);
}
sort(node, node + m);
tot = ;
int R = -;
int cs = ;
rep_up0(i, m) {
if (node[i].first - R > ) {
Left[cs] = R + ;
Right[cs ++] = node[i].first - ;
}
max_update(R, node[i].second);
}
if (R < 1e9) {
Left[cs] = R + ;
Right[cs ++] = 1e9;
}
rep_up0(i, cs) {
int L = max(s, Left[i]), R = min(t, Right[i]);
if (R >= L) a[tot ++] = R - L + ;
}
sort(a, a + tot);
//rep_up0(i, tot) cout << a[i] << " ";
int sum = ;
rep_up0(i, tot) sum += a[i];
if (sum < x + * y + * z) {
puts("NO");
continue;
}
priority_queue<Node> Q;
int cnt2 = ;
rep_up0(i, tot) {
Q.push(Node(a[i] / , a[i] % % ));
cnt2 += a[i] % / ;
} while (!Q.empty()) {
if (cnt2 >= y) break;
Node Hnode = Q.top(); Q.pop();
if (Hnode.rest) {
if (Hnode.cnt3) {
cnt2 += ;
Q.push(Node(Hnode.cnt3 - , ));
}
}
else {
if (Hnode.cnt3) {
cnt2 ++;
Q.push(Node(Hnode.cnt3 - , ));
}
}
} int cnt3 = ;
while (!Q.empty()) {
Node Hnode = Q.top(); Q.pop();
cnt3 += Hnode.cnt3;
} puts(cnt2 >= y && cnt3 >= z? "YES" : "NO") ;
}
return ;
}

[csu/coj 1083]贪心的更多相关文章

  1. csu - 1538: Shopping (贪心)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1538 很奇妙的一个题,开始没有思路.问了别人才知道. 题目的意思可以理解成上图中,从0点开始向右走 ...

  2. [csu/coj 1619] 递归

    题意:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1619 思路:由于式子具有递归的性质,考虑递归解,中间结果会超64位int,需用大数.另外自己 ...

  3. [csu/coj 1632]LCP

    题意:求一个串的出现次数超过1次的字串的个数 思路:对于一个后缀,出现在它后面的所有后缀与它的LCP的最大值就是应该增加的答案,当然这里没有考虑去重,但是却转化了问题,使得我们可以用最长公共前缀来统计 ...

  4. [csu/coj 1078]多个序列的最长公共子序列

    题意:给n个序列,同一个序列里面元素互不相同,求它们的最长公共子序列. 思路:任取一个序列,对于这个序列里面的两个数ai,aj(i<j),如果对于其它每一个序列,都出现过ai,aj,且ai在aj ...

  5. [csu/coj 1079]树上路径查询 LCA

    题意:询问树上从u到v的路径是否经过k 思路:把树dfs转化为有根树后,对于u,v的路径而言,设p为u,v的最近公共祖先,u到v的路径必定是可以看成两条路径的组合,u->p,v->p,这样 ...

  6. [csu/coj 1080]划分树求区间前k大数和

    题意:从某个区间内最多选择k个数,使得和最大 思路:首先题目给定的数有负数,如果区间前k大出现负数,那么负数不选和更大,于是对于所有最优选择,负数不会出现,所以用0取代负数,问题便转化为区间的前k大数 ...

  7. 【贪心】CSU 1809 Parenthesis (2016湖南省第十二届大学生计算机程序设计竞赛)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 题目大意: 给一个长度为N(N<=105)的合法括号序列.Q(Q<= ...

  8. ACM学习历程—CSU 1216 异或最大值(xor && 贪心 && 字典树)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1216 题目大意是给了n个数,然后取出两个数,使得xor值最大. 首先暴力枚举是C(n,  ...

  9. CSU 1859 Gone Fishing(贪心)

    Gone Fishing [题目链接]Gone Fishing [题目类型]贪心 &题解: 这题要先想到枚举走过的湖,之后才可以贪心,我就没想到这,就不知道怎么贪心 = = 之后在枚举每个湖的 ...

随机推荐

  1. Linux下安装python3环境搭建

    Linux下python3环境搭建 Linux安装软件有哪些方式? rpm软件包 手动安装 拒绝此方式 需要手动解决依赖关系 yum自动化安装 自动处理依赖关系 非常好用 源代码编译安装,可自定义的功 ...

  2. 处理数字的类 —— Math类 、 Random类 、 BigDecimal类 与 BigInteger类

    在我们学习C语言时,我们处理数据时要调用很多函数,那么,Java也有很多的方法可以来处理数值的类. 那么,在本篇博文中,本人就来讲解三个用于处理数值的类 -- Math类 . Random类 与 Bi ...

  3. vim环境下空格和tab键互换

    对于已保存的文件,可以使用下面的方法进行空格和TAB的替换 TAB替换为空格::set ts=4:set expandtab:%retab! 空格替换为TAB::set ts=4:set noexpa ...

  4. Java中Character类

    Character 类在对象中包装一个基本类型char的值此外,该类提供了几种方法,以确定字符的类别(小写字母,数字,等),并将字符从大写转小写,反之亦然. 构造方法: Character(char ...

  5. gin请求数据校验

    前言 最近优化gin+vue的前后端分离项目代码时候,发现代码中对请求数据的校验比较繁琐,于是想办法简化它.最终我发现了go-playground/validator开源库很好用. 优化前代码 代码如 ...

  6. 2019-2020-1 20199326《Linux内核原理与分析》第八周作业

    可执行程序工作原理## 编译链接的过程### 示例程序hello.c #include<stdio.h> void main() { printf("Hello world\n& ...

  7. Python 输出 log 到文件的方法

    import loggingfrom logging.handlers import RotatingFileHandler module_name = "test_module" ...

  8. (转)对 Linux 新手非常有用的 20 个命令

    你打算从Windows换到Linux上来,还是你刚好换到Linux上来?哎哟!!!我说什么呢,是什么原因你就出现在我的世界里了.从我以往的经验来说,当我刚使用Linux,命令,终端啊什么的,吓了我一跳 ...

  9. java中的Volatile关键字使用

    文章目录 什么时候使用volatile Happens-Before java中的Volatile关键字使用 在本文中,我们会介绍java中的一个关键字volatile. volatile的中文意思是 ...

  10. 控制台报错 [WDS] Disconnected!

    Webpack 的 HMR 功能,是通过 WebSocket 实现的推送 JSON Patch,同时需要第三方库支持. 具体解决方案: 热加载(HMR)是 Webpack Dev Server 最强大 ...