Heritage of skywalkert(思维 + STL)

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.

示例1

输入

复制

2
2 1 2 3
5 3 4 8

输出

复制

Case #1: 68516050958
Case #2: 5751374352923604426

题意:题意:给出n,a,b,c,按照题目给的式子求a[1]~a[n]。最后求所有(i,j)的最大LCM。

分析:数据量巨大。这个题真的是各路神仙都来了,STL一通乱搞的,然后大胆暴力的。大佬做这种题应该都是有经验了,不能说人家胆子大,只能说是老江湖有经验,知道这么做看似不稳实则稳的一匹。

1、由于数据量太大,而题目让我们求的就是最小公倍数。那么两个数都尽量大,它俩最小公倍数才有可能是那个最大值。

2、所以从大到小排序,暴力前100个就ok了(好像只用暴力20个就行了)。

3、这里不能用sort O(nlogn)会超时。看了大佬的有用set的,也有用nth_element的。set不多说,自带排序。

4、nth_element这个排序就是只排序第n大的元素。处理完之后,默认排在它前面的元素都不比它大,排在它后面的元素都不比它小。nth_element(a,a+max(0,n-100),a+n);

代码就只贴set的那一种了。

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e7+10;
const int mod=1e9+7;
typedef long long ll;
typedef unsigned ui;
typedef unsigned long long ull;
using namespace std;

inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );

int n;
ui A,B,C;
ui x,y,z;
ull a[MAX],b[MAX];
ull gcd(ull a,ull b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
ull lcm(ull a,ull b)
{
    return a/gcd(a,b)*b;
}
ui tang()
{
    ui t;
    x^=x<<16;
    x^=x>>5;
    x^=x<<1;
    t=x;
    x=y;
    y=z;
    z=t^x^y;
    return z;
}
int main()
{
    int t,p=0;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%u%u%u",&n,&A,&B,&C);
        x=A;y=B;z=C;
        set<ull>s;
        for(int i=1;i<=n;i++)
        {
            a[i]=(ull)tang();

            if(i==1)
                s.insert(a[1]);

            if(s.size()<100 || a[i]>*s.begin())
                s.insert(a[i]);
            if(s.size()>100)
                s.erase(s.begin());
        }

        int cut=0;
        set<ull> :: iterator it;
        for(it=s.begin();it!=s.end();it++)
            b[++cut]=*it;

        ull ans=0;
        for(int i=1;i<=cut;i++)
            for(int j=i+1;j<=cut;j++)
                ans=max(ans,lcm(b[i],b[j]));

        printf("Case #%d: %llu\n",++p,ans);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Chinese tea culture has a long history and is deeply rooted in Chinese tradition. It is not only a way of life, but also a symbol of national pride. The sense of national pride brought by Chinese tea culture can be seen in many aspects. Firstly, Chinese tea culture is a reflection of Chinese philosophy and aesthetics. The way of making tea, the tea sets, and the tea ceremony all embody the Chinese philosophy of harmony between man and nature, and the pursuit of simplicity and elegance. The beauty of Chinese tea culture has been recognized and appreciated by people all over the world, which makes Chinese people proud of their cultural heritage. Secondly, Chinese tea culture is closely related to Chinese history and geography. China is the birthplace of tea, and tea has been an important part of Chinese people's daily life for thousands of years. The different types of tea and the different ways of making tea reflect the diversity of Chinese culture and the regional differences in China. Chinese people take pride in their unique tea culture and the rich history behind it. Thirdly, Chinese tea culture is a symbol of hospitality and friendship. In Chinese culture, serving tea to guests is a way of showing respect and hospitality. The tea ceremony is also a way of building relationships and strengthening friendships. Chinese people take pride in their ability to make guests feel welcome and comfortable through the art of tea. In conclusion, Chinese tea culture is not just a beverage, but a way of life and a symbol of national pride. It reflects the Chinese philosophy, history, geography, and hospitality. Chinese people take great pride in their tea culture and the beauty and richness it brings to their lives.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值