题意:从 0,0坐标开始走,你第k(从0开始)步只能走 从 x坐标或者y坐标增加 3^k的坐标,问你给定 x,y,按照这种规则能否走到
解题思路:题意可以理解为把这两个坐标的和转化为3进制,从第一位到最高位全都为1;
解题代码:
1 // BEGIN CUT HERE 2 /* 3 4 */ 5 // END CUT HERE 6 #line 7 "PowerOfThreeEasy.cpp" 7 #include <cstdlib> 8 #include <cctype> 9 #include <cstring> 10 #include <cstdio> 11 #include <cmath> 12 #include <algorithm> 13 #include <vector> 14 #include <string> 15 #include <iostream> 16 #include <sstream> 17 #include <map> 18 #include <set> 19 #include <queue> 20 #include <stack> 21 #include <fstream> 22 #include <numeric> 23 #include <iomanip> 24 #include <bitset> 25 #include <list> 26 #include <stdexcept> 27 #include <functional> 28 #include <utility> 29 #include <ctime> 30 using namespace std; 31 32 #define PB push_back 33 #define MP make_pair 34 35 #define REP(i,n) for(i=0;i<(n);++i) 36 #define FOR(i,l,h) for(i=(l);i<=(h);++i) 37 #define FORD(i,h,l) for(i=(h);i>=(l);--i) 38 39 typedef vector<int> VI; 40 typedef vector<string> VS; 41 typedef vector<double> VD; 42 typedef long long LL; 43 typedef pair<int,int> PII; 44 int ans[1000] = {0}; 45 46 void solve(int t) 47 { 48 49 int k = 0 ; 50 while(t) 51 { 52 k ++ ; 53 ans[k] += (t % 3); 54 t = t/3; 55 } 56 } 57 class PowerOfThreeEasy 58 { 59 public: 60 string ableToGet(int x, int y) 61 { 62 memset(ans,0,sizeof(ans)); 63 solve(x); 64 solve(y); 65 int i ; 66 for(i = 200;i >= 0;i --) 67 if(ans[i] != 0 ) 68 break; 69 // printf("%d ",i); 70 for(;i >= 1; i --) 71 if(ans[i] != 1) 72 return "Impossible"; 73 return "Possible"; 74 } 75 };