(第六场)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:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#define INF 0x3f3f3f3f
#define ll unsigned long long
using namespace std; const int MAXN = 1e7+; ll num[MAXN];
unsigned int N, A, B, C;
unsigned int x, y, z; ll gcd(ll x, ll y)
{
return y==?x:gcd(y, x%y);
} bool cmp(ll x, ll y)
{
return x>y;
} unsigned tang()
{
unsigned t;
x ^= x<<;
x ^= x>>;
x ^= x<<;
t = x;
x = y;
y = z;
z = t^x^y;
return z;
} int main()
{
int T_case;
scanf("%d", &T_case);
int cnt = ;
while(T_case--)
{ scanf("%u%u%u%u", &N, &A, &B, &C);
x = A, y = B, z = C;
for(int i = ; i < N; i++)
{
num[i] = tang();
}
unsigned int k = min(100u, N);
nth_element(num, num+k, num+N, cmp);
ll res = ;
for(int i = ; i < k; i++)
for(int j = i+; j < k; j++)
{
res = max(res, num[i]*num[j]/gcd(num[i],num[j]));
}
printf("Case #%d: %llu\n", ++cnt, res);
}
return ;
}
(第六场)Heritage of skywalkert 【玄学】的更多相关文章
- 山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard
山东省ACM多校联盟省赛个人训练第六场 D Rotating Scoreboard https://vjudge.net/problem/POJ-3335 时间限制:C/C++ 1秒,其他语言2秒 空 ...
- noi.ac 第五场第六场
t1应该比较水所以我都没看 感觉从思路上来说都不难(比牛客网这可简单多了吧) 第五场 t2: 比较套路的dp f[i]表示考虑前i个数,第i个满足f[i]=i的最大个数 i能从j转移需要满足 j< ...
- NOI.AC NOIP模拟赛 第六场 游记
NOI.AC NOIP模拟赛 第六场 游记 queen 题目大意: 在一个\(n\times n(n\le10^5)\)的棋盘上,放有\(m(m\le10^5)\)个皇后,其中每一个皇后都可以向上.下 ...
- Heritage of skywalkert
Heritage of skywalkert skywalkert, the new legend of Beihang University ACM-ICPC Team, retired this ...
- 牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)
链接:https://www.nowcoder.com/acm/contest/144/J来源:牛客网 skywalkert, the new legend of Beihang University ...
- 牛客第六场 J.Heritage of skywalkert(On求前k大)
题目传送门:https://www.nowcoder.com/acm/contest/144/J 题意:给一个function,构造n个数,求出其中任意两个的lcm的最大值. 分析:要求最大的lcm, ...
- 牛客网暑期ACM多校训练营(第六场) J Heritage of skywalkert(数论, eth_element)
链接: https://www.nowcoder.com/acm/contest/144/J 题意: 给定一个函数, 求它n次结果中任意两次的lcm最大值 分析: 首先要看出这个函数并没有什么含义, ...
- 牛客2018多校第六场 J Heritage of skywalkert - nth_element
传送门 题意:提供一个随机生成函数,让你生成n个数,然后问你其中能找到的两个数的最小公倍数 最大 是多少. 思路:可以用nth_element()函数在O(n)下求出前 15 个大的数(当然,100个 ...
- 2016多校第六场题解(hdu5793&hdu5794&hdu5795&hdu5800&hdu5802)
这场就做出一道题,怎么会有窝这么辣鸡的人呢? 1001 A Boring Question(hdu 5793) 很复杂的公式,打表找的规律,最后是m^0+m^1+...+m^n,题解直接是(m^(n+ ...
随机推荐
- 使用Verilog描述RTL图
题目要求 分别用两种方式表达此电路: 1)在一个模块中用两个过程来表达: 2)用顶层文件和例化语句的形式来表达. 给出下面RTL图的verilog描述. 1)纯过程语句描述 2)纯连续赋值语句描述 参 ...
- dockerfile 语法
基本语法格式:INSTRUCTION arguments (指令+参数)不分大小写 注释格式:# 注释 第一个指令必须是FROM,标示使用什么镜像 1.解析器指令 解析器指令是可选的,并且影响处理Do ...
- Java基础25-静态代码块
/* 静态代码块 格式: static{ 静态代码块中执行语句 } 特点:随着类的加载而执行,并且只会执行一次,并且还优先于主函数. 作用:用于给类进行初始化 */ public class Test ...
- Eclipse/Myeclipse/Scala IDEA for Eclipse里两种添加插件的方法(在线和离线)
不多说,直接上干货! 方法1:在线安装 第一步,在eclipse菜单栏下,选中help ---->Install New Software 第二步,点击图中 add 添加软件下载地址 第三步 , ...
- STM32Cubemx出现工程突然自动退出的问题
STM32Cubemx出现工程突然自动退出的问题 转载请注明出处,谢谢 https://www.cnblogs.com/kevin-nancy/p/10561944.html 或者 https://b ...
- Markdown简易使用
Markdown 笔记 标题 1.一级标题 2.二级标题 3.三级标题 列表 这是 一个 无序列表 这是 一个 有序列表 引用 这是一条引用 图片与链接 图片 链接 Baidu 粗体与斜体 粗体 斜体 ...
- 如何给MySql创建连接用户并授权
一般在为MySql创建用户时建议使用GRANT前台命令,当然如果对我们开发者而言,方法还有很多种,比如使用INSERT命令,甚至是直接修改mysql user数据表,但仍然建议按照MySQL规范去授权 ...
- Coursera 机器学习 第5章 Neural Networks: Learning 学习笔记
5.1节 Cost Function神经网络的代价函数. 上图回顾神经网络中的一些概念: L 神经网络的总层数. sl 第l层的单元数量(不包括偏差单元). 2类分类问题:二元分类和多元分类. 上 ...
- 坐标深圳 | Kubernetes!我要用这样的姿势拥抱你
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 从去年至今,容器.Kubernetes话题的热度就持续不减,有人说基于容器 +Kubernetes 的新型 PaaS 将会成为云计算的主流: ...
- nyoj 999——师傅又被妖怪抓走了——————【双广搜】
师傅又被妖怪抓走了 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 话说唐僧复得了孙行者,师徒们一心同体,共诣西方.自宝象国救了公主,承君臣送出城西,沿路饥餐渴饮,悟 ...