博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #194 (Div. 1) A. Secrets 数学
阅读量:4668 次
发布时间:2019-06-09

本文共 2909 字,大约阅读时间需要 9 分钟。

A. Secrets

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/333/problem/A

Description

Gerald has been selling state secrets at leisure. All the secrets cost the same: n marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on. There are no coins of other denominations. Of course, Gerald likes it when he gets money without the change. And all buyers respect him and try to give the desired sum without change, if possible. But this does not always happen.

One day an unlucky buyer came. He did not have the desired sum without change. Then he took out all his coins and tried to give Gerald a larger than necessary sum with as few coins as possible. What is the maximum number of coins he could get?

The formal explanation of the previous paragraph: we consider all the possible combinations of coins for which the buyer can not give Gerald the sum of n marks without change. For each such combination calculate the minimum number of coins that can bring the buyer at least n marks. Among all combinations choose the maximum of the minimum number of coins. This is the number we want.

 

Input

The single line contains a single integer n (1 ≤ n ≤ 1017).

Please, do not use the %lld specifier to read or write 64 bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Output

In a single line print an integer: the maximum number of coins the unlucky buyer could have paid with.

 

Sample Input

1

Sample Output

1

HINT

 

题意

所有的硬币面额都是3的幂,给出价格N,假设N无法由目前所有的硬币组合成,那么求在多花最少钱的情况下最多用多少枚硬币.

题解:

N不断除3,直到N不是3的倍数,答案就是n/3+1

代码:

 

//qscqesze#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define maxn 200001#define mod 10007#define eps 1e-9int Num;char CH[20];//const int inf=0x7fffffff; //нчоч╢Сconst int inf=0x3f3f3f3f;/*inline void P(int x){ Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts("");}*/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;}inline void P(int x){ Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts("");}//**************************************************************************************ll n;int main(){ n=read(); while(n%3==0) n/=3; cout<

 

转载于:https://www.cnblogs.com/qscqesze/p/4528529.html

你可能感兴趣的文章
php apache 配置后不能正常显示html文件的解决方法
查看>>
FILE类型指针的头文件
查看>>
牛客网暑期ACM多校训练营(第五场)J-plan (模拟)
查看>>
如何做一个跨平台的游戏App?
查看>>
五、椒盐排骨
查看>>
loj136 (最小瓶颈路,多次询问)
查看>>
4.1字符类型统计
查看>>
discuz核心函数库function_core的函数注释
查看>>
[Python] 用python做一个游戏辅助脚本,完整思路
查看>>
(转载)linux中shell变量
查看>>
对象数组操作
查看>>
盘点selenium phantomJS使用的坑
查看>>
Android Studio优秀插件汇总
查看>>
oracle下的数据库实例、表空间、用户及其表的区分
查看>>
Jmeter中的变量(三)
查看>>
Oracle数据库备份dmp文件,使用cmd命令导入导出步骤,以及忘记Oracle密码
查看>>
20180601 -1
查看>>
jetty;linux 目录结构
查看>>
Codeforces914D Bash and a Tough Math Puzzle
查看>>
测试,发布,质量保障,用户体验
查看>>