博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ural 1261. Tips(进制运算)
阅读量:7191 次
发布时间:2019-06-29

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

1261. Tips

Time limit: 1.0 second
Memory limit: 64 MB
The favorite resting place of the Ural programmers is Threenland island. There is only one tribulation: dollars and euro don’t go about here. So the tourists are to exchange their money into threets (the currency of Threenland). There go about 1 threet, 3 threets, 9 threets, 27 threets, …, 3
k threets, … Once programmer Vasechkin, after the 
N-threets bill was given to him found out, that he’d got one paper of each denomination. Waiters in Threenland have a custom to keep the change. Waiters like to get the tip that can be presented by a set of papers in which paper of each denomination appears not more than once. Otherwise their feelings are hurt. They have a peeve on a client if they don’t get tips at all. Help please Vasechkin to pay for the dinner and not to hurt the waiter.

Input

consists of an integer 
N. 1 ≤ 
N ≤ 10 7.

Output

Output two integers separated with a space – that is the sum that Vasechkin is to pay and an amount of tips. If there are several solutions choose any of them. If there is no solution output 0. Remember that Ural programmers are not rich, so Vasechkin can’t pay more than 4294967291 threets.

Sample

input output
5
9 4

 

题意:给出一个数n,要求求出两个数a,b;a和b的3进制表示没有2;并且b+n=a;并且按a b的格式输出;

思路:利用进制运算的思想,将给出的数n变成3进制表示,然后再2出现的位置加1,直到没有了2为止,并且在加的过程中记录加数;最后这个加数便是b;

 

1 #include 
2 using namespace std; 3 int tip=0,bill=0,n,m=1; 4 int main() 5 { 6 cin >> n; 7 bill=n; 8 do 9 {10 if (n%3==2)11 {12 tip+=m;13 ++n;14 }15 n/=3,m*=3;16 }while (n);17 if (!tip) tip=m;18 cout <
<< ' ' << tip << endl;19 return 0;20 }
View Code

 

 

转载于:https://www.cnblogs.com/zhangchengbing/p/3416500.html

你可能感兴趣的文章
SSDT 结构体
查看>>
android 银联支付接入报nullexception异常
查看>>
配置OSPF
查看>>
EIGRP邻居关系
查看>>
x3850X5如何添加CPU和QPI Wrap Card及两节点配置说明
查看>>
12.3、bash脚本循环语句
查看>>
用C语言实现“智障”的棋盘游戏
查看>>
JavaScript的对象——灵活与危险
查看>>
如何看待sds?
查看>>
隔行换色
查看>>
-- 小白python2之函数
查看>>
如何不用那么担心成为一个坏程序员
查看>>
基于SSM的驾校预约报名管理系统-java驾校预约报名管理系统
查看>>
#8 bash的颜色显示规则
查看>>
用python写的判断质数和登录程序升级版
查看>>
18.6 负载均衡集群介绍 18.7 LVS介绍 18.8 LVS调度算法 18.9/18.10 L
查看>>
Apache安装部署
查看>>
CCNA网络技术实验手册:Cisco IOS备份与升级
查看>>
相关VB.NET文件对象基础知识讲解
查看>>
简单描述Servlet Filter(过滤器) 相关知识
查看>>