试题A :组队
490
试题B :年号字串
// BYQ
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
string res = "";
int n = 2019;
while (n)
{
n -- ;
res += (char)('A' + n % 26);
n /= 26;
}
reverse(res.begin(), res.end());
cout << res;
}
试题C :数列求值
// 4659
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 3e7;
int f[N];
int main()
{
f[1] = 1;
f[2] = 1;
f[3] = 1;
for (int i = 4; i <= 20190324; i ++ )
f[i] = (f[i - 3] + f[i - 2] + f[i - 1]) % 10000;
cout << f[20190324];
}
试题D :数的分解
// 40785
#include <iostream>
#include <algorithm>
using namespace std;
bool check(int n)
{
while (n)
{
int now = n % 10;
if (now == 2 || now == 4) return true;
n /= 10;
}
return false;
}
int main()
{
int res = 0;
for (int i = 1; i < 2019; i ++ )
{
if (check(i)) continue;
for (int j = i + 1; j < 2019; j ++ )
{
if (check(j)) continue;
for (int k = j + 1; k < 2019; k ++ )
{
if (check(k)) continue;
if (i + j + k == 2019) res ++ ;
}
}
}
cout << res;
}
试题E :迷宫
#include <iostream>
#include <queue>
using namespace std;
const int N = 55;
struct Point
{
int x, y;
string road;
};
int n = 30, m = 50;
char g[N][N];
bool vis[N][N];
int dx[] = {1, 0, 0, -1}, dy[] = {0, -1, 1, 0};
char op[] = {'D', 'L', 'R', 'U'};
void bfs()
{
queue<Point> que;
vis[0][0] = true;
que.push({0, 0, ""});
while (que.size())
{
auto t = que.front(); que.pop();
if (t.x == n - 1 && t.y == m - 1)
{
cout << t.road;
return ;
}
for (int i = 0; i < 4; i ++ )
{
int ax = t.x + dx[i], ay = t.y + dy[i];
if (ax < 0 || ax >= n || ay < 0 || ay >= m) continue;
if (!vis[ax][ay] && g[ax][ay] == '0')
{
Point pt = {ax, ay, t.road + op[i]};
vis[ax][ay] = true;
que.push(pt);
}
}
}
}
int main()
{
for (int i = 0; i < n; i ++ )
{
scanf("%s", g[i]);
getchar();
}
bfs();
}
试题F :特别数的和
#include <iostream>
using namespace std;
bool check(int x)
{
while (x)
{
int now = x % 10;
if (now == 2 || now == 0 || now == 1 || now == 9) return true;
x /= 10;
}
return false;
}
int main()
{
int n; cin >> n;
int res = 0;
for (int i = 1; i <= n; i ++ )
{
if (check(i)) res += i;
}
cout << res;
}
试题G :完全二叉树的权值
#include <iostream>
#include <vector>
using namespace std;
vector<int> ve[20];
int ww[20];
int level;
int calc(int b)
{
int res = 1;
for (int i = 1; i <= b + 1; i ++ ) res *= 2;
return res - 1;
}
int main()
{
int n; cin >> n;
int power = calc(0);
for (int i = 1, w; i <= n && scanf("%d", &w); i ++ )
{
if (i > power)
{
level ++ ;
power = calc(level);
}
ve[level].push_back(w);
}
int mx = 0, ans;
for (int i = 0; i <= level; i ++ )
{
for (auto j : ve[i])
ww[i] += j;
if (ww[i] > mx)
{
mx = ww[i];
ans = i;
}
}
cout << ans + 1;
}
试题H :等差数列
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
int n, a[N];
int main()
{
scanf("%d", &n);
for (int i = 0; i < n && scanf("%d", &a[i]); i ++ );
sort(a, a + n);
int d = 1e9 + 10;
for (int i = 1; i < n; i ++ )
d = min(d, a[i] - a[i - 1]);
if (d == 0)
{
cout << n;
return 0;
}
printf("%d", (a[n - 1] - a[0]) / d + 1);
}
试题I :后缀表达式
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int n, m;
int a[N];
int main()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < n + m + 1 && scanf("%d", &a[i]); i ++ );
sort(a, a + n + m + 1);
ll res = 0;
if (!m)
{
for (int i = 0; i < n + m + 1; i ++ ) res += a[i];
}
else
{
res = a[n + m] - a[0];
for (int i = 1; i < n + m; i ++ )
res += abs(a[i]);
}
cout << res;
}
试题J :灵能传输