[USACO Nov08]玩具toys解题报告
题目
分析
代码
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<deque>
using namespace std;
typedef long long LL;
const int SIZEN=100010;
const int INF=0x7fffffff/2;
int N;
int price;
int slow_cost,slow_wait,fast_cost,fast_wait;
int need[SIZEN]={0};
deque<pair<int,int> > can_slow,can_fast,late;//first是日期,second是个数
int calc(int buy){//购买buy个int ans=buy*price;can_fast.clear();can_slow.clear();late.clear();for(int i=1;i<=N;i++){while(!late.empty()&&late.front().first<=i-fast_wait){can_fast.push_back(late.front());late.pop_front();}while(!can_fast.empty()&&can_fast.front().first<=i-slow_wait){can_slow.push_back(can_fast.front());can_fast.pop_front();}int now=need[i];int t=min(now,buy);now-=t,buy-=t;while(now&&!can_slow.empty()){t=min(now,can_slow.back().second);ans+=t*slow_cost;now-=t,can_slow.back().second-=t;if(!can_slow.back().second) can_slow.pop_back();}while(now&&!can_fast.empty()){t=min(now,can_fast.back().second);ans+=t*fast_cost;now-=t,can_fast.back().second-=t;if(!can_fast.back().second) can_fast.pop_back();}if(now) return INF;late.push_back(make_pair(i,need[i]));}return ans;
}
void work(void){int l=0,r=0;for(int i=1;i<=N;i++) r+=need[i];while(r-l>2){int m1=(2*l+r)/3,m2=(l+2*r+2)/3;int f1=calc(m1),f2=calc(m2);if(f1>=f2) l=m1;else r=m2;}int ans=INF;for(int i=l;i<=r;i++) ans=min(ans,calc(i));printf("%d\n",ans);
}
void read(void){scanf("%d",&N);scanf("%d%d",&fast_wait,&slow_wait);scanf("%d%d",&fast_cost,&slow_cost);if(fast_wait>slow_wait){swap(fast_wait,slow_wait);swap(fast_cost,slow_cost);}if(slow_cost>fast_cost){slow_wait=fast_wait;slow_cost=fast_cost;}scanf("%d",&price);for(int i=1;i<=N;i++) scanf("%d",&need[i]);
}
int main(){freopen("toy.in","r",stdin);freopen("toy.out","w",stdout);read();work();return 0;
}
[USACO Nov08]玩具toys解题报告相关推荐
- USACO 1.3... 虫洞 解题报告(搜索+强大剪枝+模拟)
这题可真是又让我找到了八数码的感觉...哈哈.首先,第一次见题,没有思路,第二次看题,感觉是搜索,就这样写下来了.这题我几乎是一个点一个点改对的(至于为什么是这样,后面给你看一个神奇的东西),让我发现 ...
- USACO Betsy's Tour 解题报告
大神做了这道题:https://www.byvoid.com/blog/usaco-544-betsys-tour.解释得非常清楚,我也是按照这种方法做的,即统计"必经点"的个数, ...
- USACO 3.3.2 Shopping Offers解题报告
写在前面:因为之前没写的C++的USACO Training的解题报告太多--所以就不写了,要是想要代码可以联系我:xiedong_1993@foxmail.com 这题就是传说中的五维背包,其实写起 ...
- USACO Section2.1 Hamming Codes 解题报告 【icedream61】
hamming解题报告 ---------------------------------------------------------------------------------------- ...
- USACO Section2.2 Preface Numbering 解题报告 【icedream61】
preface解题报告 ---------------------------------------------------------------------------------------- ...
- USACO Section1.3 Combination Lock 解题报告
combo解题报告 -- icedream61 博客园(转载请注明出处) --------------------------------------------------------------- ...
- USACO Section1.5 Superprime Rib 解题报告
sprime解题报告 -- icedream61 博客园(转载请注明出处) -------------------------------------------------------------- ...
- USACO Training Section 1.3 Calf Flac 解题报告AC代码
解题报告: 主要方法是生长法,考虑每一位的左右各有多长的回文串,输出最长的那个,比较好想--不过要注意区分字串的奇偶. 其他实现细节看代码里的注释吧-- AC代码: /* ID: yuanmz91 P ...
- 解题报告(五)组合计数(ACM / OI)超高质量题解
繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量题解和代码,题目难度不一定按照题号排序,我会在每道题后面加上题目难度指数(1∼51 \sim 51∼5),以模板题难度 11 ...
最新文章
- 2021年大数据Kafka(九):kafka消息存储及查询机制原理
- 神经科学家为视力受损的人研发新技术
- 页面加载后如何使JavaScript执行?
- golang设计模式之原型模式
- python 文件 IO 操作
- 【机器学习基础】XGBoost、LightGBM与CatBoost算法对比与调参
- 1048:有一门课不及格的学生
- matlab设计声音听听
- 【转】ELK 日志分析系统
- 知名网络安全专家访谈记
- python安装软件win10_在win10上安装Python和Tensorflow
- Java学习之==注释、数据类型、变量、运算符
- docker-简单操作
- [转载]----Hadoop2.0命令手册
- NOIP2013华容道
- 计算机学报范文,计算机学报论文
- PDF英文文档免费翻译成中文
- 2个月公众号粉丝破万的心路历程
- 宏观调控绝不是微观控制
- 室内声场计算机模拟的声线跟踪法和虚声源法,建筑物理课件.ppt