题解【CF466A】Cheap Travel

Mr_WA

2019-10-16 12:35:30

Solution

hello大家吼啊,我这个蓝名小蒟蒻又双叒叕来写题解啦!这是本蒟提交的唯一一篇翻译,当然要写篇题解纪念一下啦! 首先我们的思路当然是考虑买哪种票便宜,第一种票的价格为: ```c n/m*b+(n%m)*a ``` 第二种票的价格就不用说了,a*n搞定。 但是!但是!但是!有可能第一种票比第二种票便宜很多,买完n div m张票后,再买一张第一种票可能比第二种票要便宜,所以! ```c n/m*b+min((n%m)*a,b) ``` 这才是第二种票真正的价格! 然后,用一个min语句求较便宜的一种方案,如下: ```c min(n/m*b+min((n%m)*a,b),a*n) ``` 献上既不整齐也不美观的小破程序: ```c #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<string> using namespace std; int n,b,m,a; float s; int main() { cin>>n>>m>>a>>b; s=b/m; cout<<min(n/m*b+min((n%m)*a,b),a*n); return 0; } ``` 小破程序没什么好抄的,抄题勿提交,提交勿抄题!