您的位置:首页 > 其它

ural 1261. Tips

2016-09-21 16:41 232 查看

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,
…, 3k 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 ≤ 107.

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

inputoutput
5

9 4

Problem Author: Alexander Ipatov
Problem Source: Open collegiate programming contest for high school children of the Sverdlovsk region, October 11, 2003
具体参考这里

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#define FOR(i, a, b)  for(int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i, 1, n)
#define FORP(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i <(n); ++i)
#define SZ(x) ((int)(x).size )
#define ALL(x) (x).begin(), (x.end())
#define MSET(a, x) memset(a, x, sizeof(a))
using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
int read(){
int 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;
}
const double pi=3.14159265358979323846264338327950288L;
const double eps=1e-6;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 1005;
const int xi[] = {0, 0, 1, -1};
const int yi[] = {1, -1, 0, 0};

int N, T;

int main() {
//freopen("in.txt", "r", stdin);
long long int n, m, bill = 0, s = 1;
scanf("%I64d", &n);
m = n;;
do{
if(n%3 == 2){
bill += s;
n++;
}
n /= 3, s *= 3;
}while(n);
s*=3;
if(!bill) bill = s;
printf("%I64d %I64d\n", bill+m, bill);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: