CodeForces - 948C Producing Snow(优先队列)
题意:
n天。
每天你会堆一堆雪,体积为 v[i]。每天都有一个温度 t[i] 所有之前堆过的雪在第 i 天体积都会减少 t[i] 。
输出每天融化了的雪的体积。

这个题的正解我怎么想都很难理解,但是慢慢理解了。
计算一个 t[i] 的前缀和 sum。
那么到第 j 天时,设第 i 堆雪融化的体积是 V,则 V = min (sum [ j ] - sum[ i-1], v[ i ] )
所以把 v[ i ] + sum[ i -1] 加入优先队列里,就可以只处理所有当天能化完的雪了。
若 sum[ j ] - v [i] + sum[i - i] <= 0,则证明第 i 堆雪在第 j 天能化完,对答案贡献为V。
否则对答案贡献为 t[i] 。
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std; #define maxn 100000 + 1000
typedef long long LL; int main()
{
int n;
scanf("%d", &n); int v[maxn], t[maxn];
for (int i = ; i <= n; i++)
scanf("%d", &v[i]); LL sum[maxn];
sum[] = ; for (int i = ; i <= n; i++)
{
scanf("%d", &t[i]);
sum[i] = sum[i-] + t[i];
} priority_queue<LL, vector<LL>, greater<LL> > q;
for (int i = ; i <= n; i++)
{
q.push(v[i] + sum[i-]);
LL ans = ;
while(!q.empty())
{
LL x = q.top();
if (sum[i]-x >= )//这堆雪第 i 天能够融化
{
ans += t[i] - (sum[i]-x);
q.pop();
}
else break; // 否则后面的都化不完了
}
ans += q.size() * t[i]; printf("%lld%c", ans, i==n? '\n':' ');
}
}
CodeForces - 948C Producing Snow(优先队列)的更多相关文章
- Codeforces 948C Producing Snow(优先队列+思维)
题目链接:http://codeforces.com/contest/948/problem/C 题目大意:给定长度n(n<=1e5),第一行v[i]表示表示第i堆雪的体积,第二行t[i]表示第 ...
- 2018.12.05 codeforces 948C. Producing Snow(堆)
传送门 维护一个堆. 每次先算出一个都不弹掉的总贡献. 然后把要弹掉的弹掉,并减去它们对应的贡献. 代码: #include<bits/stdc++.h> #define ri regis ...
- Codeforces I. Producing Snow(优先队列)
题目描述: C. Producing Snow time limit per test 1 second memory limit per test 256 megabytes input stand ...
- CodeForces - 948C(前缀和 + 二分)
链接:CodeForces - 948C 题意:N天,每天生产一堆雪体积 V[i] ,每天每堆雪融化 T[i],问每天融化了多少雪. 题解:对 T 求前缀和,求每一堆雪能熬过多少天,再记录一下多余的就 ...
- 【二分】Producing Snow @Codeforces Round #470 Div.2 C
time limit per test: 1 second memory limit per test: 256 megabytes Alice likes snow a lot! Unfortuna ...
- Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1) C.Producing Snow
题目链接 题意 每天有体积为Vi的一堆雪,所有存在的雪每天都会融化Ti体积,求出每天具体融化的雪的体积数. 分析 对于第i天的雪堆,不妨假设其从一开始就存在,那么它的初始体积就为V[i]+T[1. ...
- Codeforces 923 B. Producing Snow
http://codeforces.com/contest/923/problem/B 题意: 有n天,每天产生一堆体积为Vi的雪,每天所有雪堆体积减少Ti 当某一堆剩余体积vi<=Ti时,体积 ...
- [CodeForces948C]Producing Snow(优先队列)
Description 题目链接 Solution 将温度做一个前缀和,用一个优先队列依次处理一遍 思路还是很简单的 Code #include <cstdio> #include < ...
- Codeforces 681C. Heap Operations 优先队列
C. Heap Operations time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
随机推荐
- scrapy爬取美女图片
使用scrapy爬取整个网站的图片数据.并且使用 CrawlerProcess 启动. 1 # -*- coding: utf-8 -* 2 import scrapy 3 import reques ...
- Canada Cup 2016 D. Contest Balloons 好题。优先队列 + 简单贪心
http://codeforces.com/contest/725/problem/D 这题一看就是贪心的了,w - t最小的那个,肯定是优先打死. 但是一直都不会写,为什么呢,因为这个太像二分答案了 ...
- 作用域提升(Scope Hositing )是 Webpack 3 的标志性特征
http://blog.csdn.net/playboyanta123/article/details/73533079
- nodejs 实践:express 最佳实践(七) 改造模块 connect2 解析
nodejs 实践:express 最佳实践(七) 改造模块 connect2 解析 nodejs 发展很快,从 npm 上面的包托管数量就可以看出来.不过从另一方面来看,也是反映了 nodejs 的 ...
- 编译错误you should not run configure as root (set FORCE_UNSAFE_CONFIGURE=1 in environment to bypass this check)
解决方法: export FORCE_UNSAFE_CONFIGURE=1
- 电话号码 马赛克*号 string类扩展
/// <summary> /// 字符串马赛克 /// </summary> /// <param name="source"></pa ...
- (外挂破解)Cheat Engine(内存修改工具)V6.2中文版软件介绍
Heat Engine是一款内存修改编辑工具,Cheat Engine允许你修改你的游戏,所以你将总是赢.它包括16进制编辑,反汇编程序,内存查找工具.与同类修改工具相比,它具有强大的反汇编功能,且自 ...
- UVA 1616 Caravan Robbers 商队抢劫者(二分)
x越大越难满足条件,二分,每次贪心的选区间判断是否合法.此题精度要求很高需要用long double,结果要输出分数,那么就枚举一下分母,然后求出分子,在判断一下和原来的数的误差. #include& ...
- python_82_标准库_random模块
import random print(help(random.random)) #随机整数 print(random.randint(1,7))#生成一个[1, 7]的随机整数 print(rand ...
- c++ 读取文件 最后一行读取了两次
用ifstream的eof(),竟然读到文件最后了,判断eof还为false.网上查找资料后,终于解决这个问题. 参照文件:http://tuhao.blogbus.com/logs/21306687 ...