A - Still TBD
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long LL;
int main(){
string s;
cin >> s;
if (s[5] == '1') cout << "TBD" << endl;
else if(s[6]>'4')
cout << "TBD" << endl;
else
cout << "Heisei" << endl;
return 0;
}
B - Digital Gifts
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long LL;
int n;
double res = 0;
int main(){
cin >> n;
for (int i = 0; i < n;i++){
double x;
string s;
cin >> x >> s;
if (s == "JPY") res += x;
else
res += 380000.0 * x;
}
cout << res << endl;
return 0;
}
C - Synthetic Kadomatsu
给出abc三个数,以及n个备选的数,每次可以花费1点魔法值,讲一个数+1,也可以花费10点魔法值,将两个数相加,问最少需要多少魔法值,获得最终的abc三个数,n<=8
dfs暴力算即可
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long LL;
int n, a, b, c;
int l[N];
int res = 0x3f3f3f3f;
void dfs(int now, int nowa, int nowb, int nowc, int add) {
if (now == n) {
if (nowa == a || nowb == b || nowc == c) return;
res = min(res, abs(nowa) + abs(nowb) + abs(nowc) + add);
return;
}
dfs(now + 1, nowa - l[now], nowb, nowc, add + (nowa == a ? 0 : 10));
dfs(now + 1, nowa, nowb - l[now], nowc, add + (nowb == b ? 0 : 10));
dfs(now + 1, nowa, nowb, nowc - l[now], add + (nowc == c ? 0 : 10));
dfs(now + 1, nowa, nowb, nowc, add);
}
int main() {
cin >> n >> a >> b >> c;
for (int i = 0; i < n; i++) cin >> l[i];
dfs(0, a, b, c, 0);
cout << res << endl;
return 0;
}
D - Lazy Faith
在数轴上有a和b两类点,现在给出一个点k,问从k点开始,走到最近的a点和b点一共需要走多远
对于输入的k,先lower_bound找到大于等于k的a点和b点,枚举走这两个点或者走较小的点的情况即可,一共四种情况
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long LL;
LL a[N], b[N];
int q, n, m;
int main() {
cin >> n >> m >> q;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
while (q--) {
LL now;
cin >> now;
int posa = lower_bound(a, a + n, now) - a;
int posb = lower_bound(b, b + m, now) - b;
LL res = 0x3f3f3f3f3f3f3f3f;
if (posa > 0 && posb < m) {
res = min(res, b[posb] - a[posa - 1] +
min(now - a[posa - 1], b[posb] - now));
}
if (posa < n && posb > 0) {
res = min(res, a[posa] - b[posb - 1] +
min(now - b[posb - 1], a[posa] - now));
}
if(posa<n&&posb<m){
res = min(res, max(a[posa], b[posb]) - now);
}
if(posa>0&&posb>0){
res = min(res, now - min(a[posa - 1], b[posb - 1]));
}
cout << res << endl;
}
return 0;
}