Hdu6085 Rikka with Candies(2017多校第5场)

RikkawithCandies数学问题解析
本文介绍了一个名为RikkawithCandies的编程竞赛问题,该问题涉及数学逻辑和优化技巧,特别是利用bitset进行高效计算。文章详细解释了如何通过打表法和优化策略解决这个问题。

Rikka with Candies

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


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  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 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)(1in,1jm)  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 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
————————————————————————————————————

​ 题目的意思是存在两个长度分别为  n,m  的数组  A,B  。有  q  个询问,每个询问给出一个数字  k  ,可以得到使得  AimodBj=k  的种数。求该种数的奇偶性。

思路:打表出所有查询k,k<Bi,从最大的Bi开始枚举。如果a%b==k,那么(a-k)%b==0

所以我们考虑用bitset优化这个过程


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>

using namespace std;

#define LL long long
const int INF = 0x3f3f3f3f;
#define mod 10000007
#define mem(a,b) memset(a,b,sizeof a)

bitset<50005>bt,bi;

int b[50005],ans[500005];
int main()
{
    int a,T,m,n,k;;
    for(scanf("%d",&T); T--;)
    {
        bi.reset();
        bt.reset();
        scanf("%d%d%d",&n,&m,&k);
        for(int i=0; i<n; i++)
            scanf("%d",&a),bt.set(a);
        int mx=-1;
        for(int i=0; i<m; i++)
            scanf("%d",&b[i]),mx=max(mx,b[i]);
        sort(b,b+m);
        int cnt=m-1;
        for(int i=mx; i>=0; i--)
        {
            ans[i]=((bi<<i)&bt).count()&1;
            if(b[cnt]>=i&&cnt>=0)
            {
                for(int j=0; j<=mx; j+=b[cnt])
                    bi.flip(j);
                    cnt--;
            }
        }
        for(int i=0; i<k; i++)
        {
            scanf("%d",&a);
            printf("%d\n",ans[a]);
        }

    }
    return 0;
}


【无人机】基于改进粒子群算法的无人机路径规划研究[和遗传算法、粒子群算法进行比较](Matlab代码实现)内容概要:本文围绕基于改进粒子群算法的无人机路径规划展开研究,重点探讨了在复杂环境中利用改进粒子群算法(PSO)实现无人机三维路径规划的方法,并将其与遗传算法(GA)、标准粒子群算法等传统优化算法进行对比分析。研究内容涵盖路径规划的目标优化、避障策略、航路点约束以及算法收敛性和寻优能力的评估,所有实验均通过Matlab代码实现,提供了完整的仿真验证流程。文章还提到了种智能优化算法在无人机路径规划中的应用比较,突出了改进PSO在收敛速度和全局寻优方面的优势。; 适合人群:具备一定Matlab编程基础和优化算法知识的研究生、科研人员及从事无人机路径规划、智能优化算法研究的相关技术人员。; 使用景及目标:①用于无人机在复杂地形或动态环境下的三维路径规划仿真研究;②比较不同智能优化算法(如PSO、GA、蚁群算法、RRT等)在路径规划中的性能差异;③为目标优化问题提供算法选型和改进思路。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注算法的参数设置、适应度函数设计及路径约束处理方式,同时可参考文中提到的种算法对比思路,拓展到其他智能优化算法的研究与改进中。
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值