• 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. dubbo服务的group和version

    group 当一个接口有多种实现时,可以用group区分 <!-- dubbo group 使用示例 --> <bean id="demoA" class=&qu ...

  2. 【nginx】nginx与apache的优缺点比较

    参考: http://zyan.cc/nginx_php_v6/ nginx相对于apache的优点: 1.轻量级,同样的web 服务,比apache服务器占用更少的内存及资源 2.抗并发,nginx ...

  3. Android基础新手教程——4.3.1 BroadcastReceiver牛刀小试

    Android基础新手教程--4.3.1 BroadcastReceiver牛刀小试 标签(空格分隔): Android基础新手教程 本节引言 本节我们将来学习Android四大组件中的第三个:Bro ...

  4. IIS网站无法启动,提示 另一个程序正在使用此文件

    s还用netstat -ano命令,观察哪一个进程正在使用80端口,任务管理中勾选PID,看看是哪个程序,关掉即可

  5. Estimating duration from bitrate, this may be inaccurate

    通过 ffmpeg  获取 媒体 播放时长 ./ffmpeg-linux64-v3.3.1 -i /tmp/mp30001.mp3 ffmpeg version N-86111-ga441aa90e8 ...

  6. 安装 pip pip 包 安装路径

    python2 -m pip install --upgrade pip --force-reinstall pip uninstall pandas pip install --install-op ...

  7. luogu2827 蚯蚓

    题目大意 本题中,我们将用符号[c]表示对c向下取整,例如:[3.0」= [3.1」= [3.9」=3. 蛐蛐国最近蚯蚓成灾了!隔壁跳蚤国的跳蚤也拿蚯蚓们没办法,蛐蛐国王只好去请神刀手来帮他们消灭蚯蚓 ...

  8. 【Silverlight】Bing Maps学习系列(二):通过Bing Maps Silverlight Control如何显示地图(转)

    [Silverlight]Bing Maps学习系列(二):通过Bing Maps Silverlight Control如何显示地图 如本系列第一篇你所介绍的,开发基于Silverlight的Bin ...

  9. 训练深度学习网络时候,出现Nan是什么原因,怎么才能避免?——我自己是因为data有nan的坏数据,clear下解决

    from:https://www.zhihu.com/question/49346370   Harick     梯度爆炸了吧. 我的解决办法一般以下几条:1.数据归一化(减均值,除方差,或者加入n ...

  10. [翻译]NUnit---Equality Asserts&& Identity Asserts (四)

    Equality Asserts 这些方法测试两个参数是否相等.语言不自动装修的普通类型可以使用对应的重载的方法. Comparing Numerics of Different Types 比较两个 ...