[csu/coj 1083]贪心
题意:给定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]贪心的更多相关文章
- csu - 1538: Shopping (贪心)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1538 很奇妙的一个题,开始没有思路.问了别人才知道. 题目的意思可以理解成上图中,从0点开始向右走 ...
- [csu/coj 1619] 递归
题意:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1619 思路:由于式子具有递归的性质,考虑递归解,中间结果会超64位int,需用大数.另外自己 ...
- [csu/coj 1632]LCP
题意:求一个串的出现次数超过1次的字串的个数 思路:对于一个后缀,出现在它后面的所有后缀与它的LCP的最大值就是应该增加的答案,当然这里没有考虑去重,但是却转化了问题,使得我们可以用最长公共前缀来统计 ...
- [csu/coj 1078]多个序列的最长公共子序列
题意:给n个序列,同一个序列里面元素互不相同,求它们的最长公共子序列. 思路:任取一个序列,对于这个序列里面的两个数ai,aj(i<j),如果对于其它每一个序列,都出现过ai,aj,且ai在aj ...
- [csu/coj 1079]树上路径查询 LCA
题意:询问树上从u到v的路径是否经过k 思路:把树dfs转化为有根树后,对于u,v的路径而言,设p为u,v的最近公共祖先,u到v的路径必定是可以看成两条路径的组合,u->p,v->p,这样 ...
- [csu/coj 1080]划分树求区间前k大数和
题意:从某个区间内最多选择k个数,使得和最大 思路:首先题目给定的数有负数,如果区间前k大出现负数,那么负数不选和更大,于是对于所有最优选择,负数不会出现,所以用0取代负数,问题便转化为区间的前k大数 ...
- 【贪心】CSU 1809 Parenthesis (2016湖南省第十二届大学生计算机程序设计竞赛)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 题目大意: 给一个长度为N(N<=105)的合法括号序列.Q(Q<= ...
- ACM学习历程—CSU 1216 异或最大值(xor && 贪心 && 字典树)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1216 题目大意是给了n个数,然后取出两个数,使得xor值最大. 首先暴力枚举是C(n, ...
- CSU 1859 Gone Fishing(贪心)
Gone Fishing [题目链接]Gone Fishing [题目类型]贪心 &题解: 这题要先想到枚举走过的湖,之后才可以贪心,我就没想到这,就不知道怎么贪心 = = 之后在枚举每个湖的 ...
随机推荐
- IOC趣味理解
假设一个场景: 假设你是一个四岁孩子,饿了,想吃东西.怎么做? 1,哪有吃的去哪拿,你知道冰箱有吃的,你去冰箱拿〉会有风险.比如,拿了生的吃的,吃坏肚子,甚至拿了不能吃的东西. 2, 找父母(IO ...
- samba 客户端工具 smbclient和samba挂载到本地
smbclient命令属于samba套件,它提供一种命令行使用交互式方式访问samba服务器的共享资源. 安装 yum install -y samba-client 常用参数 -c<命令> ...
- linux上Docker安装gogs私服亲测(详解)
一.前言 有网友问我为什么要使用私服,可能大部分人都不是太懂,网上那么多存储仓库而且好用方便,但是你想过没有如果企业中的项目,放在人家的仓库上这个安全性不是太好,所以说一般企业都会有自己的私服.本章教 ...
- 漫谈LiteOS-端云互通组件-MQTT开发指南(下)
1.介绍 SDK简介 Agent Tiny是部署在具备广域网能力.对功耗/存储/计算资源有苛刻限制的终端设备上的轻量级互联互通中间件,您只需调用API接口,便可实现设备快速接入到物联网平台以及数据上报 ...
- 尤雨溪在直播中讲到的Vue3.0 Beta的那些特性,快记笔记了
前言 在那天风雨交加的夜晚,Vue的创作者尤雨溪尤大大在b站直播分享了Vue.js 3.0 Beta最新进展.我对直播的内容进行了一下整理.整整用了三天的空余时间赶上了 1. 全新文档RFCs Vue ...
- 微信小程序 POST传值跳坑
来源:https://www.cnblogs.com/ordinaryk/p/8430462.html 加这个就行了: header : { 'content-type': 'application/ ...
- thinkphp5.0 配置文件加载路径说明
在thinphp5.0框架里,js,css等配置文件都是加载在/public/static的目录下,所以要引用这些文件,路径必须是要写好的,代码如图: return [ // 默认模块名 'defau ...
- swift 3.0字符串的简单使用
let str:String = "12314124" 获取某个指定位置的元素 print(str.characters[str.index(str.startIndex, off ...
- bibernate中inverse和cascade用法
一口一口吃掉Hibernate(八)--Hibernate中inverse的用法 [转自 http://blog.csdn.net/xiaoxian8023 ] 一.Inverse是hibernate ...
- 10倍处理能力 阿里云推云上首个支持12层4K非编NAS产品
5月23日,阿里云在2017云栖大会·成都峰会上正式推出了云上首个支持广电级非编的文件存储产品------NAS Plus,作为阿里云文件存储NAS的升级款,NAS Plus提供高达200Gbps的吞 ...