Heritage of skywalkert

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 ≤ 107, 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 ai, and we ensure all ai > 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 106.

输出描述:

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

-->

 

输入

2
2 1 2 3
5 3 4 8

输出

Case #1: 68516050958
Case #2: 5751374352923604426

题意:n个数求任意两个数的最大的最小公倍数。
暴力模拟了一些数据发现答案的那两个数总是前15大的数,意思就是只有前15大的数才可能组合出答案。
于是用优先队列维护前15大的数,要注意最好尽量减少pop的操作,以免超时。
#include<bits/stdc++.h>
using namespace std;
unsigned int x,y,z;
unsigned int f()
{
unsigned int t;
x^=x<<;
x^=x>>;
x^=x<<;
t=x;
x=y;
y=z;
z=t^x^y;
return z;
} priority_queue<unsigned long long,vector<unsigned long long>,greater<unsigned long long> >team; unsigned long long gcd(unsigned long long a,unsigned long long b)
{
if(a%b==)return b;
return gcd(b,a%b);
} int tot=;
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d %u %u %u",&n,&x,&y,&z); for(int i=; i<=n; i++)
{
unsigned long long now=f(); if(team.size()>=&&team.top()>=now)continue;
team.push(now);
if(team.size()>)team.pop();
} unsigned long long now[];
unsigned long long ans=;
int c1=;
while(!team.empty())
{
now[c1++]=team.top();
team.pop();
} for(int i=; i<c1; i++)
for(int j=; j<c1; j++)
if(i!=j)ans=max(ans,now[i]/gcd(now[i],now[j])*now[j]); printf("Case #%d: %llu\n",tot++,ans);
}
return ;
}

Heritage of skywalkert的更多相关文章

  1. (第六场)Heritage of skywalkert 【玄学】

    题目链接:https://www.nowcoder.com/acm/contest/144/J 标题:J.Heritage of skywalkert | 时间限制:1 秒 | 内存限制:256M s ...

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

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

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

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

  4. 牛客网暑期ACM多校训练营(第六场) J Heritage of skywalkert(数论, eth_element)

    链接: https://www.nowcoder.com/acm/contest/144/J 题意: 给定一个函数, 求它n次结果中任意两次的lcm最大值 分析: 首先要看出这个函数并没有什么含义, ...

  5. 牛客2018多校第六场 J Heritage of skywalkert - nth_element

    传送门 题意:提供一个随机生成函数,让你生成n个数,然后问你其中能找到的两个数的最小公倍数 最大 是多少. 思路:可以用nth_element()函数在O(n)下求出前 15 个大的数(当然,100个 ...

  6. 随机生成数组函数+nth-element函数

    这几天做了几道随机生成数组的题,且需要用nth-elemeng函数,并且都是北航出的多校题…… 首先我们先贴一下随机生成数组函数的代码: unsigned x = A, y = B, z = C; u ...

  7. R自动数据收集第一章概述——《List of World Heritage in Danger》

      导包     library(stringr) library(XML) library(maps) heritage_parsed <- htmlParse("http://en ...

  8. 洛谷P1827 美国血统 American Heritage

    P1827 美国血统 American Heritage 54通过 90提交 题目提供者JOHNKRAM 标签USACO 难度普及- 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 农夫约翰非 ...

  9. NOIopenjudge 407:Heritage

    总时间限制:  5000ms 内存限制:  65536kB 描述 Your rich uncle died recently, and the heritage needs to be divided ...

随机推荐

  1. python打飞机pro版

    # -*- coding: utf-8 -*- import pygame from sys import exit import random pygame.init() screen = pyga ...

  2. UVA 1220 Party at Hali-Bula (树形DP)

    求一棵数的最大独立集结点个数并判断方案是否唯一. dp[i][j]表示以i为根的子树的最大独立集,j的取值为选和不选. 决策: 当选择i时,就不能选择它的子结点. 当不选i时,它的子结点可选可不选. ...

  3. 多维的vector定义和初始化

    vector<vector<int> >vv(3, vector<int>(4));//这里,两个“>”间的空格是不可少的 将构造一个二维向量vv,它含有三个 ...

  4. 五、Pandas玩转数据

    Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...

  5. 如何移除 Navicat Premium for Mac 的所有文件

    作者:郭文峰链接:http://www.zhihu.com/question/24210959/answer/34579422来源:知乎著作权归作者所有,转载请联系作者获得授权. 数据库连接信息存放在 ...

  6. 拼凑json的实例

    一,拼凑  json 串 并传到后台 function writeToJson(num){ var i = 1; var jsonData = "["; for(i=1;i< ...

  7. vue新手入坑之mounted和created的区别(生命周期)

    这几个月用vue框架新做了一个项目,也算是边学习边实践吧.学习中也看过一些别人的开源项目,起初对mounted和created有一些疑惑,查询相关资料发现,这和vue的生命周期有关,在此也就做一个总结 ...

  8. ZJOI2018游记Round2

    Day0 趁着空档还溜回班上了一节物理课:瓢泼之中在9:00赶往余姚,车程3h+-- 中饭在一家饭馆,味道海星. 晚上和ykh,chj,xzt溜去吃一鸣和烧烤.一鸣不错,烧烤的话我因为口腔溃疡没怎么吃 ...

  9. Javaweb开发之路

    本文作者:DavidLin 欢迎转载,但请保留文章原始出处→_→ 本文地址:http://www.cnblogs.com/univeryinli/p/programming-skill-yinli.h ...

  10. MySql压缩版安装及避免1055错误和msvcp120.dll丢失

    MySql压缩版安装及避免1055错误和msvcp120.dll丢失 MySQL压缩版的安装快速方便,5.7及最新的8版本安装方式大致相同. 在使用group by分组时,可能会遇到1055错误. 另 ...