2017 ACM-ICPC, Universidad Nacional de Colombia Programming Contest D

匿名 (未验证) 提交于 2019-12-02 22:56:40

Input

Output
For each one output a string of A’s and B’s giving the order in which the machines are used.

Examples
Input
7
Output
AAA
Input
10
Output
ABB

额。。。其实很简单的一道题。。
本来打算 dfs 的。。。。
然后T在19个点。

int dfs(int x) {     if (x > n)return 0;     if (x == n)return 1;     if (dfs(2 * x + 1)) {         vis[++tot] = 1;         return 1;     }     if (dfs(2 * x + 2)) {         vis[++tot] = 2;         return 1;     }     return 0; } 

其实分个奇偶就可以了。。。

#include<iostream> #include<cstdio> #include<algorithm> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<set> #include<vector> #include<queue> #include<string> #include<bitset> #include<ctime> #include<deque> typedef long long ll; using namespace std; typedef unsigned long long int ull; #define maxn 30005 #define ms(x) memset(x,0,sizeof(x)) #define Inf 0x7fffffff #define inf 0x3f3f3f3f const long long int mod = 1e9 + 7; #define pi acos(-1.0) #define pii pair<int,int> #define eps 1e-7 #define pll pair<ll,ll>    ll quickpow(ll a, ll b) {     ll ans = 1;     a = a % mod;     while (b > 0) {         if (b % 2)ans = ans * a;         b = b / 2;         a = a * a;     }     return ans; }  int gcd(int a, int b) {     return b == 0 ? a : gcd(b, a%b); }   int n; int vis[maxn]; int tot;  void dfs() {     while (n) {         if (n % 2 == 0) {             vis[++tot] = 2;             n = (n - 2) / 2;         }         else {             vis[++tot] = 1;             n = (n - 1) / 2;         }     } }   int main() { //  ios::sync_with_stdio(false); //  cin >> n;     scanf("%d", &n);     dfs();     for (int i = tot; i >= 1; i--) {         if (vis[i] == 1)printf("A");         else if (vis[i] == 2)printf("B");     }     printf("\n"); }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!