zoukankan      html  css  js  c++  java
  • 2017ACM暑期多校联合训练

    题目链接

    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 10 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 has q 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 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(1≤t≤5), the number of the testcases.

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

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

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

    It is guaranteed that Ai≠Aj,Bi≠Bj for all i≠j.

    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

    题意:

    有N个人,每个人拥有Ai的钱,有M种物品,每个物品的单位价值是Bj,每种物品的数量都是无限的,我们现在有一个查询X,表示询问存在多少对购买方案对,使得Ai%Bj==X.
    输出方案数%2的结果。

    分析:

    我们开两个bitset,tmp里边存的是拥有i的钱的人是否存在,如果存在,该位为1,否则为0.ans里边存的是价格为i的物品是否存在,我们等比例放大物品的购买倍数即可。
    然后我们预处理答案暴力跑一下。

    代码:

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<bitset>
    using namespace std;
    int vis[50040];
    int output[50050];
    bitset<50050>tmp,ans,temp;
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            memset(vis,0,sizeof(vis));
            tmp.reset();//初始化,将所有的二进制定位0
            ans.reset();
            int n,m,qq,maxx=0;
            scanf("%d%d%d",&n,&m,&qq);
            int x;
            for(int i=1; i<=n; i++)
            {
                scanf("%d",&x);
                tmp.set(x);//将tmp中x处的二进制改为1
            }
            for(int i=1; i<=m; i++)
            {
                scanf("%d",&x);
                maxx=max(maxx,x);
                vis[x]=1;//标记单价
            }
            for(int i=maxx; i>=0; i--)
            {
                temp=ans&(tmp>>i);//tmp中的二进制向右移动i位
                output[i]=temp.count()%2;//计算temp中二进制为1的个数
                if(vis[i]==1)
                    for(int j=0; j<=maxx; j+=i)
                        ans.flip(j);//二进制取反
            }
            while(qq--)
            {
                scanf("%d",&x);
                printf("%d
    ",output[x]);
            }
        }
        return 0;
    }
    
  • 相关阅读:
    获取url中的参数
    css 实现单行以及多行文本溢出显示省略号
    页面跳转不带 referrer的方法
    iframe加载完成事件
    es6模块化规则(一)
    kindle电子书下载网站收藏
    vue多页面项目配置
    使用原生ajax及其简单封装
    在vue中使用jq或者第三方插件
    写博客常用语法
  • 原文地址:https://www.cnblogs.com/cmmdc/p/7326772.html
Copyright © 2011-2022 走看看