牛客网多校第6场J题 随机化暴力

牛客网多校第6场J题        链接:https://www.nowcoder.com/acm/contest/144/J

skywalkert, the new legend of Beihang University ACM-ICPC Team, retired this year leaving a group of newbies again.
 

Rumor has it that he left a heritage when he left, and only the one who has at least 0.1% IQ(Intelligence Quotient) of his can obtain it.


To prove you have at least 0.1% IQ of skywalkert, you have to solve the following problem:

Given n positive integers, for all (i, j) where 1 ≤ i, j ≤ n and i ≠ j, output the maximum value among . means the Lowest Common Multiple.

输入描述:

The input starts with one line containing exactly one integer t which is the number of test cases. (1 ≤ t ≤ 50)

For each test case, the first line contains four integers n, A, B, C. (2 ≤ n ≤ 107, A, B, C are randomly selected in unsigned 32 bits integer range)

The n integers are obtained by calling the following function n times, the i-th result of which is ai, and we ensure all ai > 0. Please notice that for each test case x, y and z should be reset before being called.

No more than 5 cases have n greater than 2 x 106.

输出描述:

For each test case, output "Case #x: y" in one line (without quotes), where x is the test case number (starting from 1) and y is the maximum lcm.

示例1

输入

2
2 1 2 3
5 3 4 8

输出

Case #1: 68516050958
Case #2: 5751374352923604426

这是我接触的第一题随机化算法,比赛的时候有点懵,队友把表打出来发现所有烫^_^后得到的值都不一样。。。

然后直接选了最大的那两个算lcm,然后只过了样例。后来学长说这题随机化,只需要取前100个最大的烫,暴力算lcm就可以得到答案了。

用到一个数学知识点:两个正整数互质的概率为  \tfrac{6}{\pi^{2}}  .

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e7+5;
unsigned x,y,z;
int n;
unsigned long long gcd(unsigned a,unsigned b)
{
    while(b)
    {
        int c=a%b;
        a=b;
        b=c;
    }
    return a;
}
unsigned tang()
{
    unsigned t;
    x ^= x << 16;
    x ^= x >> 5;
    x ^= x << 1;
    t = x;
    x = y;
    y = z;
    z = t ^ x ^ y;
    return z;
}
unsigned a[maxn];

int main()
{
    int t;
    cin>>t;
    int cnt=1;
    while(t--)
    {
        scanf("%d%u%u%u",&n,&x,&y,&z);
        for(int i=0;i<n;++i)
            a[i]=tang();
        int m=min(100,n);
        nth_element(a,a+n-m,a+n);//找出前100个大的
        unsigned long long ans=0;
        for(int i=n-m;i<n;++i)
            for(int j=i+1;j<n;++j)
        {
            ans=max(ans,1ull*a[i]*a[j]/gcd(a[i],a[j]));
        }
        printf("Case #%d: %llu\n",cnt++,ans);
    }
}

 

MATLAB主动噪声和振动控制算法——对较大的次级路径变化具有鲁棒性内容概要:本文主要介绍了一种在MATLAB环境下实现的主动噪声和振动控制算法,该算法针对较大的次级路径变化具有较强的鲁棒性。文中详细阐述了算法的设计原理与实现方法,重点解决了传统控制系统中因次级路径动态变化导致性能下降的问。通过引入自适应机制和鲁棒控制策略,提升了系统在复杂环境下的稳定性和控制精度,适用于需要高精度噪声与振动抑制的实际工程景。此外,文档还列举了个MATLAB仿真实例及相关科研技术服务内容,涵盖信号处理、智能优化、机器学习等个交叉领域。; 适合人群:具备一定MATLAB编程基础和控制系统理论知识的科研人员及工程技术人员,尤其适合从事噪声与振动控制、信号处理、自动化等相关领域的研究生和工程师。; 使用景及目标:①应用于汽车、航空航天、精密仪器等对噪声和振动敏感的工业领域;②用于提升现有主动控制系统对参数变化的适应能力;③为相关科研项目提供算法验证与仿真平台支持; 阅读建议:建议读者结合提供的MATLAB代码进行仿真实验,深入理解算法在不同次级路径条件下的响应特性,并可通过调整控制参数进一步探究其鲁棒性边界。同时可参考文档中列出的相关技术案例拓展应用景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值