• 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. Samba完整篇 ubuntu 10.04

    基本的服务器准备工作 修改Root密码 sudo passwd root 在提示下建立新密码 修改静态IP: sudo gedit /etc/network/interfaces   #网络配置文件 ...

  2. iOS音频播放 (二):AudioSession 转

    原文出处 :http://msching.github.io/blog/2014/07/08/audio-in-ios-2/ 前言 本篇为<iOS音频播放>系列的第二篇. 在实施前一篇中所 ...

  3. 单一责任原则(SRP)

    1.就一个类而言,应该仅有一个引起它变化的原因. 2.在SRP中定义职责为:“变化的原因”.  如果你想到多个动机去改变这个类,那这个类就有多个职责

  4. C#高级编程五十四天----Lookup类和有序字典

    Lookup类 Dictionary<Tkey,TValue>仅仅为每一个键支持一个值.新类Lookup<Tkey,TValue>是.NET3.5中新增的,它类似与Dictio ...

  5. Qt Quick之StackView具体解释(2)

    在"StackView具体解释(1)"中,我们学习了StackView的基本使用方法,这次呢,我们来讲delegate的定制.被管理的View的生命周期.查找View等主题. 本文 ...

  6. c++运算符重载以及一些基本概念

    c++primer第四版435 1.赋值( = ), 下标( [ ] ) ,调用 (  ( )  ), 成员訪问箭头 (->)等操作符必须定义为成员,定义为非成员时,编译器报错 2. 像赋值一样 ...

  7. javaSE基础(二)

    文件:文件是信息在计算机上的保存形式. 可控式异常:一种必须被处理或必须在可能产生异常的方法中给出声明的异常. 可控式异常的三种处理方式: 1)try...catch捕获 2)throws语句往上抛 ...

  8. [Codeforces Education Round 6E] New Year Tree

    [题目链接] https://codeforces.com/contest/620/problem/E [算法] 显然 , 一棵子树的DFS序必然为连续的一段 用线段树维护颜色数即可 [代码] #in ...

  9. php语法错误导致服务器错误(500)解决

    PHP编码出错不提示,而是提示500错误,这对于开发来说,是很不方便的.下面讲解如何开启错误提示步骤: 1. 打开php.ini文件.以我的ubuntu为例,这个文件在: /etc/php5/apac ...

  10. Python不兼容问题

    今天遇到了一个Python2与3不兼容的坑. ride是基于robot框架的python自动化ui,但它只支持python2,而我电脑环境只有python3,想跑别人基于ride编写的测试用例,折腾了 ...