题意:给定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. [apue] getopt 可能重排参数

    看第21章时,介绍到了解析命令行的神器 getopt,了解了 linux 下处理通用命令行的方法. 命令行可分为参数与选项,其中不带 - 或 -- 前缀的为参数,对一个命令而言数量是固定的,多个参数之 ...

  2. Missing artifact net.sf.json-lib:json-lib:jar:2.2.3

    <!-- https://mvnrepository.com/artifact/net.sf.json-lib/json-lib --><dependency> <gro ...

  3. AI-web-1靶机过关记录

    靶机地址:172.16.1.195 Kali地址:172.16.1.107 1.信息收集 端口扫描: 目录扫描: 发现robots.txt敏感文件,查看 存在/m3diNf0/,/se3reTdir7 ...

  4. Python爬取全球疫情数据,实现可视化显示地图数据(附代码)

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 武汉地区,目前已经实现住院患者清零了,国内疫情已经稳定,然而中国以外新冠确 ...

  5. DEDE中自定义表单HTML 怎么写

    用DEDE嵌套网站时,有时我们需要添加自定义字段,而自定义字段的HTML样式如何设置呢? 功能地图(核心/频道模型/内容模型管理/)——普通文章的修改——字段管理——你的自定义字段的修改——最下面自定 ...

  6. 【转载】pyinstaller的使用和几个坑

    1.-w是不显示命令窗口,  -i 图标文件的路径  这是改变图标的,但是我发现只能改变任务栏里的和命令窗口的图标,并不能改变exe文件的图标.另外这些参数要加载pyinstaller和路径中间. 2 ...

  7. Inno Script - How to make “I Accept the Agreement” radio button on EULA page selected by Default

    出处: https://stackoverflow.com/questions/11187022/inno-script-how-to-make-i-accept-the-agreement-radi ...

  8. Golang Map实现(四) map 的赋值和扩容

    title: Golang Map 实现 (四) date: 2020-04-28 18:20:30 tags: golang map 操作,是map 实现中较复杂的逻辑.因为当赋值时,为了减少has ...

  9. C#多线程(16):手把手教你撸一个工作流

    目录 前言 节点 Then Parallel Schedule Delay 试用一下 顺序节点 并行任务 编写工作流 接口构建器 工作流构建器 依赖注入 实现工作流解析 前言 前面学习了很多多线程和任 ...

  10. JDK12的五大重要新特性

    文章目录 JDK12的五大重要新特性 引入JVM常量API 扩展了switch语句 支持Unicode 11.0 为日本Reiwa Era提供了方形字符支持 NumberFormat增加了对以紧凑格式 ...