题意:给定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. tortoise 设置beyond Compare比较工具

    1.桌面右击tortoiseSVN->setting->Diff Viewer面板,选择external,选中beyond Compare路径

  2. JavaScript思维导图很全(W3C上的!!!!很重要快来看!)

  3. xshell下使用vim的编辑一个文件Ctrl+S和Ctrl+Q

    xshell下使用vim的编辑一个文件,保存的时候习惯性的按了Ctrl+S 结构悲剧了.屏幕锁死了.按其他键都没有反应,exc也不行. 经过问度娘才知道. 原来Ctrl+S在Linux里,是锁定屏幕的 ...

  4. 8、Flink Table API & Flink Sql API

    一.概述 上图是flink的分层模型,Table API 和 SQL 处于最顶端,是 Flink 提供的高级 API 操作.Flink SQL 是 Flink 实时计算为简化计算模型,降低用户使用实时 ...

  5. 共享文件夹下其他文件可以访问但php文件访问不了的原因

    刚开始的问题是在virtualbox里的共享文件夹下的项目运行不了,原因是宝塔下nginx的用户和用户组默认是www 和 www 需要改成www vboxsf(因为自动挂载的目录为/media/sf_ ...

  6. phpcms 用phpexcel导入导出excel

    html <form method="post" action="?m=content&c=content&a=public_add_excel&q ...

  7. 2019-2020-1 20199325《Linux内核原理与分析》第二周作业

    冯诺依曼计算机硬件框图: 下面是一个简单的程序example.c. intadd_a_and_b(int a,int b){returna+b;}intmain(){returnadd_a_and_b ...

  8. D3.js 力导向图的显示优化

    D3.js 作为一个前端,说到可视化除了听过 D3.js 的大名,常见的可视化库还有 ECharts.Chart.js,这两个库功能也很强大,但是有一个共同特点是封装层次高,留给开发者可设计和控制的部 ...

  9. Shoutem旨在成为React Native移动应用领域的WordPress

    近日,Shoutem推出了新的基于React Native的应用构建器,为开发人员提供了移动应用领域的WordPress. \\ Shoutem让开发人员可以使用一个可视化环境快速创建基于React ...

  10. android 动画学习总结

    本文内容是本人阅读诸多前辈的学习心得后整理的,若有雷同,请见谅 Android 动画 分类:帧动画,补间动画,属性动画  . 1.帧动画 将一张张单独的图片连贯的进行播放,从而在视觉上产生一种动画的效 ...