题目链接

Problem Description

As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

There are n children and m kinds of candies. The ith child has Ai dollars and the unit price of the ith kind of candy is Bi. The amount of each kind is infinity.

Each child has his favorite candy, so he will buy this kind of candies as much as possible and will not buy any candies of other kinds. For example, if this child has 10 dollars and the unit price of his favorite candy is 4 dollars, then he will buy two candies and go home with 2 dollars left.

Now Yuta has q queries, each of them gives a number k. For each query, Yuta wants to know the number of the pairs (i,j)(1≤i≤n,1≤j≤m) which satisfies if the ith child’s favorite candy is the jth kind, he will take k dollars home.

To reduce the difficulty, Rikka just need to calculate the answer modulo 2.

But It is still too difficult for Rikka. Can you help her?

Input

The first line contains a number t(1≤t≤5), the number of the testcases.

For each testcase, the first line contains three numbers n,m,q(1≤n,m,q≤50000).

The second line contains n numbers Ai(1≤Ai≤50000) and the third line contains m numbers Bi(1≤Bi≤50000).

Then the fourth line contains q numbers ki(0≤ki<maxBi) , which describes the queries.

It is guaranteed that Ai≠Aj,Bi≠Bj for all i≠j.

Output

For each query, print a single line with a single 01 digit -- the answer.

Sample Input

1

5 5 5

1 2 3 4 5

1 2 3 4 5

0 1 2 3 4

Sample Output

0

0

0

0

1

题意:

有N个人,每个人拥有Ai的钱,有M种物品,每个物品的单位价值是Bj,每种物品的数量都是无限的,我们现在有一个查询X,表示询问存在多少对购买方案对,使得Ai%Bj==X.

输出方案数%2的结果。

分析:

我们开两个bitset,tmp里边存的是拥有i的钱的人是否存在,如果存在,该位为1,否则为0.ans里边存的是价格为i的物品是否存在,我们等比例放大物品的购买倍数即可。

然后我们预处理答案暴力跑一下。

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<bitset>
using namespace std;
int vis[50040];
int output[50050];
bitset<50050>tmp,ans,temp;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(vis,0,sizeof(vis));
tmp.reset();//初始化,将所有的二进制定位0
ans.reset();
int n,m,qq,maxx=0;
scanf("%d%d%d",&n,&m,&qq);
int x;
for(int i=1; i<=n; i++)
{
scanf("%d",&x);
tmp.set(x);//将tmp中x处的二进制改为1
}
for(int i=1; i<=m; i++)
{
scanf("%d",&x);
maxx=max(maxx,x);
vis[x]=1;//标记单价
}
for(int i=maxx; i>=0; i--)
{
temp=ans&(tmp>>i);//tmp中的二进制向右移动i位
output[i]=temp.count()%2;//计算temp中二进制为1的个数
if(vis[i]==1)
for(int j=0; j<=maxx; j+=i)
ans.flip(j);//二进制取反
}
while(qq--)
{
scanf("%d",&x);
printf("%d\n",output[x]);
}
}
return 0;
}

