2016.3.24 ACM算法讨论群群赛

来源:互联网 发布:终极算法 pdf 百度云 编辑:程序博客网 时间:2024/06/01 08:35

套题链接: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 secondusing namespace std;typedef long long LL;typedef pair<int,int> PII;// headconst 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 secondusing namespace std;typedef long long LL;typedef pair<int,int> PII;// headLL 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;}
0 0
原创粉丝点击