【二分】【动态规划】Codeforces Round #393 (Div. 1) B. Travel Card
水dp,加个二分就行,自己看代码。
2 seconds
256 megabytes
standard input
standard output
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare.
The fare is constructed in the following manner. There are three types of tickets:
- a ticket for one trip costs 20 byteland rubles,
- a ticket for 90 minutes costs 50 byteland rubles,
- a ticket for one day (1440 minutes) costs 120 byteland rubles.
Note that a ticket for x minutes activated at time t can be used for trips started in time range from t to t + x - 1, inclusive. Assume that all trips take exactly one minute.
To simplify the choice for the passenger, the system automatically chooses the optimal tickets. After each trip starts, the system analyses all the previous trips and the current trip and chooses a set of tickets for these trips with a minimum total cost. Let the minimum total cost of tickets to cover all trips from the first to the current is a, and the total sum charged before is b. Then the system charges the passenger the sum a - b.
You have to write a program that, for given trips made by a passenger, calculates the sum the passenger is charged after each trip.
The first line of input contains integer number n (1 ≤ n ≤ 105) — the number of trips made by passenger.
Each of the following n lines contains the time of trip ti (0 ≤ ti ≤ 109), measured in minutes from the time of starting the system. All ti are different, given in ascending order, i. e. ti + 1 > ti holds for all 1 ≤ i < n.
Output n integers. For each trip, print the sum the passenger is charged after it.
3
10
20
30
20
20
10
10
13
45
46
60
103
115
126
150
256
516
20
20
10
0
20
0
0
20
20
10
In the first example, the system works as follows: for the first and second trips it is cheaper to pay for two one-trip tickets, so each time 20 rubles is charged, after the third trip the system understands that it would be cheaper to buy a ticket for 90 minutes. This ticket costs 50rubles, and the passenger had already paid 40 rubles, so it is necessary to charge 10rubles only.
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[100010],f[100010];
int main()
{
freopen("b.in","r",stdin);
scanf("%d",&n);
for(int i=1;i<=n;++i)
scanf("%d",&a[i]);
for(int i=1;i<=n;++i)
{
f[i]=f[i-1]+20;
int *p=lower_bound(a+1,a+n+1,a[i]-89);
f[i]=min(f[i],f[p-a-1]+50);
p=lower_bound(a+1,a+n+1,a[i]-1439);
f[i]=min(f[i],f[p-a-1]+120);
printf("%d\n",f[i]-f[i-1]);
}
return 0;
}
【二分】【动态规划】Codeforces Round #393 (Div. 1) B. Travel Card的更多相关文章
- Codeforces Round #393 (Div. 2)
A. Petr and a calendar time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition)A 水 B 二分 C并查集
A. Petr and a calendar time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #393 (Div. 2) - B
题目链接:http://codeforces.com/contest/760/problem/B 题意:给定n张床,m个枕头,然后给定某个特定的人(n个人中的其中一个)他睡第k张床,问这个人最多可以拿 ...
- Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) E - Nikita and stack 线段树好题
http://codeforces.com/contest/760/problem/E 题目大意:现在对栈有m个操作,但是顺序是乱的,现在每输入一个操作要求你输出当前的栈顶, 注意,已有操作要按它们的 ...
- Codeforces 1104 D. Game with modulo-交互题-二分-woshizhizhang(Codeforces Round #534 (Div. 2))
D. Game with modulo time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 【二分】Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string
题意:交互题:存在一个至少有一个0和一个1的长度为n的二进制串,你可以进行最多15次询问,每次给出一个长度为n的二进制串,系统返回你此串和原串的海明距离(两串不同的位数).最后要你找到任意一个0的位置 ...
- 【二分】Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market
傻逼二分 #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ll ...
- 【二分】Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale
当m>=n时,显然答案是n: 若m<n,在第m天之后,每天粮仓减少的量会形成等差数列,只需要二分到底在第几天,粮仓第一次下降到0即可. 若直接解不等式,可能会有误差,需要在答案旁边扫一下. ...
- Codeforces Round #393 (Div. 2) - C
题目链接:http://codeforces.com/contest/760/problem/C 题意:有n个烤串,并且每个烤串起初都放在一个火盆上并且烤串都正面朝上,现在定义p序列,p[i]表示在i ...
随机推荐
- JS让任意图片垂直水平居中且页面不滚动
说一下以前遇到的一个问题: 假设有一张小图,要实现点击查看大图的功能,而这个图的宽高可能会超过浏览器的宽高,这时候我们通过JS来改变图片的宽高,从而实现图片在浏览器居中显示且不滚屏. 方法如下: 首先 ...
- 关于IE6的一些总结
开篇之前,循例简单说说IE6的一些背景吧. IE6是指微软浏览器系列中的第六个版本,它是在2001年的时候伴随着XP系统的问世而同时推出的一款浏览器.因为XP普及的原因,这款浏览器一度问鼎全球浏览器市 ...
- sublime JSX Html 标签补全
Preferences -> Package Settings -> Emmet ->key bindings – user { "keys": ["t ...
- Dom4j解析语音数据XML文档(注意ArrayList多次添加对象,会导致覆盖之前的对象)
今天做的一个用dom4j解析声音文本的xml文档时,我用ArrayList来存储每一个Item的信息,要注意ArrayList多次添加对象,会导致覆盖之前的对象:解决方案是在最后将对象添加入Array ...
- GDOI2015的某道题目
分析: 考试的时候由于一些神奇的原因(我就不说是什么了)...没有想$C$题,直接交了个暴力上去... 然后发现暴力的数组开的太大,由于矩阵乘法的需要做$m$次初始化,所以只拿到了10分... 我们一 ...
- MDIO/MDC(SMI)接口-leonwang202
ChinaUnix博客 http://blog.chinaunix.net/uid-24148050-id-132863.html
- swift mac 使用git, 并使用osc, 打开当前目录命令在终端输入 open . windows 下为start .
使用git.osc而不用github, 因为在osc里面可以设置私有项目,而不需要公开. ssh-keygen -t rsa -C "email@email.com" mac下生成 ...
- The service base of EF I am using
using CapMon.Data; using System; using System.Collections.Generic; using System.Linq; using System.T ...
- 正则表达式解析基本json
var str='{"state": "SUCCESS","original": "C:\Users\liuhao_a\Deskt ...
- Linux kernel中断子系统之(五):驱动申请中断API【转】
转自:http://www.wowotech.net/linux_kenrel/request_threaded_irq.html 一.前言 本文主要的议题是作为一个普通的驱动工程师,在撰写自己负责的 ...