hdu 6085(bitset)

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 nn children and mm kinds of candies. The iith child has AiAi dollars and the unit price of the iith kind of candy is BiBi. 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 1010 dollars and the unit price of his favorite candy is 44 dollars, then he will buy two candies and go home with 22 dollars left.

Now Yuta has qq queries, each of them gives a number kk. For each query, Yuta wants to know the number of the pairs (i,j)(1≤i≤n,1≤j≤m)(i,j)(1≤i≤n,1≤j≤m) which satisfies if the iith child’s favorite candy is the jjth kind, he will take kk dollars home.

To reduce the difficulty, Rikka just need to calculate the answer modulo 22.

But It is still too difficult for Rikka. Can you help her?
Input
The first line contains a number t(1≤t≤5)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)n,m,q(1≤n,m,q≤50000).

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

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

It is guaranteed that Ai≠Aj,Bi≠BjAi≠Aj,Bi≠Bj for all i≠ji≠j.
Output
For each query, print a single line with a single 0101 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

就是给你A集合 n个数,B集合 m个数 q个询问
问有多少对 (i,j) 使得a[i]%b[j]==k
转化得 a[i]-k=tb[j].

因为集合数量已经到达 5e4,所以暴力是不行的,利用bitset 对一个集合进行某项操作 例如 -k

从大到小枚举最大的k,因为k一定不能比b集合里面最大的数大,所以从最大的数开始 从大到小枚举,然后更新,如果有i存在,那么相当于 在0~N中 存在着 i,2i,3i这样的模数,更新就好,由于小于等于当前k的数对k是没有贡献的,所以从大到小一直更新就好,由于只要求奇偶,所以&1 就好

#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]=(bx&(a>>i)).count()&1;
        if(b[i])
        {
            for(int j=0;j<N;j+=i)
                bx.flip(j);
        }
    }
}

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=1;i<=n;i++)
        {
            scanf("%d",&x);
            a.set(x);
        }
        for(int i=1;i<=m;i++)
        {
            scanf("%d",&x);
            b.set(x);
            maxt=max(x,maxt);
        }
        ans.reset();
        solve(maxt);
        while(q--)
        {
            int x;
            scanf("%d",&x);
            puts(ans[x]?"1":"0");
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在信号处理领域,DOA(Direction of Arrival)估计是一项关键技术,主要用于确定多个信号源到达接收阵列的方向。本文将详细探讨三种ESPRIT(Estimation of Signal Parameters via Rotational Invariance Techniques)算法在DOA估计中的实现,以及它们在MATLAB环境中的具体应用。 ESPRIT算法是由Paul Kailath等人于1986年提出的,其核心思想是利用阵列数据的旋转不变性来估计信号源的角度。这种算法相比传统的 MUSIC(Multiple Signal Classification)算法具有较低的计算复杂度,且无需进行特征值分解,因此在实际应用中颇具优势。 1. 普通ESPRIT算法 普通ESPRIT算法分为两个主要步骤:构造等效旋转不变系统和估计角度。通过空间平移(如延时)构建两个子阵列,使得它们之间的关系具有旋转不变性。然后,通过对子阵列数据进行最小二乘拟合,可以得到信号源的角频率估计,进一步转换为DOA估计。 2. 常规ESPRIT算法实现 在描述中提到的`common_esprit_method1.m`和`common_esprit_method2.m`是两种不同的普通ESPRIT算法实现。它们可能在实现细节上略有差异,比如选择子阵列的方式、参数估计的策略等。MATLAB代码通常会包含预处理步骤(如数据归一化)、子阵列构造、旋转不变性矩阵的建立、最小二乘估计等部分。通过运行这两个文件,可以比较它们在估计精度和计算效率上的异同。 3. TLS_ESPRIT算法 TLS(Total Least Squares)ESPRIT是对普通ESPRIT的优化,它考虑了数据噪声的影响,提高了估计的稳健性。在TLS_ESPRIT算法中,不假设数据噪声是高斯白噪声,而是采用总最小二乘准则来拟合数据。这使得算法在噪声环境下表现更优。`TLS_esprit.m`文件应该包含了TLS_ESPRIT算法的完整实现,包括TLS估计的步骤和旋转不变性矩阵的改进处理。 在实际应用中,选择合适的ESPRIT变体取决于系统条件,例如噪声水平、信号质量以及计算资源。通过MATLAB实现,研究者和工程师可以方便地比较不同算法的效果,并根据需要进行调整和优化。同时,这些代码也为教学和学习DOA估计提供了一个直观的平台,有助于深入理解ESPRIT算法的工作原理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值