Cheap Travel(暴力求解法)

原创 2015年11月21日 09:47:31
A. Cheap Travel
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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 ntimes. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?

Input

The single line contains four space-separated integers nmab (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.

Output

Print a single integer — the minimum sum in rubles that Ann will need to spend.

Sample test(s)
input
6 2 1 2
output
6
input
5 2 2 3
output
8
Note

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趟旅行,有一种票一张可做m趟旅行,有一种票只能做一次旅行,价格分别为a,b

解题思路:由于数据量小,可直接暴力求解

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

#define MAX_N 1000005//可由数据推得最大票价不会超过这个数

int n,m,a,b,ans;

int main()
{
	while(cin>>n>>m>>a>>b)
	{
		ans=MAX_N;
		for(int i=0;i<=n;i++)
		{
			int j=(n-i)/m + bool((n-i)%m);
			
			ans = min(ans,i*a+j*b);
		}
		
		cout<<ans<<endl;
	}
	return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

Codeforces Cheap Travel

import java.util.Scanner; public class CheapTravel { public static void main(String[] args) { S...
  • Lutte_
  • Lutte_
  • 2017年06月22日 09:57
  • 94

A. Cheap Travel

解题说明:此题是一道简单的模拟题,要么每次买票,要么买一次票用mci
  • jj12345jj198999
  • jj12345jj198999
  • 2014年09月13日 19:58
  • 555

CodeForces 466A Cheap Travel

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description A...
  • ALONENanGong
  • ALONENanGong
  • 2016年01月14日 10:33
  • 167

【CODEFORCES】 A. Cheap Travel

A. Cheap Travel time limit per test 1 second memory limit per test 256 megabytes in...
  • S_Black
  • S_Black
  • 2015年02月06日 16:10
  • 472

466A. Cheap Travel

A. Cheap Travel time limit per test 1 second memory limit per test 256 megabytes input standar...
  • daima66699
  • daima66699
  • 2017年01月25日 14:45
  • 127

cf466A Cheap Travel

A. Cheap Travel time limit per test 1 second memory limit per test 256 megabytes in...
  • zhb1997
  • zhb1997
  • 2014年09月13日 22:06
  • 368

Codeforces 466A - Cheap Travel

A. Cheap Travel time limit per test 1 second memory limit per test 256 megabytes input standar...
  • Nicholafs
  • Nicholafs
  • 2017年07月19日 10:31
  • 96

CodeForces 466A Cheap Travel

Description Ann has recently started commuting by subway. We know that a one ride subway ticket cos...
  • geekdoe
  • geekdoe
  • 2015年12月31日 16:53
  • 326

codeforces——466A——Cheap Travel

A. Cheap Travel time limit per test 1 second memory limit per test 256 megabytes input s...
  • lose__way
  • lose__way
  • 2017年05月20日 17:19
  • 120

Codeforces 466 A. Cheap Travel

A. Cheap Travel time limit per test 1 second memory limit per test 256 megabytes in...
  • u012797220
  • u012797220
  • 2014年09月13日 10:21
  • 1818
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Cheap Travel(暴力求解法)
举报原因:
原因补充:

(最多只允许输入30个字)