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

本篇博客解析了Heritageofskywalkert题目,介绍了如何通过选取前100个最大数值来求解任意两数间最大最小公倍数的问题。利用nth_element算法优化并实现快速求解。

题目链接:https://www.nowcoder.com/acm/contest/144/J

标题:J、Heritage of skywalkert

| 时间限制:1 秒 | 内存限制:256M

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 个数, 求其中两个数的最小公倍数的最大值。

官方题解:

由于数据看上去像是随机⽣生成的,只需要选出前 100 大的数平方暴力即可。 随机两个正整数互质的概率为 6/(π^2) = 0.608...

解题思路:

nth_element()选出前100大的数,暴力前 100 大的数取最大的最小公倍数。

 

AC code:

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <algorithm>
 4 #include <cmath>
 5 #define INF 0x3f3f3f3f
 6 #define ll unsigned long long
 7 using namespace std;
 8 
 9 const int MAXN = 1e7+10;
10 
11 ll num[MAXN];
12 unsigned int N, A, B, C;
13 unsigned int x, y, z;
14 
15 ll gcd(ll x, ll y)
16 {
17     return y==0?x:gcd(y, x%y);
18 }
19 
20 bool cmp(ll x, ll y)
21 {
22     return x>y;
23 }
24 
25 unsigned tang()
26 {
27     unsigned t;
28     x ^= x<<16;
29     x ^= x>>5;
30     x ^= x<<1;
31     t = x;
32     x = y;
33     y = z;
34     z = t^x^y;
35     return z;
36 }
37 
38 int main()
39 {
40     int T_case;
41     scanf("%d", &T_case);
42     int cnt = 0;
43     while(T_case--)
44     {
45 
46         scanf("%u%u%u%u", &N, &A, &B, &C);
47         x = A, y = B, z = C;
48         for(int i = 0; i < N; i++)
49         {
50             num[i] = tang();
51         }
52         unsigned int k = min(100u, N);
53         nth_element(num, num+k, num+N, cmp);
54         ll res = 0;
55         for(int i = 0; i < k; i++)
56             for(int j = i+1; j < k; j++)
57         {
58             res = max(res, num[i]*num[j]/gcd(num[i],num[j]));
59         }
60         printf("Case #%d: %llu\n", ++cnt, res);
61     }
62     return 0;
63 }
View Code

 

内容概要:本文详细介绍了“秒杀商城”微服务架构的设计与实战全过程,涵盖系统从需求分析、服务拆分、技术选型到核心功能开发、分布式事务处理、容器化部署及监控链路追踪的完整流程。重点解决了高并发场景下的超卖问题,采用Redis预减库存、消息队列削峰、数据库乐观锁等手段保障数据一致性,并通过Nacos实现服务注册发现与配置管理,利用Seata处理跨服务分布式事务,结合RabbitMQ实现异步下单,提升系统吞吐能力。同时,项目支持Docker Compose快速部署和Kubernetes生产级编排,集成Sleuth+Zipkin链路追踪与Prometheus+Grafana监控体系,构建可观测性强的微服务系统。; 适合人群:具备Java基础和Spring Boot开发经验,熟悉微服务基本概念的中高级研发人员,尤其是希望深入理解高并发系统设计、分布式事务、服务治理等核心技术的开发者;适合工作2-5年、有志于转型微服务或提升架构能力的工程师; 使用场景及目标:①学习如何基于Spring Cloud Alibaba构建完整的微服务项目;②掌握秒杀场景下高并发、超卖控制、异步化、削峰填谷等关键技术方案;③实践分布式事务(Seata)、服务熔断降级、链路追踪、统一配置中心等企业级中间件的应用;④完成从本地开发到容器化部署的全流程落地; 阅读建议:建议按照文档提供的七个阶段循序渐进地动手实践,重点关注秒杀流程设计、服务间通信机制、分布式事务实现和系统性能优化部分,结合代码调试与监控工具深入理解各组件协作原理,真正掌握高并发微服务系统的构建能力。
### Heritage Science npj 参考文献格式指南 Heritage Science 是一种遵循特定引用规范的学术期刊。其参考文献条目通常采用 APA 或者 Vancouver 风格的一种变体,具体取决于作者指南的要求。以下是基于所提供的信息以及常见的 Heritage Science 引用风格来构建参考文献条目的方法。 #### 文献引用基本结构 对于一篇期刊文章,在 Heritage Science 中的标准参考文献格式如下: - **作者姓名**: 姓氏在前,名字缩写在后。 - **出版年份**: 放置在括号中。 - **文章标题**: 使用句首大写字母书写。 - **期刊名称**: 斜体显示。 - **卷号**(期号): 页面范围。 例如: Smith J, Doe A. Building Information Modeling for Cultural Heritage Conservation (2023). *Heritage Science* 11(1), pp. 1–15 [^1]. 如果涉及在线资源,则需补充 DOI 或 URL 地址。 #### 示例:PRISMA 方法应用于 HBIM 的参考文献条目 假设原始资料来自 Scopus 和 Google Scholar 数据库中的论文,可以按照以下方式格式化该条目: Doe A, Smith J. Application of PRISMA Approach to Data Collection on Heritage Building Information Modeling (HBIM) Within Ten Years (2023). *Journal Name*, Volume(Issue), Pages. https://doi.org/XXXXX 其中,“https://doi.org/XXXXX”应替换为实际存在的 DOI 编码;如果没有 DOI,则提供完整的访问链接或者说明数据获取途径。 另外需要注意的是,当提及具体的数据库时(如 Scopus 和 Google Scholar),可以在正文部分简单描述而不必列入正式参考列表里除非特别强调这些平台本身作为研究对象的一部分。 --- ### 如何实现上述格式? 为了确保符合 Heritage Science 的标准,建议采取以下措施之一: 1. 利用手动输入法严格按照模板填写每一条目; 2. 运用 EndNote/Zotero/Mendeley 等文献管理工具自动生成并调整至目标期刊所需的样式文件下导出最终版本。 下面给出一段 Python 脚本用于自动化生成简单的参考文献字符串(仅作演示用途): ```python def generate_reference(author="Author Lastname", year=2023, title="Title Here", journal="Journal Name", volume=1, issue=1, pages=(1, 10)): formatted_title = ' '.join([word.capitalize() if i == 0 else word.lower() for i, word in enumerate(title.split())]) reference_string = f"{author} ({year}). {formatted_title}. *{journal}* {volume}({issue}), {pages[0]}-{pages[1]}." return reference_string print(generate_reference( author="Doe A", year=2023, title="Application Of Prisma Approach To Data Collection On Hbim For Heritage Conservation Within Ten Years", journal="Heritage Science", volume=11, issue=1, pages=(1, 15))) ``` 运行此脚本将会得到类似于之前提到的手工编写的参考文献项。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值