牛客2018多校第六场 J Heritage of skywalkert - nth_element
题意:提供一个随机生成函数,让你生成n个数,然后问你其中能找到的两个数的最小公倍数 最大 是多少。
思路:可以用nth_element()函数在O(n)下求出前 15 个大的数(当然,100个数也是可以的),暴力枚举这15个数两两求最小公倍数的结果。当然可以用小根堆优先队列,保证队列中有15个最大的数。
(雾,由于是随机数,互质的概率大。
// #include<bits/stdc++.h>
//#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<cstddef>
#include<cstdio>
#include<memory>
#include<vector>
#include<cctype>
#include<string>
#include<cmath>
#include<queue>
#include<deque>
#include<ctime>
#include<stack>
#include<map>
#include<set> #define fi first
#define se second
#define pb push_back
#define INF 0x3f3f3f3f
#define pi 3.1415926535898
#define lson l,(l+r)/2,rt<<1
#define rson (l+r)/2+1,r,rt<<1|1
#define Min(a,b,c) min(a,min(b,c))
#define Max(a,b,c) max(a,max(b,c))
using namespace std; typedef long long ll;
typedef pair<int,int> P;
typedef unsigned long long ull; const int MOD=1e9+;
const ll LLMAX=2e18;
const int MAXN=1e6+; template<class T>
inline void read(T &DataIn)
{
DataIn=; T Flag=; char c=getchar();
while(!isdigit(c)){ Flag|=c=='-'; c=getchar(); }
while(isdigit(c)){ DataIn=DataIn*+c-''; c=getchar(); }
DataIn= Flag? -DataIn: DataIn;
} template<class T>
inline void write(T DataOut,char EndChar='\n')
{
T lenth=,number[];
if(DataOut==){ putchar(); return; }
while(DataOut>){ number[++lenth]=DataOut%; DataOut/=;}
for(int i=lenth;i>=;i--) putchar(number[i]+);
putchar(EndChar);
} //priority_queue<ll,vector<ll>,less<ll> > qd;
// priority_queue<ll, vector<ll>, greater<ll> > qu; const int maxn = 2e7+; int n;
ull A,B,C; unsigned x,y,z;
unsigned tang(){
unsigned t;
x ^=x<<;
x ^=x>>;
x ^=x<<;
t=x;
x=y;
y=z;
z=t^x^y;
return z;
}
ull mp[maxn],mx;
bool cmp(const ull &a,const ull &b){
return a > b;
}
ull gcd(ull a,ull b){
if(b==)return a;
else return gcd(b,a%b);
}
int main(void)
{
FILE *fin=NULL,*fout=NULL;
ios::sync_with_stdio(false); cin.tie();
//fin=freopen("D:/Project__C++/testdata.in","r",stdin);
//fout=freopen("D:/Project__C++/testdata.out","w",stdout);
int t;
cin>>t; for(int T = ; T <= t; T ++)
{ cin>>n>>A>>B>>C; x=A,y=B,z=C; for(int i=;i<n;i++)
{
mp[i] = tang();
}
int tot = min(n,); //由于是随机的,所以取前15个枚举就可以通过此题。
nth_element(mp,mp+tot,mp+n,cmp);
mx = ;
for(int i=; i<tot; i++){
for(int j=i+; j<tot; j++){
mx = max(mx, mp[i] / (gcd(mp[i],mp[j])) * mp[j]);
}
}
cout<<"Case #"<<T<<": "<<mx<<endl;
} return ;
}
nth_element
牛客2018多校第六场 J Heritage of skywalkert - nth_element的更多相关文章
- 牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)
链接:https://www.nowcoder.com/acm/contest/144/J来源:牛客网 skywalkert, the new legend of Beihang University ...
- 牛客2018多校第五场E-room 最小费用最大流
题意:有n个寝室,每个寝室4个人,现在在搞搬寝室的活动,告诉你每个寝室之前的人员名单,和之后的人员名单,问最少需要几个人要搬寝室. 思路: 转化为最小费用最大流解决的二分图问题,对每个去年的宿舍,向每 ...
- 牛客暑假多校第六场I-Team Rocket
一.题意 我们是穿越银河的火箭队....... 给出若干个区间,之后给出若干个点,要求对每个点求出,第一个覆盖点的区间的数量,之后用当前所有点覆盖的区间的序号的乘积结合输入的Y来生成下一位点.最后输出 ...
- 牛客暑假多校第六场 I Team Rocket
题意: 现在有n条火车, 每条火车都有一个运行 [ Li, Ri ], 现在有m支火箭队, 每次火箭队都会破坏这整条铁路上的一个点, 如果一条火车的运行区间[Li, Ri] 被破坏了, 那么这条火车会 ...
- 2019牛客暑期多校第六场题解ABDJ
A.Garbage Classification 传送门 题意:给你两个串,第一个串s由小写字母组成,第二个串t由dwh组成,长度为26,分别表示字母a到z代表的字符.现在要你判断: 如果字符串中‘h ...
- 牛客网多校第4场 J Hash Function 【思维+并查集建边】
题目链接:戳这里 学习博客:戳这里 题意: 有n个空位,给一个数x,如果x%n位数空的,就把x放上去,如果不是空的,就看(x+1)%n是不是空的. 现在给一个已经放过数的状态,求放数字的顺序.(要求字 ...
- 牛客第六场 J.Heritage of skywalkert(On求前k大)
题目传送门:https://www.nowcoder.com/acm/contest/144/J 题意:给一个function,构造n个数,求出其中任意两个的lcm的最大值. 分析:要求最大的lcm, ...
- 牛客网多校训练第一场 J - Different Integers(树状数组 + 问题转换)
链接: https://www.nowcoder.com/acm/contest/139/J 题意: 给出n个整数的序列a(1≤ai≤n)和q个询问(1≤n,q≤1e5),每个询问包含两个整数L和R( ...
- 2020牛客暑期多校训练营 第二场 J Just Shuffle 置换 群论
LINK:Just Shuffle 比较怂群论 因为没怎么学过 置换也是刚理解. 这道题是 已知一个置换\(A\)求一个置换P 两个置换的关键为\(P^k=A\) 且k是一个大质数. 做法是李指导教我 ...
随机推荐
- 【JDK】JDK源码-Queue, Deque
概述 Queue 和 Deque 都是接口.其中 Queue 接口定义的是一个队列,它包含队列的基本操作:入队(enqueue)和出队(dequeue). Deque 接口继承自 Queue 接口,表 ...
- DVWA-SQL注入
SQL注入解题思路 寻找注入点,可以通过web扫描工具实现 通过注入点,尝试得到连接数据库的用户名,数据库名称,权限等信息. 猜解关键数据库表极其重要字段与内容. 通过获得的用户信息寻找后台进行登录. ...
- input属性设置type="number"之后, 仍可输入e, E, -, + 的解决办法
<el-input v-model="scope.row.variables.leaderbuweiscores.score" @keyup.native="cha ...
- ElasticSearch6.x版本聚合分析整理
ElasticSearch6.x版本聚合分析整理 ES将聚合分析主要分为如下4类 Bucket,分桶类型,类似SQL中的GROUP BY语法 Metric,指标分析类型,如计算最大值 , 最小值,平均 ...
- Salesforce LWC学习(三) import & export / api & track
我们使用vs code创建lwc 时,文件会默认生成包含 template作为头的html文件,包含了 import LightningElement的 js文件以及对应的.js-meta.xml文件 ...
- dotnetcore 与 hbase 之一——hbase 环境准备
转载请注明出处www.cnblogs.com/hsxian! 总述 这是一系列针对 .net core (c#) 读取 hbase 的教程.本人苦于找不到 c#的原生 hbase 客户端,多番寻觅之下 ...
- SVG和canvas渲染的性能比较
1.什么是SVG? 描述: 一种使用XML描述的2D图形的语言 SVG基于XML意味着,SVG DOM中的每个元素都是可用的,可以为某个元素附加Javascript事件处理器. 在 SVG 中,每个被 ...
- The introduction of the book American daily English notes (enlarged edition)
After reading the book of American daily English notes written by Linkun Yang[1], I think I should a ...
- SonarQube系列二、分析dotnet core/C#代码
[前言] 本系列主要讲述sonarqube的安装部署以及如何集成jenkins自动化分析.netcore项目.目录如下: SonarQube系列一.Linux安装与部署 SonarQube系列二.分析 ...
- hadoop2.7之作业提交详解(上)
根据wordcount进行分析: import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; impo ...