HDU 6085 Rikka with Candies (bitset)
来源:互联网 发布:java 大并发处理 编辑:程序博客网 时间:2024/06/07 06:13
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
Output
For each query, print a single line with a single 01 digit – the answer.
Sample Input
15 5 51 2 3 4 51 2 3 4 50 1 2 3 4
Sample Output
00001
题意
思路
考虑枚举
我们用
用
此时
AC 代码
#include<bits/stdc++.h>using namespace std;const int maxn = 5e4+10;bitset<maxn>a,b;bitset<maxn>ans,cnt;void slove(int maxK){ cnt.reset(); ans.reset(); for(int i=maxK; i>=0; --i) //枚举k { ans[i]=(cnt&(a>>i)).count()&1; //存在多少个(a-i)%b=0 if(b[i]) //枚举 i 的倍数 for(int j=0; j<maxn; j+=i) cnt.flip(j); }}template <class T>inline void scan_d(T &ret){ char c; ret = 0; while ((c = getchar()) < '0' || c > '9'); while (c >= '0' && c <= '9') { ret = ret * 10 + (c - '0'), c = getchar(); }}int main(){ int T; scan_d(T); while(T--) { int n,m,q; scan_d(n); scan_d(m); scan_d(q); a.reset(); b.reset(); int maxK=0; for(int i=0; i<n; ++i) { int x; scan_d(x); a.set(x); } for(int i=0; i<m; ++i) { int x; scan_d(x); b.set(x); maxK=max(maxK,x); } slove(maxK); while(q--) { int x; scan_d(x); puts(ans[x]?"1":"0"); } } return 0;}
- HDU 6085 Rikka with Candies (bitset)
- HDU 6085 Rikka with Candies(bitset)
- HDU 6085 Rikka with Candies (bitset)
- Hdu 6085 Rikka with Candies【思维+Bitset】
- hdu 6085 Rikka with Candies bitset
- HDU 6085 Rikka with Candies 模拟bitset
- hdu 6085 Rikka with Candies(bitset容器)
- HDU 6085 Rikka with Candies(bitset操作+思路转化)
- HDU 6085 Rikka with Candies 压位 bitset区间提取
- hdu 6085 Rikka with Candies(bitset 计数原理)
- 【多校训练】hdu 6085 Rikka with Candies bitset
- hdu 6085 Rikka with Candies bitset优化计数
- HDU 6085 Rikka with Candies (bitset, 2017 Multi-Univ Training Contest 5)
- HDU 6085 Rikka with Candies(2017多校第五场)bitset枚举
- HDU 6085 Rikka with Candies
- HDU 6085 Rikka with Candies
- HDU 6085 Rikka with Candies
- hdu 6085 Rikka with Candies
- VectorDrawable异常处理
- 微信公众号回复消息-微信公众号使用教程14
- 数据挖掘概念与技术第三版 范明、孟晓峰译 第三章习题答案
- 解析JION
- BZOJ2049: [Sdoi2008]Cave 洞穴勘测
- HDU 6085 Rikka with Candies (bitset)
- Python使用pandas读取Excel文件数据和预处理小案例
- 树莓派3连接pi cam摄像头
- 1 Linux基础知识
- [Linux]进程与线程
- Java垃圾收集算法—深入理解Java虚拟机(七)
- 一个链表中,如果有环则输出环的入口节点,否则输出NULL
- C3P0错误APPARENT DEADLOCK!!!解决
- LinuxStudyNote(43)-RPM包查询命令、查询是否安装、查询包详细信息、查询包中文件安装位置、查询系统文件属于哪个rpm包、查询软件包的依赖性