牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)
链接:https://www.nowcoder.com/acm/contest/144/J
来源:牛客网
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 ≤ 10
7
, A, B, C are randomly selected in unsigned 32 bits integer range)
No more than 5 cases have n greater than 2 x 10
6
.
输出描述:
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.
输入例子:
2
2 1 2 3
5 3 4 8
输出例子:
Case #1: 68516050958
Case #2: 5751374352923604426
-->
输出
Case #1: 68516050958
Case #2: 5751374352923604426 分析:由于数据看上去像是随机⽣成的,只需要选出前 100 ⼤的数平⽅暴⼒即可。 随机两个正整数互质的概率为 6/π。
比赛的时候想到应该是枚举前面最大的多少项,但是因为不知道怎么快速计算前面多少项没有试一发了!!
结束后补题知道了nth_element求数组中最大的前多少项
AC代码:
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef unsigned long long ll;
const ll maxn = 1e7+10;
const ll mod = 998244353;
unsigned x, y, z, a[maxn];
ll n;
unsigned gcd( unsigned a, unsigned b ) {
if( a == 0 ) {
return b;
} else if( b == 0 ) {
return a;
} else {
return gcd( b, a%b );
}
}
unsigned rnd() {
unsigned t;
x ^= x << 16;
x ^= x >> 5;
x ^= x << 1;
t = x;
x = y;
y = z;
z = t ^ x ^ y;
return z;
}
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll T, t = 1;
scanf("%llu",&T);
while( T -- ) {
scanf("%llu%u%u%u",&n,&x,&y,&z);
for( ll i = 0; i < n; i ++ ) {
a[i] = rnd();
}
ll m = min( (ll)n, (ll)100 );
nth_element( a, a+n-m, a+n );
ll ans = 0;
for( ll i = n-m; i < n; i ++ ) {
for( ll j = i+1; j < n; j ++ ) {
ans = max( ans, (ll)a[i]*a[j]/gcd(a[i],a[j]) );
}
}
printf("Case #%llu: %llu\n", t++, ans);
}
return 0;
}
牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)的更多相关文章
- 牛客2018多校第六场 J Heritage of skywalkert - nth_element
传送门 题意:提供一个随机生成函数,让你生成n个数,然后问你其中能找到的两个数的最小公倍数 最大 是多少. 思路:可以用nth_element()函数在O(n)下求出前 15 个大的数(当然,100个 ...
- 2019 牛客多校第六场 J Upgrading Technology
题目链接:https://ac.nowcoder.com/acm/contest/886/J 题目大意 略. 分析 见代码. 代码如下 #include <bits/stdc++.h> u ...
- 牛客多校第六场 J Upgrading Technology dp
题意: 有n个技能,一开始都是0级,第i个技能从j-1级升到j级,花费$c_{i,j}$,但是花费不一定是正的 所有的技能升到j级时,奖励$d_j$但是奖励也不一定是正的 题解: 用sum[i][j] ...
- 牛客多校第3场 J 思维+树状数组+二分
牛客多校第3场 J 思维+树状数组+二分 传送门:https://ac.nowcoder.com/acm/contest/883/J 题意: 给你q个询问,和一个队列容量f 询问有两种操作: 0.访问 ...
- 牛客多校第五场 J:Plan
链接:https://www.nowcoder.com/acm/contest/143/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...
- 牛客多校第六场-H-Pair
链接:https://ac.nowcoder.com/acm/contest/887/H来源:牛客网 题目描述 Given three integers A, B, C. Count the numb ...
- 牛客多校第六场 C Generation I 组合数学 阶乘逆元模板
链接:https://www.nowcoder.com/acm/contest/144/C来源:牛客网 Oak is given N empty and non-repeatable sets whi ...
- 同构图+思维构造——牛客多校第六场E
考的其实是同构图的性质: 1.同构图的顶点数,边数相等 2.同构图通过点的映射后邻接矩阵相同 这篇博客讲的很好https://www.jianshu.com/p/c33b5d1b4cd9 本题还需要一 ...
- 牛客第六场 J.Heritage of skywalkert(On求前k大)
题目传送门:https://www.nowcoder.com/acm/contest/144/J 题意:给一个function,构造n个数,求出其中任意两个的lcm的最大值. 分析:要求最大的lcm, ...
随机推荐
- 为什么for循环可以遍历list:Python中迭代器与生成器
1 引言 只要你学了Python语言,就不会不知道for循环,也肯定用for循环来遍历一个列表(list),那为什么for循环可以遍历list,而不能遍历int类型对象呢?怎么让一个自定义的对象可遍历 ...
- PPT | Docker定义存储-让应用无痛运行
编者注: 本文为9月27日晚上8点有容云平台存储架构师张朝潞在腾讯课堂中演讲的PPT,本次课堂为有容云主办的线上直播Docker Live时代●Online Meetup-第三期:Docker定义存储 ...
- Letters Shop
B. Letters Shop time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- PIP键盘设置实时时钟--智能模块
大家好,许久没来发帖,今天带来点干货.希望大家多多讨论,相互学习. 使用 TOPWAY Smart LCD (HMT050CC-C) PIP键盘设置实时时钟 第一步 建立工程 第二步 建立2 ...
- 4、一个打了鸡血的for循环(增强型for循环)
对于循环,我们大家应该都不陌生,例如do-while循环,while循环,for循环,今天给大家介绍一个有趣的东西——打了鸡血的for循环(增强型for循环). 首先看代码,了解一下for循环的结构: ...
- java多线程基础(一)--sleep和wait的区别
sleep和wait的区别有: 1.这两个方法来自不同的类分别是Thread和Object: 2.最主要是sleep方法没有释放锁,而wait方法释放了锁,使得线程可以使用同步控制块或者方法: 3.w ...
- 使用CXF实现WebService
一.首先创建一个maven项目,引入相应的jar包 <?xml version="1.0" encoding="UTF-8"?> <proje ...
- 【POJ - 3259】Wormholes(最短路 Floyd算法)
Wormholes 题目描述 教学楼里有很多教室,这些教室由双向走廊连接.另外,还存在一些单向的秘密通道,通过它们可以回到过去.现在有 N (1 ≤ N ≤ 500) 个教室,编号 1..N, M ( ...
- 记一次mysql主从同步因断电产生的不能同步问题 1236 1032
背景: 项目新上线一个月,qa需要测试断电服务拉起,服务拉起成功后,发现mysql主从异常,以下是发现的问题以及解决方案 问题1: Slave_IO_Running: No 一方面原因是因为网络通信 ...
- Zookeeper_阅读源码第一步_在 IDE 里启动 zkServer(单机版)
Zookeeper是开源的,如果想多了解Zookeeper或看它的源码,最好是能找到它的源码并在 IDE 里启动,可以debug看它咋执行的,能够帮助你理解其原理. 准备源码 所以我们很容易搞到它的源 ...