940B Our Tanya is Crying Out Loud
题目大意
给你n,k,A,B四个数,x=n,有两种操作:
1.将x-1,需支付A个金币
2.将x÷k,需支付B个金币,当且仅当k能整除x时可进行此操作
问将x修改为1至少要花几个金币
分析
模拟两个过程,如果k能整除x则判断一个一个将x减到想x/k和将x除以k哪个花费的金币少,否则如果x大于k将x减去x模k的余数(不可每次减1,减若干次,否则会超时),x小于k则减去(x-1)。注意特判k等于1的情况。
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int main()
{ long long n,m,i,j,k,x,a,b,ans=0;
cin>>n>>k>>a>>b;
x=n;
if(k==1){
cout<<(n-1)*a<<endl;
return 0;
}
while(x!=1){
if(x%k!=0){
if(x>k){
ans+=(x%k)*a;
x=x-x%k;
}else {
ans+=(x-1)*a;
x=1;
}
}else {
if((x-x/k)*a<b){
ans+=(x-x/k)*a;
x=x/k;
}else {
x=x/k;
ans+=b;
}
}
}
cout<<ans<<endl;
return 0;
}
940B Our Tanya is Crying Out Loud的更多相关文章
- codeforce round#466(div.2) B. Our Tanya is Crying Out Loud
B. Our Tanya is Crying Out Loud time limit per test1 second memory limit per test256 megabytes input ...
- Codeforces Round #466 (Div. 2) B. Our Tanya is Crying Out Loud[将n变为1,有两种方式,求最小花费/贪心]
B. Our Tanya is Crying Out Loud time limit per test 1 second memory limit per test 256 megabytes inp ...
- CF940B Our Tanya is Crying Out Loud
Our Tanya is Crying Out Loud time limit per test 1 second memory limit per test 256 megabytes input ...
- 「日常训练」Our Tanya is Crying Out Loud (CFR466D2B)
题意(Codeforces 940B) 对一个数字$x$,你有两个决策:花费$A$减一.或花费$B$除以$k$(但必须可以除尽).问使之到$1$的最少花费. 分析 贼鸡儿简单,但我花式犯蠢……如果除不 ...
- B. Our Tanya is Crying Out Loud
http://codeforces.com/problemset/problem/940/B Right now she actually isn't. But she will be, if you ...
- Codeforces Round #466 (Div. 2) Solution
从这里开始 题目列表 小结 Problem A Points on the line Problem B Our Tanya is Crying Out Loud Problem C Phone Nu ...
- Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...
- Codeforces Round #466 (Div. 2)
所有的题目都可以在CodeForces上查看 中间看起来有很多场比赛我没有写了 其实是因为有题目没改完 因为我不想改,所以就没有写了(大部分题目还是改完了的) 我还是觉得如果是打了的比赛就一场一场写比 ...
- Codeforces Round #466 (Div. 2) 题解
人生中第三次\(CF\)... 考试中切了\(A\)~\(E\) \(F\)题会做没时间写 题解 A:Points on the line 题意 给定一个数列,删最小的数,使最大差不大于一个定值 So ...
随机推荐
- Uva 12171 Sculpture - 离散化 + floodfill
题目连接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- 我的java学习之路--Java注解专题
学习网址:http://www.imooc.com/video/8861 1.引言 2.Java中的常见注解 JDK自带注解:<br>@Override @Deprecated @Supp ...
- 通过与Quickbuild和Mist.io的持续集成实现云管理和使用监控
欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 这篇文章由巴拉克·梅里莫维奇撰写. 总结我自己有关Openstack的各种骚操作先告一段落.这一次我想谈谈有关监控云服务的使用情况. 我个人使用 ...
- python3 第一章 - 简介
1.什么是python 引用官方的话:Python是一种易于学习,强大的编程语言.它具有高效的高级数据结构,并通过简单而有效的方法来进行面向对象编程.Python的优雅语法和动态类型,以及其解释性质, ...
- 基于jQuery表单快速录入数据功能
一.功能介绍:完全依靠jQuery,表单table新增行(按键盘tab增一行,按esc删一行),也可以加一个新增行按钮点击新增多行,这里就不多说了~~ 二.该功能主要实现技术: 1,总体.NET MV ...
- junit4X系列--Rule
原文出处:http://www.blogjava.net/DLevin/archive/2012/05/12/377955.html.感谢作者的无私分享. 初次用文字的方式记录读源码的过程,不知道怎么 ...
- [搬运] .NET Core 2.1中改进的堆栈信息
原文 : Stacktrace improvements in .NET Core 2.1 作者 : Ben Adams 译者 : 张很水 . NET Core 2.1 现在具有可读的异步堆栈信息!使 ...
- android Android SDK Manager遇到的问题
打开Android SDK Manager 1点击左上角的tools-->options:将Proxy Settings 里的HTTP Proxy Server和HTTP Proxy Port分 ...
- grep使用技巧一:模式pattern为字符串文件
pattern文件: antc areq bdos bogt …… igs.txt文件: abmf 298.4725 16.2623 abpo 47.2292 -19 ...
- #pragma once 与 #ifndef 解析
转自:http://www.cnblogs.com/hokyhu/archive/2009/03/30/1425604.html 为了避免同一个文件被include多次,C/C++中有两种方式,一种是 ...