• Appreciation to our TA, 王毅峰, who designed this task.

问题描述

Give you N numbers a[1]...a[n]

and M numbers b[1]...b[m]

For each b[k], if we can find i,j a[i] + a[j] = b[k] or a[i] = b[k] , we say k is a good number.

And you should only output the number of good numbers.

0 < n, m, a[i], b[j] <= 200000

sample input

3 6

1

3

5

2

4

5

7

8

9

sample output

4

b[1]...b[m] 2,4,5,7,8,9

2 = 1+1

4 = 1+3

5 = 5

8 = 3+5

问题解析

TA的本意是想让我们运用bitset的方法,然而我不太懂,所以投机取巧用了类似于桶排序的方式,之后我会再去研究一下TA的解法的。

My answer

#include <iostream>
using namespace std; int main() {
int tong1[200000] = {0};
int tong2[200000] = {0};
int n, m, temp, sum = 0;
cin >> n >> m;
while (n--) {
cin >> temp;
tong1[temp]++;
}
while (m--) {
cin >> temp;
tong2[temp]++;
}
for (int i = 1; i < 200000; i++) {
int pan = 0;
if (tong2[i] != 0) {
if (tong1[i] != 0) {
pan = 1;
} else {
for (int j = 1; j < i; j++) {
if (tong1[j] != 0 && tong1[i-j] != 0) {
pan = 1;
break;
}
}
}
if (pan == 1)
sum += tong2[i];
}
}
cout << sum << endl;
return 0;
}

TA's answer

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <bitset>
using namespace std;
const int maxn = 50001;
bitset<maxn> goal, now, tmp;
int a[maxn], n, m; void work() {
scanf("%d", &m);
goal.reset();
now.reset();
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
now.set(a[i]);
}
// scanf("%d", &m);
for (int i = 1; i <= m; ++i) {
int k;
scanf("%d", &k);
goal.set(k);
}
sort(a + 1, a + n + 1);
tmp = now;
for (int i = 1; i <= n; ++i) {
tmp = tmp << (a[i] - a[i - 1]);
now = now | tmp;
}
goal = goal & now;
printf("%d\n", goal.count());
} int main() {
while (scanf("%d", &n) != EOF) work();
}

LN : Eden Bitset_3的更多相关文章

  1. LN : Eden Polymorphic And OOP Design Pattern Abstract Factory

    Appreciation to our TA, +7, who designed this task. Client.cpp #include <iostream> #include &l ...

  2. HDU5977 Garden of Eden(树的点分治)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5977 Description When God made the first man, he ...

  3. DSY3163*Eden的新背包问题

    Description "寄没有地址的信,这样的情绪有种距离,你放着谁的歌曲,是怎样的心心静,能不能说给我听."失忆的Eden总想努力地回忆起过去,然而总是只能清晰地记得那种思念的 ...

  4. Ubuntu杂记——链接ln的使用:创建和删除符号链接

    原文链接:http://blog.csdn.net/janpylx/article/details/6761910 一 . 使用方式 ln [option] source_file dist_file ...

  5. linux命令大全之ln命令详解(创建软链接和硬链接)

    ln是linux中又一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个同步的链接,分为软链接.硬链接.软链接相当于windows的快捷方式,下面是使用方法和示例   ln是linux中又一 ...

  6. hdu-5977 Garden of Eden(树分治)

    题目链接: Garden of Eden Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  7. bzoj 3163: [Heoi2013]Eden的新背包问题

    Description "寄没有地址的信,这样的情绪有种距离,你放着谁的歌曲,是怎样的心心静,能不能说给我听."失忆的Eden总想努力地回忆起过去,然而总是只能清晰地记得那种思念的 ...

  8. liunx ln -s 软连接

    项目中遇到不同项目中上传图片共享问题 解决方法就用到了 liunx的ln -s 的软连接, 用法: liunx ln -s 文件路径 实现共享思路:不同的目录都软连接到同一个目录

  9. [CentOS] 指定命令别名:Alias & 软链接生成命令 ln -s

    参考:CentOS里alias命令详解 每天一个linux命令(35):ln 命令 1. Alias命令 功能描述:我们在进行系统的管理工作一定会有一些我们经常固定使用,但又很长的命令.那我们可以给这 ...

随机推荐

  1. [Unity3D]Unity3D游戏开发之从Unity3D到Eclipse

    ---------------------------------------------------------------------------------------------------- ...

  2. android PercentRelativeLayout 支持百分比来设置控件的宽高

    Android 最终官方支持按百分比来设置控件的宽高了. 我们先来看看效果:       看一下布局: PercentRelativeLayout <android.support.percen ...

  3. 【MySQL】Win7下修改MySQL5.5默认编码格式

    一般安装MySQL程序过程中,有一步骤是选择MySQL的默认编码格式的,程序默认为Latin1编码格式,当然也可以选择第三个选项,手动选择gbk或utf8编码格式,以支持中文数据.如下图: 现在问题出 ...

  4. Angular Scope解析与应用

    Scope层级结构 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA== ...

  5. ZOJ问题(2010浙江大学研究生复试上机题目[找规律] hdoj 3788)

    ZOJ问题 pid=3788">点击打开链接 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  6. SDUST 2844-Mineral Water(数学)

    Mineral Water nid=24#time" title="C.C++.go.haskell.lua.pascal Time Limit1000ms Memory Limi ...

  7. ubuntu下apache+mysql+php+mysql等之webserver搭建

    相信非常多人跟我一样,想搭建一个自己的webserver.网上资料非常多.可是因为版本号的区别,总是存在依照一个教程来做无法全然实现的问题.近期我也折腾了好几天,google不能用,仅仅能百度,真想说 ...

  8. Codeforces Round #319 (Div. 2)B. Modulo Sum DP

                                                             B. Modulo Sum                               ...

  9. 【uoj35】后缀排序

    后缀数组模板题 #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio ...

  10. 2018.09.09 DL24 Day2总结

    今天挂的有点惨…… T1.forging 这道题自己在考试的时候想出来了…… 这题是一个期望递推.我们首先考虑这么一件事,一枚硬币,你抛到正面停止,抛到反面继续抛,问期望抛的次数.是两次.我们假设期望 ...