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

只要按照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. python三层架构

    conf/setting(配置文件)    一般是对utility进行相关设置   index(主文件) main函数触发某个对象的业务逻辑方法   model(数据库) admin  是对数据库的操 ...

  2. uva 11105 - Semi-prime H-numbers(数论)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/36644069 option=com_onli ...

  3. python用pyinstaller打包成exe文件

    版本为Python2.7 一.安装Pyinstaller 1.安装pywin32 下载安装文件:查找到跟自己适用的python版本及window系统版本匹配的pywin32,下载后安装  使用pip命 ...

  4. PAT 1062 Talent and Virtue[难]

    1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...

  5. PAT 1079 Total Sales of Supply Chain[比较]

    1079 Total Sales of Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors(经 ...

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

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

  7. (16)Cocos2d-x 多分辨率适配完全解析

    Overview 从Cocos2d-x 2.0.4开始,Cocos2d-x提出了自己的多分辨率支持方案,废弃了之前的retina相关设置接口,提出了design resolution概念. 3.0中有 ...

  8. EF Code First学习笔记:数据库创建(转)

    控制数据库的位置 默认情况下,数据库是创建在localhost\SQLEXPRESS服务器上,并且默认的数据库名为命名空间+context类名,例如我们前面的BreakAway.BreakAwayCo ...

  9. 网关服务Spring Cloud Gateway(三)

    上篇文章介绍了 Gataway 和注册中心的使用,以及 Gataway 中 Filter 的基本使用,这篇文章我们将继续介绍 Filter 的一些常用功能. 修改请求路径的过滤器 StripPrefi ...

  10. 20145326 《Java程序设计》第4周学习总结

    20145326 <Java程序设计>第4周学习总结 教材学习内容总结 第六章 一.何谓继承 1.继承共同行为 面向对象中,子类继承父类,避免重复的行为定义.不过并非为了避免重复定义行为就 ...