题目链接

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. 敏捷开发之Scrum站立会议

    Scrum是迭代式增量软件开发过程,通常用于敏捷开发.站立会议通常指Scrun方法中的每日站立会议.顾名思义,是每天以站姿的方式召开的会议.以下从功能及要点方面对其进行解释说明: 功能:     1. ...

  2. Ribbon源码解析

    SpringCloud中的Ribbon开源项目,提供了客户端的负载均衡算法.这篇文章,我们来介绍下他是如何实现的.为了方便理解,我们以客户端调用的流程来介绍,其中会穿插介绍相关源代码. 简单回顾下Ri ...

  3. php多维数组排序 3

    本文实例讲述了php简单实现多维数组排序的方法.分享给大家供大家参考,具体如下: 之前在做一个功能的时候,必须要把数据放到二维数组里并且排序,然后上网找找解决思路, 这时候会用到array_multi ...

  4. Vue 定时执行函数

    var app = new Vue({ el: '#app', data: { count: , }, filters: { }, mounted: function () { this.$nextT ...

  5. asp.netMVC中权限控制论

    这里设想了一个简单的思路,如果用户登录了,也就是session中有值才可以在控制器中操作,这样先添加一个控制器,如下代码: public class AuthController : Controll ...

  6. Java开发Excel POI getPhysicalNumberOfCells 与 getLastCellNum的区别

    1.getPhysicalNumberOfCells 与 getLastCellNum的区别 用org.apache.poi的包做excel导入,无意间发明若是excel文件中有空列,空列后面的数据全 ...

  7. 在Linux上编译使用tcmalloc

    项目需要使用tcmalloc,比较简单的方法是安装tcmalloc相关包(gpertools)后,将tcmalloc的静态库提取出来,在编译项目内核(执行makefile)时,链接上静态库即可. 这里 ...

  8. 降雨量 HYSBZ - 1067(RMQ)

    F.A.Qs Home Discuss ProblemSet Status Ranklist Contest 入门OJ Login Register 捐赠本站 Notice:1:注册本OJ方式请见ht ...

  9. 【洛谷】CYJian的水题大赛【第二弹】解题报告

    点此进入比赛 T1: JerryC Loves Driving 第一题应该就是一道水分题(然而我只水了130分),我的主要做法就是暴力模拟,再做一些小小的优化(蠢得我自己都不想说了). My Code ...

  10. 基于注解的spring mvc 中使用 ajax json 的model

    在 Spring mvc3中,响应.接受 JSON都十分方便. 使用注解@ResponseBody可以将结果(一个包含字符串和JavaBean的Map),转换成JSON. 使用 @RequestBod ...