传送门

题意:提供一个随机生成函数,让你生成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的更多相关文章

  1. 牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)

    链接:https://www.nowcoder.com/acm/contest/144/J来源:牛客网 skywalkert, the new legend of Beihang University ...

  2. 牛客2018多校第五场E-room 最小费用最大流

    题意:有n个寝室,每个寝室4个人,现在在搞搬寝室的活动,告诉你每个寝室之前的人员名单,和之后的人员名单,问最少需要几个人要搬寝室. 思路: 转化为最小费用最大流解决的二分图问题,对每个去年的宿舍,向每 ...

  3. 牛客暑假多校第六场I-Team Rocket

    一.题意 我们是穿越银河的火箭队....... 给出若干个区间,之后给出若干个点,要求对每个点求出,第一个覆盖点的区间的数量,之后用当前所有点覆盖的区间的序号的乘积结合输入的Y来生成下一位点.最后输出 ...

  4. 牛客暑假多校第六场 I Team Rocket

    题意: 现在有n条火车, 每条火车都有一个运行 [ Li, Ri ], 现在有m支火箭队, 每次火箭队都会破坏这整条铁路上的一个点, 如果一条火车的运行区间[Li, Ri] 被破坏了, 那么这条火车会 ...

  5. 2019牛客暑期多校第六场题解ABDJ

    A.Garbage Classification 传送门 题意:给你两个串,第一个串s由小写字母组成,第二个串t由dwh组成,长度为26,分别表示字母a到z代表的字符.现在要你判断: 如果字符串中‘h ...

  6. 牛客网多校第4场 J Hash Function 【思维+并查集建边】

    题目链接:戳这里 学习博客:戳这里 题意: 有n个空位,给一个数x,如果x%n位数空的,就把x放上去,如果不是空的,就看(x+1)%n是不是空的. 现在给一个已经放过数的状态,求放数字的顺序.(要求字 ...

  7. 牛客第六场 J.Heritage of skywalkert(On求前k大)

    题目传送门:https://www.nowcoder.com/acm/contest/144/J 题意:给一个function,构造n个数,求出其中任意两个的lcm的最大值. 分析:要求最大的lcm, ...

  8. 牛客网多校训练第一场 J - Different Integers(树状数组 + 问题转换)

    链接: https://www.nowcoder.com/acm/contest/139/J 题意: 给出n个整数的序列a(1≤ai≤n)和q个询问(1≤n,q≤1e5),每个询问包含两个整数L和R( ...

  9. 2020牛客暑期多校训练营 第二场 J Just Shuffle 置换 群论

    LINK:Just Shuffle 比较怂群论 因为没怎么学过 置换也是刚理解. 这道题是 已知一个置换\(A\)求一个置换P 两个置换的关键为\(P^k=A\) 且k是一个大质数. 做法是李指导教我 ...

随机推荐

  1. T-SQL 日期

    --日期查询格式 ) --R:06/17/2011 ) --R:2011.06.17 ) --R:17/06/2011 ) --R:17.06.2011 ) --R:17-06-2011 ) --R: ...

  2. spring-boot-plus集成Spring Boot Admin管理和监控应用

    Spring Boot Admin Spring Boot Admin用来管理和监控Spring Boot应用程序 应用程序向我们的Spring Boot Admin Client注册(通过HTTP) ...

  3. 【Java】Caused by: com.ibatis.sqlmap.client.SqlMapException: There is no statement named *** in this SqlMap.

    如题: 可能原因: 在xxx.xml文件中有两个标签的id命名相同: DAO实现类方法中没有写对应xxx.xml的id名称: 实体映射文件xxx.xml未加入到sqlMap-Config.xml文件中 ...

  4. 【iOS】this class is not key value coding-compliant for the key ...

    一般此问题 都是由 interface build 与代码中 IBOutlet 的连接所引起的. 可能是在代码中对 IBOutlet 的名称进行了修改,导致 interface build 中的连接实 ...

  5. 【Android Studio】Frameworks detected: Android framework is detected in the project Configure

    刚开始在 Mac 上用 Android Studio, 打开第一个项目就遇到了问题,描述如下: 上午9:: Frameworks detected: Android framework is dete ...

  6. Linux基础文件查找

    一.文件查找 (一).命令文件 [root@linux ~]# chich ls //从PATH环境变量 [root@linux ~]# chereis vim [root@linux ~]# ech ...

  7. Java - 自动配置log4j的日志文件路径

    目录 1 日志路径带来的痛点 2 log4j.properties文件的配置 3 彻底解决痛点 3.1 单独的Java程序包 (非Java Web项目) 3.2 Web项目 4 附录 - 获取当前项目 ...

  8. soap天气查询

    public class MainActivity extends AppCompatActivity { private TextView tvContent; @Override protecte ...

  9. sql存储过程中循环批量插入

    前几天有一个需求很头痛,部门是有上下级关系的,在给部门的经理赋予角色和权限的时候,通常我们都会认为假如经理A的部门是1,那么我给了他部门1 的管理权限,那么1的下级部门101,102,103 &quo ...

  10. 关于int的范围以及溢出问题

    最近在练一些算法题目的时候恰巧碰到了几道关于int范围与溢出相关的问题,于是就整理一下. 1.原码.补码 在计算机中数值都是用补码表示和存储的(正数补码与原码一致,负数补码是原码符号位不变,其余位取反 ...