• 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. BZOJ——2190: [SDOI2008]仪仗队

    思路: 我们将其所在的位置设为(0,0),那么如果存在一个点(x,y),且有gcd(x,y)=k(k!=1),那么点(x/k,y/k)一定会将(x,y)挡住.而如果k=1,那么点(x,y)就一定会被看 ...

  2. 我的arcgis培训照片12

    来自:http://www.cioiot.com/successview-381-1.html

  3. 图解Windows下安装WebLogic

    Oracle 的Weblogic分开发者版本和生产版本,有32位和64位.一般生产版本的weblogic是64位的,安装文件是一个大小为1G多的jar包.去oracle官网上下载64版weblogic ...

  4. 【转】golang中的并行与并发

    原文:http://blog.csdn.net/taohaoge/article/details/27970421 ------------------------------------------ ...

  5. Dell PowerEdgeServerT110II USB Boot更新

    可引导USB设备更新Dell PowerEdge服务器 当显示Boot Options(“启动选项”)时,选择option 1(选项 1)以开始固件更新. 现在正在加载的Linux发行版本 然后固件更 ...

  6. java UDP聊天与文件传输

    package rgy.com.UDP3; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.Action ...

  7. Bootstrap 过渡效果 transition.js源码分析

    前言: 阅读建议:去github下载一个完整dom然后把,本篇代码复制进去然后运行就好了以地址 Bootstrap 自带的 JavaScript 插件的动画效果几乎都是使用 CSS 过渡实现的,那么判 ...

  8. html5 弹性布局

    html5 弹性布局 一.移动开发常用技巧 Viewport基本知识 设置布局Viewport的各种信息1.width=device-width: 设置Viewport视口宽度等于设备宽度2.init ...

  9. 洛谷P3216 [HNOI2011]数学作业

    题目描述 小 C 数学成绩优异,于是老师给小 C 留了一道非常难的数学作业题: 给定正整数 N 和 M,要求计算 Concatenate (1 .. N) Mod M 的值,其中 Concatenat ...

  10. 洛谷P2827 蚯蚓——思路题

    题目:https://www.luogu.org/problemnew/show/P2827 思路... 用优先队列模拟做的话,时间主要消耗在每次的排序上: 能不能不要每次排序呢? 关注先后被砍的两条 ...