2016.3.24 ACM算法讨论群群赛

套题链接: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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值