CodeForces 333A Secrets
来源:互联网 发布:社交网络的坏处 编辑:程序博客网 时间:2024/05/21 06:48
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?
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.
题意:首先有一堆硬币,面值是3的n次方:1,3,9,27……,然后给你一个数n,让你用硬币去换,条件是:
你用硬币要尽可能的大于n并且最接近n;
你用的硬币数量要尽可能的多;
问要多少个硬币换取。
题解:首先1面值的不能用,然后找到第一个不能整除3的面值,用除数+1就是结果。
#include<iostream>#include<cstring>#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;int main(){ long long int n,t; long long int ans; while(~scanf("%lld",&n)) { if(n%3!=0) { ans=n/3+1; } else if(n%3==0) { t=3*3; while(t) { if(t==n) { ans=1; break; } else if(n%t!=0) { ans=n/t+1; break; } else t=t*3; } } printf("%lld\n",ans); }}
- CodeForces 333A Secrets
- 【codeforces 333A】 - Secrets
- CodeForces-333A-Secrets
- CodeForces 333A Secrets
- CodeForces 333A Secrets 题解&代码
- 【CodeForces 333A】Secrets(模拟)
- Codeforces Round #194 (Div. 1) / 333A Secrets(贪心)
- CF 333 A.Secrets【枚举】
- Secrets of a Super Hacker
- Codeforces 173B Chamber of Secrets 题解
- Codeforces Problem 333A
- CodeForces 173B Chamber of Secrets(最短路)
- Undocumented Windows 2000 Secrets: A Programmer's Cookbook
- CodeForces-a
- Codeforces 903A A
- ipsec.secrets
- ProBlogger: Secrets for Blogging Your Way to a Six-Figure Income
- [每天读一点英文:那些给我勇气的句子]Seven secrets to a great life
- Radar Installation(poj1328,贪心,区间交集问题)
- HDU 2196 Computer(经典树形DP)
- PHP打开文件模式比较
- Sarov zones(SGU171,排序+模拟,)
- Android之Fragment实现TabHost
- CodeForces 333A Secrets
- 内存管理单元mmu
- 批处理创建和修改环境变量
- java5.0中增强的for/in循环
- 小Q系列故事——大笨钟
- Minimal Coverage(ural1303,区间贪心)
- HTTP消息头
- New Year Bonus Grant(SGU195,贪心or区间DP)
- 手工打造可执行程序