zoukankan      html  css  js  c++  java
  • (第六场)Heritage of skywalkert 【玄学】

    题目链接:https://www.nowcoder.com/acm/contest/144/J

    标题:J、Heritage of skywalkert

    | 时间限制:1 秒 | 内存限制:256M

    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

    题意概括:

    按照给出的函数打出 N 个数, 求其中两个数的最小公倍数的最大值。

    官方题解:

    由于数据看上去像是随机⽣生成的,只需要选出前 100 大的数平方暴力即可。 随机两个正整数互质的概率为 6/(π^2) = 0.608...

    解题思路:

    nth_element()选出前100大的数,暴力前 100 大的数取最大的最小公倍数。

    AC code:

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <algorithm>
     4 #include <cmath>
     5 #define INF 0x3f3f3f3f
     6 #define ll unsigned long long
     7 using namespace std;
     8 
     9 const int MAXN = 1e7+10;
    10 
    11 ll num[MAXN];
    12 unsigned int N, A, B, C;
    13 unsigned int x, y, z;
    14 
    15 ll gcd(ll x, ll y)
    16 {
    17     return y==0?x:gcd(y, x%y);
    18 }
    19 
    20 bool cmp(ll x, ll y)
    21 {
    22     return x>y;
    23 }
    24 
    25 unsigned tang()
    26 {
    27     unsigned t;
    28     x ^= x<<16;
    29     x ^= x>>5;
    30     x ^= x<<1;
    31     t = x;
    32     x = y;
    33     y = z;
    34     z = t^x^y;
    35     return z;
    36 }
    37 
    38 int main()
    39 {
    40     int T_case;
    41     scanf("%d", &T_case);
    42     int cnt = 0;
    43     while(T_case--)
    44     {
    45 
    46         scanf("%u%u%u%u", &N, &A, &B, &C);
    47         x = A, y = B, z = C;
    48         for(int i = 0; i < N; i++)
    49         {
    50             num[i] = tang();
    51         }
    52         unsigned int k = min(100u, N);
    53         nth_element(num, num+k, num+N, cmp);
    54         ll res = 0;
    55         for(int i = 0; i < k; i++)
    56             for(int j = i+1; j < k; j++)
    57         {
    58             res = max(res, num[i]*num[j]/gcd(num[i],num[j]));
    59         }
    60         printf("Case #%d: %llu
    ", ++cnt, res);
    61     }
    62     return 0;
    63 }
    View Code
  • 相关阅读:
    《计算机图形学》学习笔记 0
    最全面的百度地图JavaScript离线版开发
    android 中文api
    SQL Compare数据库比较工具 完全破解+使用教程
    Android系统自带样式(android:theme)
    android studio 导入第三方库的记录
    web在线打印,打印阅览,打印维护,打印设计
    Oracle如何实现跨库查询
    WPF自适应窗体实现小结
    【转】WCF OpenTimeout, CloseTimeout, SendTimeout, ReceiveTimeout
  • 原文地址:https://www.cnblogs.com/ymzjj/p/9459382.html
Copyright © 2011-2022 走看看