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 ...
随机推荐
- 一篇文章帮你解决python的包管理
写python代码的人都知道,一个项目写下下来,不可避免的都需要使用很多第三方包,通常我们都是通过pip install ,然而当我们需要上线的时候问题来了,如果中间你自己不记得自己安装了多少个包,这 ...
- Java ASM介绍
一.什么是ASM 首先看下官方中的说明 ASM a very small and fast Java bytecode manipulation framework. ASM是一个JAVA字节码分析. ...
- Java数据持久层框架 MyBatis之API学习三(XML 映射配置文件)
对于MyBatis的学习而言,最好去MyBatis的官方文档:http://www.mybatis.org/mybatis-3/zh/index.html 对于语言的学习而言,马上上手去编程,多多练习 ...
- Hyperledger Fabric Membership Service Providers (MSP)——成员服务
Membership Service Providers (MSP) 本文将介绍有关MSPs的设置和最佳实践的详细方案. Membership Service Providers (MSP)是一个旨在 ...
- python 实现词云
拿现在比较火的小说<大主宰>做测试,看看其中的关键词词云是啥 代码 import matplotlib.pyplot as plt from wordcloud import WordCl ...
- linux 如何降低入向软中断占比
最近遇到一个问题,当tcp收包的时候,我们的服务器的入向软中断比例很高. 我们知道,napi模式,可以降低收包入向软中断占比,那么,针对napi模式,能不能优化?本文针对2.6.32-358内核进行分 ...
- linux unzip 解压后文件名乱码
在windows上zip的包,rz上传到linux下,发现出现乱码.记录下解决过程: 1.确定windows上的默认字符集 在Windows平台下,直接在命令行中,输入:chcp 在显示的结果中,会出 ...
- System包含的信息
System类中的属性值 System.getProperty()方法大全 System.out.println("java版本号:" + System.getProperty(& ...
- Linux指令--touch
原文出处:http://www.cnblogs.com/peida/archive/2012/10/30/2745714.html linux的touch命令不常用,一般在使用make的时候可能会用到 ...
- 【转】利用matlab生成随机数函数
原文地址:利用matlab生成随机数函数 rand(n):生成0到1之间的n阶随机数方阵 rand(m,n):生成0到1之间的m×n的随机数矩阵 (现成的函数) betarnd:贝塔分布的随机数生成 ...