cf466A Cheap Travel
1 second
256 megabytes
standard input
standard output
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
The single line contains four space-separated integers n, m, a, b (1 ≤ n, m, a, b ≤ 1000) — the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Print a single integer — the minimum sum in rubles that Ann will need to spend.
6 2 1 2
6
5 2 2 3
8
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
题意是要买n张票,可以买1张价格是a,也可以买m张价格是b
忘记考虑全买m张的最后剩下来直接买m张比一张一张更优的情况了……wa了两次
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctime>
#define LL long long
using namespace std;
LL n,m,a,b;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int main()
{
n=read();m=read();a=read();b=read();
printf("%d",min(min(n*a,(n/m)*b+(n%m)*a),(n/m+1)*b));
}
cf466A Cheap Travel的更多相关文章
- codeforces 466A. Cheap Travel 解题报告
题目链接:http://codeforces.com/problemset/problem/466/A 题目意思:一个 ride 需要 a 卢布,m 个 ride 需要 b 卢布,这两种方案都可以无限 ...
- Codeforces Round #266 (Div. 2)
http://codeforces.com/contest/466 噗,b没写出来啊.a写完后过了40分钟了啊,罚时4次啊!果然太弱 总结: a题看错题,没有考虑m>=n其实也是可行的,导致调了 ...
- [codeforces] 暑期训练之打卡题(二)
每个标题都做了题目原网址的超链接 Day11<Given Length and Sum of Digits...> 题意: 给定一个数 m 和 一个长度 s,计算最大和最小在 s 长度下, ...
- cheap gucci bags for women finish fashion jewellery has to move
Is certainly his dresser seem or dress creation process into video clip. Bus dropped???? Especially ...
- 图论 - Travel
Travel The country frog lives in has nn towns which are conveniently numbered by 1,2,…,n. Among n(n− ...
- 【BZOJ-1576】安全路径Travel Dijkstra + 并查集
1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1044 Solved: 363[Sub ...
- Linux inode && Fast Directory Travel Method(undone)
目录 . Linux inode简介 . Fast Directory Travel Method 1. Linux inode简介 0x1: 磁盘分割原理 字节 -> 扇区(sector)(每 ...
- HDU - Travel
Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is t ...
- 2015弱校联盟(1) - I. Travel
I. Travel Time Limit: 3000ms Memory Limit: 65536KB The country frog lives in has n towns which are c ...
随机推荐
- BZOJ 2875 随机数生成器
http://www.lydsy.com/JudgeOnline/problem.php?id=2875 题意:给出mod,a,c,g,x0,n,xn=(a*xn-1+c)%mod,求xn%g 求A* ...
- asm_c515c.uew
/L20"ASM for C515C" Nocase Line Comment = ; String Chars = "' DisableMLS File Extensi ...
- 过程化开发2048智力游戏WebApp
时间荏苒,唯编程与青春不可辜负,感觉自己一直没有专心去提升编程的技能,甚是惭愧!!! 周五,无意间看到一个开发2048的视频,有点兴趣就动起手来了,虽然不擅长前端开发,在此献丑,分享一下自己使用过程化 ...
- ntp服务器池列表
CentOS: 0.centos.pool.ntp.org 1.centos.pool.ntp.org 2.centos.pool.ntp.org 国内可用的 ntp.fudan.edu.cn 复旦 ...
- 二十七、Java图形化界面设计——容器(JFrame)
摘自http://blog.csdn.net/liujun13579/article/details/7756729 二十七.Java图形化界面设计--容器(JFrame) 程序是为了方便用户使用的, ...
- poj 3301 Texas Trip(几何+三分)
Description After a day trip with his friend Dick, Harry noticed a strange pattern of tiny holes in ...
- ID(dfs+bfs)-hdu-4127-Flood-it!
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4127 题目意思: 给n*n的方格,每个格子有一种颜色(0~5),每次可以选择一种颜色,使得和左上角相 ...
- java值传递
Java使用按值传递的函数调用方式,这往往使我感到迷惑.因为在基础数据类型和对象的传递上,我就会纠结于到底是按值传递,还是按引用传递.其实经过学习,Java在任何地方,都一直发挥着按值传递的本色. 首 ...
- Cocos2d-X中实现菜单特效
Cocos2d-X中能够讲菜单和动作结合起来使用实现菜单特效 程序实例1:使用菜单和动作的组合实现菜单特效<一> #include "MenuItem.h" CCSce ...
- Oracle SQL函数之转换函数
chartorowid(c1) [功能]转换varchar2类型为rowid值 [参数]c1,字符串,长度为18的字符串,字符串必须符合rowid格式 [返回]返回rowid值 [示例] SQL> ...