zoukankan      html  css  js  c++  java
  • ural 1261. Tips

    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
    具体参考这里
     1 #include <iostream>
     2 #include <sstream>
     3 #include <fstream>
     4 #include <string>
     5 #include <vector>
     6 #include <deque>
     7 #include <queue>
     8 #include <stack>
     9 #include <set>
    10 #include <map>
    11 #include <algorithm>
    12 #include <functional>
    13 #include <utility>
    14 #include <bitset>
    15 #include <cmath>
    16 #include <cstdlib>
    17 #include <ctime>
    18 #include <cstdio>
    19 #include <cstring>
    20 #define FOR(i, a, b)  for(int i = (a); i <= (b); i++)
    21 #define RE(i, n) FOR(i, 1, n)
    22 #define FORP(i, a, b) for(int i = (a); i >= (b); i--)
    23 #define REP(i, n) for(int i = 0; i <(n); ++i)
    24 #define SZ(x) ((int)(x).size )
    25 #define ALL(x) (x).begin(), (x.end())
    26 #define MSET(a, x) memset(a, x, sizeof(a))
    27 using namespace std;
    28 
    29 
    30 typedef long long int ll;
    31 typedef pair<int, int> P;
    32 int read(){
    33     int x=0,f=1;char ch=getchar();
    34     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    35     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    36     return x*f;
    37 }
    38 const double pi=3.14159265358979323846264338327950288L;
    39 const double eps=1e-6;
    40 const int mod = 1e9 + 7;
    41 const int INF = 0x3f3f3f3f;
    42 const int MAXN = 1005;
    43 const int xi[] = {0, 0, 1, -1};
    44 const int yi[] = {1, -1, 0, 0};
    45 
    46 int N, T;
    47 
    48 int main() {
    49     //freopen("in.txt", "r", stdin);
    50     long long int n, m, bill = 0, s = 1;
    51     scanf("%I64d", &n); 
    52     m = n;;
    53     do{
    54         if(n%3 == 2){
    55             bill += s;
    56             n++;
    57         }
    58         n /= 3, s *= 3;
    59     }while(n);
    60     s*=3;
    61     if(!bill) bill = s;
    62     printf("%I64d %I64d
    ", bill+m, bill);
    63     return 0;
    64 }
     
  • 相关阅读:
    洛谷 P1786 帮贡排序 题解
    Bayes++ Library入门学习之熟悉UKF相关类
    Bayes++ Library入门学习之熟悉class-Bayesian_filter_base(2)
    Bayes++ Library入门学习之熟悉class-Importance_resampler
    Bayes++ Library入门学习之熟悉class-Bayesian_filter_base(1)
    Bayes++ Library入门学习之熟悉namespace
    CMake入门之创建一个基于PCL的最小工程
    CUDA学习之从CPU架构说起
    #pragma 预处理指令详解
    C++中inline函数
  • 原文地址:https://www.cnblogs.com/cshg/p/5893245.html
Copyright © 2011-2022 走看看