牛客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是一个大质数. 做法是李指导教我 ...
随机推荐
- RocketMQ中Producer的启动源码分析
RocketMQ中通过DefaultMQProducer创建Producer DefaultMQProducer定义如下: public class DefaultMQProducer extends ...
- Docker部署ELK 日志归集
ELK ELK是Elasticsearch.Logstash.Kibana的缩写,使用ELK的原因是因为公司使用Spring cloud部署了多个微服务,不同的微服务有不同的日志文件,当生产上出现问题 ...
- hdoj 4715 Difference Between Primes 素数筛选+二分查找
#include <string.h> #include <stdio.h> const int maxn = 1000006; bool vis[1000006]; int ...
- &= 的含义
这是一个缩略式子,展开之后的结果是a = a & b;&是按位与的操作符. 按位与运算:参加运算的两个数据,按二进位进行“与”运算.如果两个相应的二进位都为1,则该位的结果值为1,否则 ...
- File signature analysis fails to recognize .old file
My friend May she found a strange file called "bkp.old" as below in the evidence files. Sh ...
- GStreamer流媒体知识介绍
GStreamer框架 1.GStreamer是什么? 众所周知,Microsoft's Windows和Apple's MacOS对多媒体设备.多媒体创作.播放和实时处理等方面都有很好的支持,而Li ...
- webpack4核心模块tapable源码解析
_ 阅读目录 一:理解Sync类型的钩子 1. SyncHook.js 2. SyncBailHook.js 3. SyncWaterfallHook.js 4. SyncLoopHook.js 二: ...
- Serilog 自定义Enricher 来增加记录的信息
Serilog 自定义Enricher 来增加记录的信息 Intro Serilog 是 .net 里面非常不错的记录日志的库,结构化日志记录,而且配置起来很方便,自定义扩展也很方便 Serilog ...
- SimpleDateFormat线程不安全问题解决及替换方法
场景:在多线程情况下为避免多次创建SimpleDateForma实力占用资源,将SimpleDateForma对象设置为static. 出现错误:SimpleDateFormat定义为静态变量,那么多 ...
- JavaWeb无框架,借助反射采用精巧设计模式实现放微信PC聊天页面
本周开始在写仿写一个微信PC端的聊天页面,没有使用ssh.ssm等框架,采用JavaWeb.反射.MySQL.C3P0等技术.这里把其中和核心技术列出来请大家指教. 与传统JavaWeb项目的区别 传 ...