zoukankan      html  css  js  c++  java
  • HDU 6085 bitset

    Rikka with Candies

    Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 1452    Accepted Submission(s): 634


    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 10dollars 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)(1in,1jm) 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(1t5), the number of the testcases. 

    For each testcase, the first line contains three numbers n,m,q(1n,m,q50000)

    The second line contains n numbers Ai(1Ai50000) and the third line contains m numbers Bi(1Bi50000).

    Then the fourth line contains q numbers ki(0ki<maxBi) , which describes the queries.

    It is guaranteed that AiAj,BiBj for all ij.
     
    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
     
    Source
     
     1 #pragma comment(linker, "/STACK:1024000000,1024000000")
     2 #include<iostream>
     3 #include<cstdio>
     4 #include<cmath>
     5 #include<string>
     6 #include<queue>
     7 #include<algorithm>
     8 #include<stack>
     9 #include<cstring>
    10 #include<vector>
    11 #include<list>
    12 #include<set>
    13 #include<map>
    14 #include<bitset>
    15 #include<time.h>
    16 using namespace std;
    17 int t;
    18 int n,m,q;
    19 bitset<50004> a,b,ans,exm;
    20 int main(){
    21     scanf("%d",&t);
    22     for(int i=1;i<=t;i++){
    23         scanf("%d %d %d",&n,&m,&q);
    24         a.reset();
    25         b.reset();
    26         int maxn=0;
    27         int x;
    28         for(int j=0; j<n;j++){
    29           scanf("%d",&x);
    30           a.set(x);
    31         }
    32         for(int j=0;j<m;j++){
    33             scanf("%d",&x);
    34             b.set(x);
    35             maxn=max(maxn,x);
    36         }
    37         exm.reset();
    38         ans.reset();
    39         for(int j=maxn;j>=0;j--){
    40             ans[j]=(exm&(a>>j)).count()&1;//ans[j]:(a-j)%b==0的个数的奇偶性
    41             if(b[j]){
    42                 for(int k=0;k<=50000;k+=j)
    43                  exm.flip(k);
    44             }
    45         }
    46         for(int j=1;j<=q;j++){
    47             scanf("%d",&x);
    48             printf("%c
    ",ans[x]?'1':'0');
    49         }
    50     }
    51     return 0;
    52 }
     
  • 相关阅读:
    更新我电脑的编译器之Java语言
    HTML/CSS基础
    查找元素的杀手锏xpath
    错误日志的实时抓取保证代码质量
    Splinter常用api
    从底层向上理解Git
    infer运用实践
    流程图在测试用例编写中的运用
    2016小结
    Splinter 查找元素
  • 原文地址:https://www.cnblogs.com/hsd-/p/7347353.html
Copyright © 2011-2022 走看看