牛客多校第六场 J Heritage of skywalkert 简单题

 

题意   :每次运行上述的函数可获得一个数,让你从运行n次函数后得到的n个数中   求随便两个数的lcm  输出其中的最大值

思路:这个数看起来像是随便生成的  那么我们就取其中前100个最大的数 暴力求出最大lcm即可。   愚蠢的我不知道unsigned 如果超出范围不会变负数  无符号数超出位数的部分就不要   好吧 我第一次用 unsigned  根本不知道啥玩意。    前100个最大的数不能用multiset 存全部n个数 再一个个找 不然会tle  。

 可以先全放一个数组里 然后用 nth_element函数  (天啊 我又是第一次用这个玩意,用法是 nth_element(num,num+len,num+n)  填入的三个分别是 数组的开头,   第len大,数组结尾    最后数组会变乘 第len大 在 num+len位置上  之前的都比它小,之后的都比它大)  处理过之后只要 从len~n里暴力即可   头文件是stdio.h

代码:

#include<math.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
#include<string>
#include<iostream>
#include<set>
using namespace std;
typedef unsigned long long ll;

unsigned x,y,z,t;
 
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 num[10000005];
int main()
{
    int t;
    scanf("%d",&t);
    for(int cas=1;cas<=t;cas++){
        int n,len;
        unsigned a,b,c;
        scanf("%d%u%u%u",&n,&a,&b,&c);
        x=a;
        y=b;
        z=c;
        for(int i=0;i<n;i++){
            num[i]=tang();
        }
 
        len=max(0,n-100);
        nth_element(num,num+len,num+n);
 
        ll ans=0;
        for(int i=len;i<n;i++){
            for(int j=i+1;j<n;j++){
                ans=max(ans,(ll)num[i]/__gcd(num[i],num[j])*num[j]);
            }
        }
        printf("Case #%d: %llu\n",cas,ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/lkaicheng/article/details/81415047
今日推荐