首页 > 其他 > 详细

<牛客多校round 6>

时间:2018-08-07 00:18:22      阅读:145      评论:0      收藏:0      [点我收藏+]

Solved:3

rank:156

 

J. Heritage of skywalker

学习一下nth_element 可以o (n)的找出前多少大的元素

技术分享图片
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

int n;
unsigned x, y, z;

unsigned int tang()
{
    unsigned int t;
    x ^= x << 16;
    x ^= x >> 5;
    x ^= x << 1;
    t = x;
    x = y;
    y = z;
    z = t ^ x ^ y;
    return z;
}

ull gcd(ull x, ull y)
{
    if(y == 0) return x;
    return gcd(y, x % y);
}

ull q[10000005];

int main()
{
    int T;
    scanf("%d", &T);
    int cas = 0;
    while(T--)
    {
        cas++;
        cin>>n>>x>>y>>z;
        for(int i = 0; i < n; i++) q[i] = tang();
        
        int len = min(100, n);
        nth_element(q, q + len, q + n, greater<ull>());
        ull ans = 0;
        for(int i = 0; i < len; i++)
        {
            for(int j = i + 1; j < len; j++)
            {
                ull tmp = gcd(q[i], q[j]);
                ans = max(ans, q[i] / tmp * q[j]);
            }
        }
        printf("Case #%d: %llu\n", cas, ans);
    }
    return 0;
} 
View Code

 

<牛客多校round 6>

原文:https://www.cnblogs.com/lwqq3/p/9434239.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!