2017ACM暑期多校联合训练 - Team 5 1001 HDU 6085 Rikka with Candies (模拟)的更多相关文章

  1. 2017ACM暑期多校联合训练 - Team 8 1008 HDU 6140 Hybrid Crystals (模拟)

    题目链接 Problem Description Kyber crystals, also called the living crystal or simply the kyber, and kno ...

  2. 2017ACM暑期多校联合训练 - Team 6 1001 HDU 6096 String (字符串处理 字典树)

    题目链接 Problem Description Bob has a dictionary with N words in it. Now there is a list of words in wh ...

  3. 2017ACM暑期多校联合训练 - Team 5 1006 HDU 5205 Rikka with Graph (找规律)

    题目链接 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, s ...

  4. 2017ACM暑期多校联合训练 - Team 2 1001 HDU 6045 Is Derek lying? (模拟)

    题目链接 Problem Description Derek and Alfia are good friends.Derek is Chinese,and Alfia is Austrian.Thi ...

  5. 2017ACM暑期多校联合训练 - Team 1 1001 HDU 6033 Add More Zero (数学)

    题目链接 Problem Description There is a youngster known for amateur propositions concerning several math ...

  6. 2017ACM暑期多校联合训练 - Team 4 1004 HDU 6070 Dirt Ratio (线段树)

    题目链接 Problem Description In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the foll ...

  7. 2017ACM暑期多校联合训练 - Team 9 1005 HDU 6165 FFF at Valentine (dfs)

    题目链接 Problem Description At Valentine's eve, Shylock and Lucar were enjoying their time as any other ...

  8. 2017ACM暑期多校联合训练 - Team 9 1010 HDU 6170 Two strings (dp)

    题目链接 Problem Description Giving two strings and you should judge if they are matched. The first stri ...

  9. 2017ACM暑期多校联合训练 - Team 8 1006 HDU 6138 Fleet of the Eternal Throne (字符串处理 AC自动机)

    题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion ...

随机推荐

  1. nodejs 调试

    什么语言入门的准备功能就是写helloworld, 调试. 用惯了chrome的话,推荐用chrome自带的调试器来调试.很方便. 在地址栏中输入 chrome://inspect 并按回车,会打开如 ...

  2. mysql(五)查询缓存

    mysql的逻辑架构图如下: 当开启查询缓存时,mysql会将查询结果缓存到查询缓存区域,结果对应的key是使用查询语句,数据库名称,客户端协议的版本等因素算出的一个hash值. 在下次查询时,根据一 ...

  3. stm32中使用#pragma pack(非常有用的字节对齐用法说明)

    #pragma pack(4)   //按4字节对齐,但实际上由于结构体中单个成员的最大占用字节数为2字节,因此实际还是按2字节对齐 typedef struct { char buf[3];//bu ...

  4. Simple上网导航--静态版

    现在的网址导航显然是一个针对小白用户的网页大全,新闻.笑话.视频.黄段子要什么有什么,一个网址导航竟然也要滑动好多页.其实80%的功能我都用不到,但是它们却时刻展现在我的眼前.所以我决定做一个简洁清晰 ...

  5. appium使用H5怎么定位元素

    允许是一个class,如果遇到有多个class,只能填写一个. 对于移动端H5元素定位采用Chromedriver的解决方案,具体操作如下: 1.手机安装Chrome浏览器 2.开启USB调试模式,并 ...

  6. Day22-CSRF跨站请求伪造

    csrf 跨站请求伪造 一.简介 django为用户实现防止跨站请求伪造的功能,通过中间件 django.middleware.csrf.CsrfViewMiddleware 来完成. 1.1 第1次 ...

  7. LiveCD及Casper调研

    1.LiveCD原理 LiveCD本质上是ISO 9660/El Torito格式的CD-ROM. 下面对LiveCD涉及的各种技术做了简单的调研. 1.1. CD-ROM CD-ROM是一种光盘存储 ...

  8. ACID和CAP, BASE

      ACID:关系型数据库中事务的4个属性:   Atomicity,原子性,整个事务的所有操作,要么全部完成,要么全部不完成,不可能停滞在中间的某个环节.事务在执行过程中出错,会回滚到事务开始前的状 ...

  9. 导出ORACLE表结构到SQL语句(含CLOB)

      转自:http://blog.itpub.net/84738/viewspace-442854/ 先用exp导出空表 exp username/password rows=n file=expor ...

  10. 【刷题】BZOJ 2753 [SCOI2012]滑雪与时间胶囊

    Description a180285非常喜欢滑雪.他来到一座雪山,这里分布着M条供滑行的轨道和N个轨道之间的交点(同时也是景点),而且每个景点都有一编号i(1<=i<=N)和一高度Hi. ...