2017多校训练Contest5: 1001 Rikka with Candies hdu6085
来源:互联网 发布:广通软件怎么样 编辑:程序博客网 时间:2024/06/13 17:28
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压进一个bitset x1
从大到小枚举k,每次把大于k的b的所有倍数压入bitset x2里
然后直接(x1>>k)&x2求出当前k的答案
手写会好一点,用系统的bitset需要卡一下常数
#include<map>#include<cmath>#include<queue>#include<bitset>#include<vector>#include<cstdio>#include<string>#include<cstring>#include<cassert>#include<iostream>#include<algorithm>using namespace std;inline int read(){ int x=0;char ch=getchar(); while(ch<'0'||ch>'9'){ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x;}inline bool cmp(int x,int y){ return x>y;}bitset<50051> x1,x2;int a[50051],b[50051];int ans[50051];int main(){ int T; //scanf("%d",&T); T=read(); while(T>0) { T--; int n,m,q; //scanf("%d%d%d",&n,&m,&q); n=read(); m=read(); q=read(); int i,j; int maxx=0; for(i=1;i<=n;i++) { //scanf("%d",&a[i]); a[i]=read(); maxx=max(maxx,a[i]); } for(i=1;i<=m;i++) { //scanf("%d",&b[i]); b[i]=read(); maxx=max(maxx,b[i]); } sort(b+1,b+1+m,cmp); x1.reset(); x2.reset(); for(i=1;i<=n;i++) //x1[a[i]]=1; x1.flip(a[i]); int d=1; b[0]=0; memset(ans,0,sizeof(ans)); for(i=maxx;i>=0;i--) { while(d<=m&&b[d]>i) { for(j=0;j<=maxx;j+=b[d]) //x2[j]=(x2[j]^1); x2.flip(j); d++; //x2.flip(0); } //x3=((x1>>i)&x2); ans[i]=((x1>>i)&x2).count(); } int x; for(i=1;i<=q;i++) { //scanf("%d",&x); x=read(); if(ans[x]&1) puts("1"); else puts("0"); //printf("%d\n",ans[x]%2); } } return 0;}
阅读全文
0 0
- 2017多校训练Contest5: 1001 Rikka with Candies hdu6085
- 2017多校训练Contest5: 1006 Rikka with Graph hdu6090
- 2017多校训练Contest5: 1008 Rikka with Subset hdu6092
- hdu6085 Rikka with Candies
- HDU6085-Rikka with Candies
- HDU-2017 多校训练赛5-1001-Rikka with Candies
- 【2017多校】HDU6085 Rikka with Candies
- 【多校训练】hdu 6085 Rikka with Candies bitset
- Hdu6085 Rikka with Candies(2017多校第5场)
- hdu6085 Rikka with Candies [bitset+想法]
- Rikka with Candies(HDU6085) (bitset加速计数)
- 2016多校训练Contest5: 1001 ATM Mechine hdu5781
- 2016多校训练Contest8: 1008 Rikka with Sequence hdu5828
- 【多校训练】hdu 6090 Rikka with Graph
- 【多校训练】 hdu 6092 Rikka with Subset
- HDU-2017 多校训练赛5-1006-Rikka with Graph
- HDU-2017 多校训练赛5-1008-Rikka with Subset
- 2017 多校训练第五场 HDU 6092 Rikka with Subset
- 柱状图js封装插件
- Hadoop+Spark学习
- 算法的复杂度
- 设计模式-工厂方法模式
- 【POJ3041】Asteroids(二分图)
- 2017多校训练Contest5: 1001 Rikka with Candies hdu6085
- Vue键盘事件
- 动态规划专题之石子合并
- [NOIP2012]同余方程
- null强制转任何类型的对象
- Android学习心得(三)关于真机调试后,签名的apk无法安装的问题
- WPF入门基础
- 基于commons-fileupload-1.2.jar的纯jsp文件上传
- easyui Tabs中的链接/按钮点击后添加一个新TAB的解决方法