ural 1261. Tips
2016-09-21 16:41
232 查看
1261. Tips
Time limit: 1.0 secondMemory 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
Outputtwo 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 |
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; }
相关文章推荐
- ural 1261. Tips(进制运算)
- URAL 1261
- URAL_1091_Tmutarakan Exams
- Ural 1014 Product of Digits 解题报告
- URAL 1016 Cube on the Walk
- URAL 1080 Map Coloring (BFS)
- URAL 1029 Ministry
- iOS Tips - 02
- URAL 1045 Funny Game
- URAL 1137Bus Routes (dfs)
- 10 Time Management Tips That Work
- UWP tips (与wp8.1的不同)
- Android Dev Tips (持续更新)
- Android Studio Tips -- 自定义Logcat
- URAL 1046 Geometrical dreams 用复平面
- URAL 1152 False Mirrors (DFS枚举)
- 架构Tips——海量数据
- [Voice Tips 2] IPHONE
- Java Interview Preparation Tips-Part 1: Core Java Interview Questions
- Socket tips: UDP Echo service - Client code