A 进制转换
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
char ans[50];
int tail = 0;
while (n > 0) {
int k = n % m;
n /= m;
if (k < 10)
ans[tail++] = k + '0';
else
ans[tail++] = k - 10 + 'A';
}
for (int i = tail - 1; i >= 0; i--) {
cout << ans[i];
}
cout << endl;
return 0;
}
B 进制转换
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
int len = s.size();
int k = len - 1;
cout << s[0] << "*" << n << "^" << k;
for (int i = 1; i < len; i++) {
k--;
if (s[i] == '0') continue;
cout << "+" << s[i] << "*" << n << "^" << k;
}
cout<<endl;
return 0;
}
C 进制转换
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, ans = 0;
string s;
cin >> n >> s >> m;
int len = s.size();
int k = 1;
for (int i = len - 1; i >= 0; i--) {
int t;
if (s[i] >= 'A' && s[i] <= 'F') {
t = s[i] - 'A' + 10;
} else {
t = s[i] - '0';
}
ans += t * k;
k *= n;
}
char a[50];
int tail=0;
while(ans>0){
int t=ans%m;
ans/=m;
char c;
if(t>=10){
c=t-10+'A';
}else{
c=t+'0';
}
a[tail++]=c;
}
for(int i=tail-1;i>=0;i--){
cout<<a[i];
}
cout<<endl;
return 0;
}
D 传染
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m, x;
cin >> n >> m;
x = 1;
while (m--) {
x = x * (n + 1);
}
cout << x << endl;
return 0;
}
E 跳马问题
#include <bits/stdc++.h>
using namespace std;
int a[30][30];
int next_x[4] = {-1, -2, -2, -1};
int next_y[4] = {-2, -1, 1, 2};
int main() {
int n, m;
cin >> n >> m;
a[0][0] = 1;
for (int i = 0; i <= m; i++) {
for (int j = 0; j <= n; j++) {
for (int l = 0; l < 4; l++) {
int x = i + next_x[l];
int y = j + next_y[l];
if (x >= 0 && x <= m && y >= 0 && y <= n) {
a[i][j] += a[x][y];
}
}
}
}
cout << a[m][n] << endl;
return 0;
}
F 台阶问题
#include<bits/stdc++.h>
using namespace std;
const int N=100010;
const int mod=100003;
int a[N];
int main(){
int n,k;
cin>>n>>k;
int sum=0;
for(int i=1;i<=k;i++){
a[i]=sum+1;
a[i]%=mod;
sum+=a[i];
sum%=mod;
}
for(int i=k+1;i<=n;i++){
a[i]=sum;
sum+=a[i];
sum-=a[i-k];
sum=(sum+mod)%mod;
}
cout<<a[n]<<endl;
return 0;
}
G 全排列问题
#include <bits/stdc++.h>
using namespace std;
bool book[10];
int a[10], n;
void solve(int tail) {
if (tail > n) {
for (int i = 1; i < n; i++) printf("%5d",a[i]);
printf("%5d\n",a[n]);
return;
}
for(int i=1;i<=n;i++){
if(!book[i]){
book[i]=true;
a[tail]=i;
solve(tail+1);
book[i]=false;
}
}
}
int main() {
scanf("%d",&n);
solve(1);
return 0;
}