如果没有必选的限制条件,就是水题了、、、

只要按照w + t排序就可以了,然后搞个堆来维护

于是有了限制条件,还是水题。。。

到了必选的时候强制选上,不加入堆中即可。

 /**************************************************************
Problem: 1555
User: rausen
Language: C++
Result: Accepted
Time:2228 ms
Memory:10948 kb
****************************************************************/ #include <cstdio>
#include <cctype>
#include <algorithm>
#include <queue> using namespace std;
typedef long long ll;
const int N = ; struct data {
int w, t, f;
}a[N];
bool operator < (const data &a, const data &b) {
return (ll) a.w + a.t < (ll) b.w + b.t;
} ll tot, V;
int n, m, w, ans;
priority_queue <int> q; inline ll read() {
ll x = ;
char ch = getchar();
while (!isdigit(ch))
ch = getchar();
while (isdigit(ch)) {
x = x * + ch - '';
ch = getchar();
}
return x;
} inline void del_top() {
tot -= q.top(), q.pop();
--ans;
} inline void add(int x) {
tot += a[x].w, q.push(a[x].w);
++ans;
} bool work() {
int i;
tot = ;
for (i = ; i <= n; ++i)
if (a[i].f == ) {
while (tot > a[i].t) {
if (q.empty()) return ;
del_top();
}
tot += a[i].w, ++ans;
}else {
if (!q.empty() && tot > a[i].t)
if (q.top() < a[i].w || tot - q.top() > a[i].t)
continue;
if (tot > a[i].t)
del_top();
add(i);
}
return ;
} int main() {
int i, X;
n = read(), m = read(), V = read();
for (i = ; i <= n; ++i)
a[i].w = read(), a[i].t = read();
for (i = ; i <= m; ++i) {
X = read(), a[X].f = ;
tot += a[X].w;
}
sort(a + , a + n + );
a[++n].f = , a[n].t = V;
if (!work()) puts("Foolish SD!");
else printf("%d\n", ans - );
return ;
}

(p.s. 怎么又想开fread二笔优化了呢、、、233)

BZOJ1555 KD之死的更多相关文章

  1. bzoj1555 KD之死 贪心+堆优化

    1555: KD之死 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 124  Solved: 54[Submit][Status][Discuss] D ...

  2. BZOJ 1555 KD之死

    贪心,按t+w排序维护不一定放到拖车上的大根堆. #include<iostream> #include<cstdio> #include<cstring> #in ...

  3. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  4. k-d tree模板练习

    1. [BZOJ]1941: [Sdoi2010]Hide and Seek 题目大意:给出n个二维平面上的点,一个点的权值是它到其他点的最长距离减最短距离,距离为曼哈顿距离,求最小权值.(n< ...

  5. 一起KVM环境下windows7虚拟机异常死机(BSOD)的问题解决

    先说一下环境: 一.硬件 8台服务器做的超融合架构,软件存储池, 每台服务器是96G内存,两颗Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz,32线程. 每台服务器是 ...

  6. mysql每秒最多能插入多少条数据 ? 死磕性能压测

    前段时间搞优化,最后瓶颈发现都在数据库单点上. 问DBA,给我的写入答案是在1W(机械硬盘)左右. 联想起前几天infoQ上一篇文章说他们最好的硬件写入速度在2W后也无法提高(SSD硬盘) 但这东西感 ...

  7. wp已死,metro是罪魁祸首!

    1.这篇文章肯定会有类似这样的评论:“我就是喜欢wp,我就是喜欢metro,我就是软粉“等类似的信仰论者发表的评论. 2.2014年我写过一篇文章,windows phone如何才能在中国翻身? 我现 ...

  8. APP测试点总结(功能,交互,死机崩溃状态分析,容易出错的检查点)

    APP测试点总结(功能,交互,死机崩溃状态分析,容易出错的检查点) 版权声明:本文为博主原创文章,未经博主允许不得转载. 最近涉足APP端测试,常见检查点总结如下:   一.业务方面: 1.  注册( ...

  9. 利用KD树进行异常检测

    软件安全课程的一次实验,整理之后发出来共享. 什么是KD树 要说KD树,我们得先说一下什么是KNN算法. KNN是k-NearestNeighbor的简称,原理很简单:当你有一堆已经标注好的数据时,你 ...

随机推荐

  1. JavaScript原型链的理解

    JavaScript中的每一个对象都有prototype属性,我们称之为原型,而原型的值也是一个对象,因此它有自己的原型,这样就串联起来形成了一条原型链.原型链的链头是object,它的prototy ...

  2. day14(编码实战-用户登录注册)

    day14 案例:用户注册登录 要求:3层框架,使用验证码   功能分析 注册 登录   1.1 JSP页面 regist.jsp 注册表单:用户输入注册信息: 回显错误信息:当注册失败时,显示错误信 ...

  3. centos shell基础 alias 变量单引号 双引号 history 错误重定向 2>&1 jobs 环境变量 .bash_history source配置文件 nohup & 后台运行 cut,sort,wc ,uniq ,tee ,tr ,split, paste cat> 2.txt <<EOF 通配符 glob模式 发邮件命令mail 2015-4-8 第十二节课

    centos shell基础知识 alias  变量单引号 双引号   history 错误重定向 2>&1  jobs  环境变量 .bash_history  source配置文件 ...

  4. PAT 1139 First Contact[难][模拟]

    1139 First Contact(30 分) Unlike in nowadays, the way that boys and girls expressing their feelings o ...

  5. google chrome插件开发,自己动手,丰衣足食

    因为平时上网都用chrome,但总感觉除了速度快,简洁以外总还有地方满足不了我的需要,然后找插件…后来发现,插件虽然海量但找个称心如意的也不是件容易的事儿,用在找插件的时间都能自己写一个了,于是,今年 ...

  6. SpringData_Repository接口概述

    Repository 接口是 Spring Data 的一个核心接口,它不提供任何方法,开发者需要在自己定义的接口中声明需要的方法  public interface Repository<T, ...

  7. EditPlus 4.3.2487 中文版已经发布(11月12日更新)

    新的版本修复了粘贴多重选择文本的问题,以及增加了横向扩展列选模式选择范围的快捷键(Ctrl+Alt+→/←).

  8. PHP保存Base64图片base64_decode的问题 文件打不开的问题

      PHP对Base64的支持非常好,有内置的base64_encode与base64_decode负责图片的Base64编码与解码. 编码上,只要将图片流读取到,而后使用base64_encode进 ...

  9. OpenVAS安装过程

    OpenVAS安装过程 安装过程 检查安装状况 命令行下输入opensav-check-setup,显示错误NO CA certificate file,并显示解决方法 创建证书 输入命令openva ...

  10. struts1和struts2比较