【多校训练】hdu 6085 Rikka with Candies bitset
来源:互联网 发布:荣威rx5 知乎 编辑:程序博客网 时间:2024/06/06 18:06
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 aren children and m kinds of candies. The i th child has Ai dollars and the unit price of the i th 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 has10 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 hasq 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 i th child’s favorite candy is the j th kind, he will take k dollars home.
To reduce the difficulty, Rikka just need to calculate the answer modulo2 .
But It is still too difficult for Rikka. Can you help her?
There are
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
Now Yuta has
To reduce the difficulty, Rikka just need to calculate the answer modulo
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 numbersn,m,q(1≤n,m,q≤50000) .
The second line containsn numbers Ai(1≤Ai≤50000) and the third line contains m numbers Bi(1≤Bi≤50000) .
Then the fourth line containsq numbers ki(0≤ki<maxBi) , which describes the queries.
It is guaranteed thatAi≠Aj,Bi≠Bj for all i≠j .
For each testcase, the first line contains three numbers
The second line contains
Then the fourth line contains
It is guaranteed that
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
题意:
两个长度分别为
思路:
求a%b==k的数量
->求a-k==b*j的数量
->可以用bitset优化成 ((a>>k)&bn).count(),bn为b的倍数。由于b一定要大于k,所以从大到小枚举。
具体看代码:
//// main.cpp// 1001//// Created by zc on 2017/8/30.// Copyright © 2017年 zc. All rights reserved.//#include <iostream>#include<cstring>#include<cstring>#include<cmath>#include<bitset>#include<algorithm>using namespace std;const int N=55000;bitset<N>a,b,ans,bn;int main(int argc, const char * argv[]) { int T; scanf("%d",&T); while(T--) { int n,m,q,t,mmax=0; a.reset();b.reset();ans.reset();bn.reset(); scanf("%d%d%d",&n,&m,&q); for(int i=0;i<n;i++) { scanf("%d",&t); a.set(t); } for(int i=0;i<m;i++) { scanf("%d",&t); b.set(t); mmax=max(mmax,t); } for(int i=mmax;i>=0;i--) { ans[i]=((a>>i)&bn).count()&1;//a%b==k, b>k -> a-k==j*b, b>k -> (a>>k)&bn if(b[i]) { for(int j=0;j<N;j+=i) bn.flip(j); } } for(int i=0;i<q;i++) { scanf("%d",&t); if(ans[t]) puts("1"); else puts("0"); } }}
阅读全文
0 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)
- 2017多校训练Contest5: 1001 Rikka with Candies hdu6085
- HDU-2017 多校训练赛5-1001-Rikka with Candies
- 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 6090 Rikka with Graph
- 【多校训练】 hdu 6092 Rikka with Subset
- HDU 6085 Rikka with Candies(2017多校第五场)bitset枚举
- HDU 6085 Rikka with Candies
- python,Windows环境安装及导入beautifulsoup
- RSA密钥,JAVA与.NET之间转换
- java发送邮件
- 【yoyo】计算2018年1月1日距当天事件还剩多少天,多少小时,多少分钟,多少秒;
- Android初级开发(十一)——(转载)一篇文章轻松掌握Material Design
- 【多校训练】hdu 6085 Rikka with Candies bitset
- CNN 模型压缩与加速算法综述
- CSS设计模式:转载最近看到的相关文章
- codeforces 822-B. Crossword solving(vector)
- maven profile配置
- nginx openresty异常处理小记
- Codeforces Round #430 (Div. 2)
- C++ operator关键字(重载操作符)
- 【C#】解决那些参数不同的方法无法注册委托的情况