题目链接:https://www.nowcoder.com/acm/contest/144/J
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

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

题意: 读题只读最后一句话系列。t组样例,t不超过50。每组样例四个数字n,a,b,c,n代表序列有n个数字,不超过5组样例n大于2e6,n<1e7。a,b,c在推出序列的过程中使用,数据范围unsigned int 按照题意中给出的代码,每运行一次得到的就是a[i],最后要求选出两个数字使其LCM最大,输出最大的LCM。做法:丧心病狂,不是第一次遇见这样的解法了,也就是保留前100大,然后暴力求LCM即可。注意*******  题目上说了a,b,c都是unsigned int类型的,不能开成unsigned long long类型的,不正常取舍答案会错误。nth_element(a,a+k,a+n,cmp);可以得到前k小或者前k大,自定义排序方式代码如下:
#include<stdio.h>
#include<iostream>
#include<algorithm>using namespace std;const int maxn = 10000007;int t;
int n;
unsigned int x , y , z;
unsigned long long num[maxn];unsigned long long gcd(unsigned long long a , unsigned long long b)
{unsigned long long c;c = a%b;while( c ){a = b;b = c;c = a%b;}return b;
}unsigned int solve()
{unsigned int tt;x ^= x<<16;x ^= x>>5;x ^= x<<1;tt = x;x = y;y = z;z = tt^x^y;return z;
}bool cmp(unsigned long long a , unsigned long long b)
{return a>b;
}int main()
{scanf("%d" , &t);for(int cas=1; cas<=t; cas++){scanf("%d%u%u%u" , &n , &x , &y , &z);for(int i=0; i<n; i++){num[i] = solve();}int k = min(100 , n);   ///取前100大nth_element(num , num+k , num+n , cmp);unsigned long long ans;ans = 0;for(int i=0; i<k; i++){
//            printf("%llu\n" , num[i]);for(int j=i+1; j<k; j++){ans = max(ans , num[i]*num[j]/gcd(num[i],num[j]));
//                 printf("%d..%d..%llu..%llu..%llu..%llu..\n" , i , j , num[i] , num[j] , num[i]*num[j]/gcd(num[i],num[j]) , ans);
            }}printf("Case #%d: %llu\n" , cas , ans);}return 0;
}/*
337929
608269
1351708
64488027082
85984357633405514
675854
1351708
1384776332
27694338580..1..405514..675854..137034129478..137034129478..
0..2..405514..1351708..274068258956..274068258956..
0..3..405514..1384776332..280773094747324..280773094747324..
0..4..405514..2769433858..561522100746506..561522100746506..
1..2..675854..1351708..1351708..561522100746506..
1..3..675854..1384776332..467953311543764..561522100746506..
1..4..675854..2769433858..935866475332366..935866475332366..
2..3..1351708..1384776332..467953311543764..935866475332366..
2..4..1351708..2769433858..1871732950664732..1871732950664732..
3..4..1384776332..2769433858..1917523229798924428..1917523229798924428..
*/


转载于:https://www.cnblogs.com/Flower-Z/p/9643476.html

