hdu 6085 Rikka with Candies(bitset 计数原理)
来源:互联网 发布:js去隐藏域传值 编辑:程序博客网 时间:2024/06/07 18:00
Rikka with Candies
Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1237 Accepted Submission(s): 542
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
http://blog.csdn.net/luricheng/article/details/77006185
解:求出B数组中最大的数x作为开始枚举的答案,因为不可能出现超过x的答案,从大到小遍历,(a-i)%b=0,求出bx数组中有多少是b的倍数,就能算出有多少(a-i),
即答案为i的数量
#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<cmath>#include<string>#include <bits/stdc++.h>using namespace std;const int N =50000+5;bitset<N>a,b,ans,bx;void solve(int x){ bx.reset(); for(int i=x;i>=0;i--) { ans[i]=((a>>i)&bx).count()&1; if(!b[i]) continue; for(int j=0;j<N;j+=i) bx.flip(j); } return ;}int main(){ int t; scanf("%d", &t); while(t--) { a.reset(),b.reset(); int n, m, q, x, maxt=0; scanf("%d %d %d", &n, &m, &q); for(int i=0;i<n;i++) { scanf("%d", &x); a.set(x); } for(int i=0;i<m;i++) { scanf("%d", &x); b.set(x); maxt=max(x,maxt); } ans.reset(); solve(maxt); while(q--) { scanf("%d", &x); if(ans[x])puts("1"); else puts("0"); } } return 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)
- HDU 6085 Rikka with Candies (bitset)
- Rikka with Candies(HDU6085) (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
- HDU 6085 Rikka with Candies
- HDU 6085 Rikka with Candies
- hdu 6085 Rikka with Candies
- Rikka with Candies(bitset操作)
- IOS 关于设置同样的字号,显示大小不一致
- Java泛型详解
- 在SQL Server中实现 Limit m, n 的功能
- 基于STM32+机智云物联网自助开发平台打造的环境智能监测系统
- 位运算详解
- hdu 6085 Rikka with Candies(bitset 计数原理)
- 一.想过如何对网站优化:模块化方向
- 面试常见问题——操作系统
- Mysql性能优化案例
- spring Cloud 初次使用容易忽略环节
- mybatis-generator 代码自动生成工具
- linux下创造一个假终端,同终端操作实现相同功能
- SQL删除重复数据项只保留一项
- Mybatis实现事务的方式和缓存