• 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 }
     
  • 相关阅读:
    chrony时间同步工具
    SyntaxError: missing ; before statement
    SQL 获得两个时间段之间的数据
    EasyUI DataGrid 获得分页信息
    c#里如何实现讲一个字符串数组例如 “112,221”转化成两个字符串数组“112” “221” 中间以逗号隔开
    SQL 将一个表中的所有记录插入到一个临时表中
    SQL查找指定行的记录
    SQL 中的Begin...End语句
    SQL将完整时间字段截取到年月日
    Linux学习之三:档案与文件系统的压缩与打包
  • 原文地址:https://www.cnblogs.com/hsd-/p/7347353.html
Copyright © 2020-2023  润新知