套题链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110383#overview
难度类型:后几题略烦。
A
题解
类型:模拟,位运算
直接暴力即可,计算海明距离的时候可以异或然后算 1 的个数。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
// head
const int N = 105;
int a[N];
int main() {
int t, n, m, x;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", a+i);
}
for (int i = 0; i < m; i++) {
scanf("%d", &x);
PII ans = PII(1e9, 0);
for (int j = 0; j < n; j++) {
int temp = __builtin_popcount(x ^ a[j]);
ans = min(ans, make_pair(temp, a[j]));
}
printf("%d\n", ans.se);
}
}
return 0;
}
B
题解
类型:链表,数据结构,模拟
传送门:http://blog.csdn.net/xc19952007/article/details/50990991
C
题解
类型:离散化,模拟
传送门:http://blog.csdn.net/xc19952007/article/details/50991304
D
题解
类型:最短路,递推优化
传送门:http://blog.csdn.net/xc19952007/article/details/50991345
E
题解
类型:数学,枚举
在范围内找立方和末尾为
3 的数,题目看了半天才看明白,感觉好冷啊。由于规模可以开三次根号,直接暴力枚举即可。 枚举的上界要松一些,因为是除 10 下取整。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
// head
LL cube(LL x) {
if (x >= 10000) return 1e12;
return x * x * x;
}
int main() {
LL a, b;
int cas = 1;
while (scanf("%lld%lld", &a, &b) == 2) {
int ans = 0;
LL mx = b * 11, temp;
for (int i = a; cube(i) <= mx; i++) {
for (int j = a; j <= b && (temp = cube(i) + cube(j)) <= mx; j++) {
if (temp % 10 == 3) {
temp /= 10;
if (temp >= a && temp <= b) ans++;
}
}
}
printf("Case %d: %d\n", cas++, ans);
}
return 0;
}