2017ACM暑期多校联合训练 - Team 5 1001 HDU 6085 Rikka with Candies (模拟)
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 (模拟)的更多相关文章
- 2017ACM暑期多校联合训练 - Team 8 1008 HDU 6140 Hybrid Crystals (模拟)
题目链接 Problem Description Kyber crystals, also called the living crystal or simply the kyber, and kno ...
- 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 ...
- 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 ...
- 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 ...
- 2017ACM暑期多校联合训练 - Team 1 1001 HDU 6033 Add More Zero (数学)
题目链接 Problem Description There is a youngster known for amateur propositions concerning several math ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- TeamCity编译执行selenium上传窗口脚本缺陷
2015-07-04 18:05 编写本文 TeamCity编译selenium脚本,对于上传窗口处理只支持sendKeys的使用,不支持模拟人为按下Enter键和使用autoIt等操作,即使本地调试 ...
- redis 同步化操作
异步化操作是很麻烦的的.不好控.下面介绍个同步化的库bluebird.用法很简单.看下你还子就知道了 const redis = require('redis'); const bluebird = ...
- centos中apache自用常用额外配置记录(xwamp)
xwamp套件中apache配置,记录下,以免忘记. 配置路径 ${wwwroot_dir}/conf/httpd.conf 配置内容 <ifmodule mod_deflate.c> D ...
- WPF中Image控件的Source属性的设置
1.直接关联到文件,关联后不能删除此图片,因为图片正在使用. imageEditImage.Source = new BitmapImage(new Uri(strImagePath, UriKind ...
- js中关于array的常用方法
最近总结了一些关于array中的常用方法, 其中大部分的方法来自于<JavaScript框架设计>这本书, 如果有更好的方法,或者有关于string的别的常用的方法,希望大家不吝赐教. 第 ...
- svn和git的区别及适用场景
svn和git的区别及适用场景 来源 https://blog.csdn.net/wz947324/article/details/80104621 svn的优势: 优异的跨平台支持,对windows ...
- ZJOI2018 D1
归途的车上满是悲伤的气息 虽然早就预言到D1会滚粗,但一切都结束之后还是特别难过. 延时15min 50min T1 30pts 1.5h T2 10pts 2.5h T1 50pts 4.5h T3 ...
- 【BZOJ 4449】[Neerc2015]Distance on Triangulation 多边形分治结构
这题好神啊……正解方向是分治,据我所知的分治方法有:I.离线后直接对多边形以及所有的询问进行分治 II.建立多边形的分治结构(对于三角形来说类似线段树,对于对角线来说类似平衡树),然后每次在这个分治结 ...
- Lab颜色空间
原文:http://blog.csdn.net/carson2005/article/details/7200440 同RGB颜色空间相比,Lab是一种不常用的色彩空间.它是在1931年国际照明委员会 ...
- git 列出两个 commit 之间变更的文件列表
git diff <commit1> <commit2> --stat 如: git diff 74ecf17dc 1ee25ed3c --stat src/assets 上面 ...