• 数据的随机性


    链接: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 ≤ 10
    7
    , 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 10
    6
    .

    输出描述:

    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 最大是多少?
    思路分析 :注意此题有个特点,就是A, B, C是随机产生的,这就代表了数据是有一定随机性质的,那么通常我们随机两个数是互质的概率是 6/(pi*pi) ,因此只要取个前 100 个最大的数,然后暴力去查一下即可。
      注意 : 就是当循环很大的时候,不要用 STL 中的函数,会超时!!!
    代码示例:
    #define ll unsigned long long
    
    ll n;
    unsigned x, y, z;
    priority_queue<unsigned int, vector<unsigned int>, greater<unsigned int> >que;
    unsigned arr[105];
    
    ll gcd(ll a, ll b){
        return b==0?a:gcd(b, a%b);
    }
    ll lcm(ll a, ll b){
        return a/gcd(a, b)*b;
    }
    
    int main() {
        //freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
        ll t;
        ll kas = 1;
        ll f1, f2;
        
        cin >> t;
        while(t--){
            scanf("%llu%u%u%u", &n, &x, &y, &z);
            while(!que.empty()) que.pop();
            
            for(ll i = 1; i <= n; i++){
                x ^= x<<16;
                x ^= x>>5;
                x ^= x<<1;
                unsigned f = x; x = y; y = z;
                z = f^x^y;
                
                if (que.size() < 100) que.push(z); 
                else {
                    unsigned num = que.top();
                    if (z > num) {
                        que.pop();
                        que.push(z);
                    }
                }
            }
            ll k = 1;
            while(!que.empty()) {
                arr[k++] = que.top(); que.pop();
            }
            ll ans = 0;
            for(ll i = 1; i < k; i++){
                for(int j = i+1; j < k; j++){
                    ll x = lcm((ll)arr[i], (ll)arr[j]);
                    if (ans < x) ans = x; 
                }
            }
            printf("Case #%llu: %llu
    ", kas++,ans);
        }
        return 0;
    }
    


    东北日出西边雨 道是无情却有情
  • 相关阅读:
    JAVA调优总结:JVM垃圾回收面临的问题解决方案
    用什么紧固件来固定一下我的程序人生呢
    Java设计模式动态代理研究分享
    深入理解Asp.net核心对象
    JAVA编程之动态更新JVM中的class文件
    探索J2ME应用:如何用GCF通信
    MySQL数据库备份的命令应用分享
    送给快要放弃的程序员同行们!
    减速机要像人一样智能减速就厉害了
    如何在Linux系统下进行C++程序开发
  • 原文地址:https://www.cnblogs.com/ccut-ry/p/9445990.html
Copyright © 2020-2023  润新知