#include<bits/stdc++.h>
using namespace std;int n, r;
string c ="0123456789ABCDEFGHIJ";voidf(int n){
if(n ==0)return;int t = n % r;if(t <0) t -= r, n += r;f(n/r);
cout << c[t];}intmain(){
scanf("%d%d",&n,&r);printf("%d=", n);f(n);printf("(base%d)\n", r);return0;}
#include<bits/stdc++.h>
using namespace std;int n, r;
string c ="0123456789ABCDEFGHIJ";
stack <char> stk;intmain(){
scanf("%d%d",&n,&r);printf("%d=", n);while(n){
int t = n % r;if(t <0) t -= r, n += r;
n /= r;
stk.push(c[t]);}while(stk.size())printf("%c", stk.top()), stk.pop();printf("(base%d)\n", r);return0;}
2019 提高组D1T1 格雷码
递归,二分
#include<bits/stdc++.h>#defineullunsignedlonglong
using namespace std;
ull n, k;voidf(ull n, ull k){
if(n ==0)return;
n --;
ull t =(1ull<< n);if(k < t){
//左侧
cout <<0;f(n, k);}else{
//右侧
cout <<1;f(n,2*(t-1)-(k-1));}}intmain(){
cin >> n >> k;f(n, k);return0;}/*
0 || 1
00 01 || 11 10
000 001 011 010 || 110 111 101 100
*/
生成字符串,查找,50分
#include<bits/stdc++.h>#defineullunsignedlonglong
using namespace std;
ull n, k;
string s ="01", t;
stack <char> stk;intmain(){
cin >> n >> k;for(int i =1; i <= n; i ++){
t = s;reverse(t.begin
2000 提高组T1 进制转换进制、余数的理解递归、栈#include <bits/stdc++.h>using namespace std;int n, r;string c = "0123456789ABCDEFGHIJ";void f(int n) { if (n == 0) return; int t = n % r; if (t < 0) t -= r, n += r; f(n/r); cout << c[t];}int