牛客网暑期ACM多校训练营(第六场)J Heritage of skywalkert相关推荐

  1. 牛客网暑期ACM多校训练营(第二场)J farm (二维树状数组)

    题目链接: https://www.nowcoder.com/acm/contest/140/J 思路: 都写在代码注释里了,非常好懂.. for_each函数可以去看一下,遍历起vector数组比较 ...

  2. 牛客网暑期ACM多校训练营(第九场)

    牛客网暑期ACM多校训练营(第九场) A. Circulant Matrix 做法:看到下标 \(xor\) 这种情况就想 \(FWT\),可是半天没思路,于是放弃了..其实这个 \(n\) 疯狂暗示 ...

  3. 牛客网暑期ACM多校训练营(第一场)

    牛客网暑期ACM多校训练营(第一场) A. Monotonic Matrix 考虑0和1的分界线,1和2的分界线,发现问题可以转化为两条不互相穿过的路径的方案数(可重叠),题解的做法就是把一条路径斜着 ...

  4. 牛客网暑期ACM多校训练营(第二场): H. travel(树形线头DP)

    链接:https://ac.nowcoder.com/acm/contest/140/H 来源:牛客网 题目描述 White Cloud has a tree with n nodes.The roo ...

  5. 牛客网暑期ACM多校训练营(第三场): E. Sort String(KMP)

    链接:https://www.nowcoder.com/acm/contest/141/E 来源:牛客网 题目描述 Eddy likes to play with string which is a ...

  6. 牛客网暑期ACM多校训练营(第三场): C. Shuffle Cards(splay)

    链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网 题目描述 Eddy likes to play cards game since there ...

  7. 牛客网暑期ACM多校训练营(第二场)A .run

    链接:https://www.nowcoder.com/acm/contest/140/A 来源:牛客网 题目描述 White Cloud is exercising in the playgroun ...

  8. 牛客网暑期ACM多校训练营(第一场) J (莫队算法)

    题目链接:https://www.nowcoder.com/acm/contest/139/J 题目大意:给一个序列,进行q次查询,问1~l和r~n中有多少个不同的数字 题目思路:之前只是听说过莫队算 ...

  9. 牛客网 暑期ACM多校训练营(第一场)J.Different Integers-区间两侧不同数字的个数-离线树状数组 or 可持久化线段树(主席树)...

    J.Different Integers 题意就是给你l,r,问你在区间两侧的[1,l]和[r,n]中,不同数的个数. 两种思路: 1.将数组长度扩大两倍,for(int i=n+1;i<=2* ...

  10. 牛客网暑期ACM多校训练营(第二场)D-money (dp)

    题目链接 题意 一共有n件商店,每个商店买卖东西的价格和不同,白兔想用差价挣钱,每次只能携带一种物品,问白兔最多赚多少的钱,和对应的交易次数 AC 两个变量分别记录当前买东西和买东西的剩余财富,财富越 ...

最新文章

  1. MIT自然语言处理第一讲:简介和概述(第三部分)
  2. css过渡transition
  3. Docker实战 (docker swarm的应用,docker集群的构建,在docker集群中部署服务)
  4. 思科交换机的初始配置(使用telnet登录)
  5. 题目1452:搬寝室(dp题目)
  6. Intellij IDEA 配置
  7. 【自动驾驶】一文读懂自动驾驶汽车产业链上下游|湾区人工智能
  8. python数据结构与算法篇:排序
  9. split和join和pop和remove用法
  10. java-web乱码问题解决
  11. ASP.NET中?和??的用法
  12. Cloud Native Infrastructures Meetup 精彩回顾(内含 PPT 下载)
  13. 截止失真放大电路_一起学模电:6、放大电路静态与动态分析方法
  14. php 模拟蜘蛛,php 实现使用curl模拟百度蜘蛛进行采集
  15. 【读书笔记】巴比伦富翁的理财课
  16. 导入tkinter出错
  17. 文案撰写技巧,感人文案的4大技巧
  18. 浙大OJ网址及ACM题目分类
  19. ssm毕设项目基于框架的众筹管理系统f5244(java+VUE+Mybatis+Maven+Mysql+sprnig)
  20. Go语言段子爬虫--捧腹网

热门文章

  1. 坐标和变换的数学基础(2)
  2. centos7双网卡绑定bond0
  3. 基于redis的cas集群配置(转)
  4. J2EE详细入门教程--人员登入
  5. 微软 microsoft calendar control 11.0 控件下载
  6. CentOS6.8 x86_64bit MySQL简单语句应用
  7. python常见的特异点
  8. java --级联操作(查询/更新)
  9. openstack中RemoteError: AgentNotFoundByTypeHost解决
  10. uva 1416 (SPFA) **月赛第E题的原题**