博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)...
阅读量:7170 次
发布时间:2019-06-29

本文共 2622 字,大约阅读时间需要 8 分钟。

链接:

来源:牛客网

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 ≤ 10

7

, 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 a
i, and we ensure all a
i > 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 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.

示例1

输入

22 1 2 35 3 4 8

输出

Case #1: 68516050958Case #2: 5751374352923604426 分析:由于数据看上去像是随机⽣成的,只需要选出前 100 ⼤的数平⽅暴⼒即可。 随机两个正整数互质的概率为 6/π。 比赛的时候想到应该是枚举前面最大的多少项,但是因为不知道怎么快速计算前面多少项没有试一发了!! 结束后补题知道了nth_element求数组中最大的前多少项 AC代码:
#include #include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ls (r<<1)#define rs (r<<1|1)#define debug(a) cout << #a << " " << a << endlusing 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;}

  

转载于:https://www.cnblogs.com/l609929321/p/9426160.html

你可能感兴趣的文章
Office 2019 & Office 2016 下载地址
查看>>
tomcat应用转到weblogic上时的问题
查看>>
国外程序员是如何准备面试的
查看>>
Zookeeper监控之——node-zk-browser
查看>>
我的友情链接
查看>>
10个最酷的linux单行命令
查看>>
myeclipse 10 在mac retina 屏幕下显示字体模糊解决方法
查看>>
创建自定义的指令
查看>>
javascript对象中判断属性
查看>>
git删除分支与合并分支
查看>>
Python元组
查看>>
HD TUNE以及所有其他硬盘检测工具都不能使用的情况
查看>>
Linux内存分析
查看>>
vSphere 5.5 vCenter迁移至分布式交换机
查看>>
排序 遍历
查看>>
第二次作业
查看>>
Mysql主从复制
查看>>
高斯消元法解非奇异线性方程组的MATLAB程序
查看>>
Ubuntu下Tomcat连接MySql数据库
查看>>
WPF Summary 系列指导(连载中…^_^)
查看>>