Codeforces Round 1047 (Div. 3)

由于最近这三天的数学建模,让我这个精力本来就不多的AI手更加力竭了,没注意到昨晚的cf,所以今天来补题了。
比赛连接:比赛传送门

A题:

You are doing a research paper on the famous Collatz Conjecture. In your experiment, you start off with an integer xxx, and you do the following procedure kkk times:

  • If xxx is even, divide xxx by 222.
  • Otherwise, set xxx to 3⋅x+13\cdot x+13x+1.

For example, starting off with 212121 and doing the procedure 555 times, you get 21→64→32→16→8→421\rightarrow64\rightarrow32\rightarrow16\rightarrow8\rightarrow42164321684.

After all kkk iterations, you are left with the final value of xxx. Unfortunately, you forgot the initial value. Please output any possible initial value of xxx.
Input

Each test contains multiple test cases. The first line contains the number of test cases ttt (1≤t≤4001 \le t \le 4001t400). The description of the test cases follows.

The first line of each test case contains two integers kkk and xxx (1≤k,x≤201 \leq k,x \leq 201k,x20).
Output

For each test case, print any possible initial value on a new line. It can be shown that the answer always exists.
Note

In the first test case, since 111 is odd, performing the procedure k=1k=1k=1 times results in 1⋅3+1=41\cdot3+1=413+1=4, so 111 is a valid output.

In the second test case, since 101010 is even, performing the procedure k=1k=1k=1 times results in 102=5\frac{10}{2}=5210=5, so 101010 is a valid output.

The third test case is explained in the statement.

通过观察不难发现,两种操作都是变为了偶数,所以一直在原来的基础上乘2即可(永远都只用操作一即可)。

// Problem: A. Collatz Conjecture
// Contest: Codeforces - Codeforces Round 1047 (Div. 3)
// URL: https://codeforces.com/contest/2137/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pii pair<int,int>
#define fi first
#define se second
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define lbt(x) ((x) & (-x)) const int INF = 0x3f3f3f3f;
const int inf = 1e18; void solve()
{int n,k;cin>>k>>n;int an = n;for(int i=1;i<=k;i++) an *= 2LL;cout<<an<<endl;
//	cout<<fixed<<setprecision(x)<< ; 
}signed main()// Don't forget pre_handle!
{IOSint T=1;cin>>T;while(T--) solve(); return 0;
} 

B题

You are given a permutation∗^{\text{∗}} ppp of size nnn.

Your task is to find a permutation qqq of size nnn such that GCD⁡\operatorname{GCD}GCD†^{\text{†}}(pi+qi,pi+1+qi+1)≥3(p_i+q_i, p_{i+1}+q_{i+1}) \geq 3(pi+qi,pi+1+qi+1)3 for all KaTeX parse error: Expected 'EOF', got '&' at position 9: 1 \leq i&̲lt;n. In other words, the greatest common divisor of the sum of any two adjacent positions should be at least 333.

It can be shown that this is always possible.

∗^{\text{∗}}A permutation of length mmm is an array consisting of mmm distinct integers from 111 to mmm in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2][1,2,2] is not a permutation (222 appears twice in the array), and [1,3,4][1,3,4][1,3,4] is also not a permutation (m=3m=3m=3 but there is 444 in the array).

†^{\text{†}}gcd⁡(x,y)\gcd(x, y)gcd(x,y) denotes the greatest common divisor (GCD) of integers xxx and yyy.
Input

Each test contains multiple test cases. The first line contains the number of test cases ttt (1≤t≤1041 \le t \le 10^41t104). The description of the test cases follows.

The first line of each test case contains an integer nnn (2≤n≤2⋅1052 \leq n \leq 2\cdot 10^52n2105).

The second line contains nnn integers p1,p2,…,pnp_1,p_2,\ldots,p_np1,p2,,pn (1≤pi≤n1 \leq p_i \leq n1pin).

It is guaranteed that the given array forms a permutation.

It is guaranteed that the sum of nnn over all test cases does not exceed 2⋅1052\cdot 10^52105.
Output

For each test case, output the permutation qqq on a new line. If there are multiple possible answers, you may output any.
Note

In the first test case, GCD⁡(1+2,3+3)=3≥3\operatorname{GCD}(1+2,3+3)=3\geq 3GCD(1+2,3+3)=33 and GCD⁡(3+3,2+1)=3≥3\operatorname{GCD}(3+3,2+1)=3\geq3GCD(3+3,2+1)=33, so the output is correct.

这道题也很好想,最大公约数,又因为是排列,所以我们肯定不难想到用最大的和去和每个元素进行配对,这样所有的两个位置上两个排列中所对应的数相加的和都相同了,那么这个时候就是满足条件的排列了。

// Problem: B. Fun Permutation
// Contest: Codeforces - Codeforces Round 1047 (Div. 3)
// URL: https://codeforces.com/contest/2137/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pii pair<int,int>
#define fi first
#define se second
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define lbt(x) ((x) & (-x)) const int INF = 0x3f3f3f3f;
const int inf = 1e18; void solve()
{int n;cin>>n;vector<int> a(n+1);for(int i=1;i<=n;i++) cin>>a[i];int sum = n + 1;for(int i=1;i<=n;i++) cout<<sum - a[i]<<' ';cout<<endl;
//	cout<<fixed<<setprecision(x)<< ; 
}signed main()// Don't forget pre_handle!
{IOSint T=1;cin>>T;while(T--) solve(); return 0;
} 

C题

You are given two integers aaa and bbb. You are to perform the following procedure:

First, you choose an integer kkk such that bbb is divisible by kkk. Then, you simultaneously multiply aaa by kkk and divide bbb by kkk.

Find the greatest possible even value of a+ba+ba+b. If it is impossible to make a+ba+ba+b even, output −1-11 instead.
Input

Each test contains multiple test cases. The first line contains the number of test cases ttt (1≤t≤1041 \le t \le 10^41t104). The description of the test cases follows.

The first line of each test case contains two integers aaa and bbb (1≤a,b≤a⋅b≤1018)1 \leq a,b \leq a\cdot b \leq 10^{18})1a,bab1018).
Output

For each test case, output the maximum even value of a+ba+ba+b on a new line.
Note

In the first test case, it can be shown it is impossible for a+ba+ba+b to be even.

In the second test case, the optimal kkk is 222. The sum is 2+4=62+4=62+4=6.

分情况讨论即可

// Problem: C. Maximum Even Sum
// Contest: Codeforces - Codeforces Round 1047 (Div. 3)
// URL: https://codeforces.com/contest/2137/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pii pair<int,int>
#define fi first
#define se second
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define lbt(x) ((x) & (-x)) const int INF = 0x3f3f3f3f;
const int inf = 1e18; void solve()
{int a,b;cin>>a>>b;if((a * b) & 1) {cout<<a * b + 1<<endl;return ;}int ans = -1;if(b & 1){cout<<ans<<endl;return ;}if((a * (b / 2LL) + 2LL) & 1){cout<<ans<<endl;return ;}// if(a & 1LL)// {cout<<a * (b / 2LL) + 2LL<<endl;return ;// }// if(a % 2 == 0)// {// cout<<a * b// }
//	cout<<fixed<<setprecision(x)<< ; 
}signed main()// Don't forget pre_handle!
{IOSint T=1;cin>>T;while(T--) solve(); return 0;
} 

D题

Given an array aaa, let f(x)f(x)f(x) be the number of occurrences of xxx in the array aaa. For example, when a=[1,2,3,1,4]a=[1,2,3,1,4]a=[1,2,3,1,4], then f(1)=2f(1)=2f(1)=2 and f(3)=1f(3)=1f(3)=1.

You have an array bbb of size nnn. Please determine if there is an array aaa of size nnn such that f(ai)=bif(a_i)=b_if(ai)=bi for all 1≤i≤n1 \leq i \leq n1in. If there is one, construct it.
Input

Each test contains multiple test cases. The first line contains the number of test cases ttt (1≤t≤1041 \le t \le 10^41t104). The description of the test cases follows.

The first line of each test case contains an integer nnn (1≤n≤2⋅1051 \leq n \leq 2\cdot 10^51n2105).

The second line contains nnn integers b1,b2,…,bnb_1,b_2,\ldots,b_nb1,b2,,bn (1≤bi≤n1 \leq b_i \leq n1bin).

It is guaranteed that the sum of nnn over all test cases does not exceed 2⋅1052\cdot 10^52105.
Output

For each test case, output −1-11 if there is no valid array aaa.

Otherwise, print the array aaa of nnn integers on a new line. The elements should satisfy 1≤ai≤n1 \leq a_i \leq n1ain.
Note

In the first test case, it can be shown that no array matches the requirement.

In the second test case, 444, 555, 666 appear 1,2,31,2,31,2,3 times respectively. Thus, the output array is correct as f(4),f(5),f(5),f(6),f(6),f(6)f(4),f(5),f(5),f(6),f(6),f(6)f(4),f(5),f(5),f(6),f(6),f(6) are 1,2,2,3,3,31,2,2,3,3,31,2,2,3,3,3 respectively.

这道题用map嵌套pair可以省去很多步骤,思路也比较清楚

// Problem: D. Replace with Occurrences
// Contest: Codeforces - Codeforces Round 1047 (Div. 3)
// URL: https://codeforces.com/contest/2137/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pii pair<int,int>
#define fi first
#define se second
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define lbt(x) ((x) & (-x)) const int INF = 0x3f3f3f3f;
const int inf = 1e18; void solve()
{int n;cin>>n;vector<int> a(n+1);for(int i=1;i<=n;i++) cin>>a[i];map<int,pii> mp;for(int i=1;i<=n;i++) mp[a[i]].fi ++,mp[a[i]].se = 0;int num = 0;for(auto &i : mp) num += i.se.fi;if(num != n){cout<<"-1"<<endl;return ;}for(auto &i : mp){int t1 = i.fi,t2 = i.se.fi;if(t2 % t1){cout<<"-1"<<endl;return ;}}int index = 0LL;map<int,int> cnt;map<int,bool> v;for(int i=1;i<=n;i++){if(!v[a[i]]) mp[a[i]].se = ++index;if(cnt[a[i]] == a[i]){cnt[a[i]] = 0;mp[a[i]].se = ++index;}cnt[a[i]] ++;v[a[i]] = true;cout<<mp[a[i]].se<<' ';}// for(int i=1;i<=n;i++) cout<<mp[a[i]].se<<' ';cout<<endl;
//	cout<<fixed<<setprecision(x)<< ; 
}signed main()// Don't forget pre_handle!
{IOSint T=1;cin>>T;while(T--) solve(); return 0;
} 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/news/921666.shtml
繁体地址,请注明出处:http://hk.pswp.cn/news/921666.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C++经典的数据结构与算法之经典算法思想:贪心算法(Greedy)

贪心算法&#xff08;Greedy Algorithm&#xff09;&#xff1a;通过局部最优达成全局最优的决策策略 贪心算法是一种通过每次选择局部最优解来期望全局最优解的算法思想。它不考虑未来的影响&#xff0c;仅根据当前信息做出最优选择&#xff0c;适用于具有贪心选择性质和最优子…

LangChain实战(二十一):构建自动化AI客服系统

本文是《LangChain实战课》系列的第二十一篇,将带领您构建一个完整的自动化AI客服系统。通过结合对话记忆、工具调用和业务知识库,我们将创建一个能够处理复杂客户查询的智能客服解决方案。 前言 在现代商业环境中,客户服务是企业成功的关键因素之一。传统客服系统往往面临…

一人公司智能管理系统概述

系统概述 项目结构 Al_Compny系统采用前后端分离的全栈架构&#xff0c;项目根目录下包含两个主要子目录&#xff1a;Al_Compny_backend&#xff08;后端服务&#xff09;和Al_Compny_frontend&#xff08;前端应用&#xff09;。核心功能模块 Al_Compny系统是一个面向"一…

OpenWrt | 在 PPP 拨号模式下启用 IPv6 功能

文章目录一、WAN 口配置二、LAN 口配置三、IPv6 测试本文将详细介绍 将光猫的网络模式改成桥接之后使用路由器拨号的上网方式的情况下&#xff0c;在 OpenWrt 上使用 PPP 拨号模式上网时&#xff0c;启用 IPv6 功能的方法。 一、WAN 口配置 首先&#xff0c;我们需要在 网络 …

Java如何实现一个安全的登录功能?

安全登录系统完整教程 &#x1f4cb; 目录 项目概述技术栈安全特性项目结构核心组件详解安全实现原理部署和运行安全最佳实践常见问题解答进阶扩展 &#x1f3af; 项目概述 这是一个基于Spring Boot和Spring Security的完整安全登录系统&#xff0c;专为初学者设计&#xff…

星辰诞愿——生日快乐

前言 今天这篇博客并非技术文章&#xff0c;而是庆祝我可爱的妹妹18岁生日以及介绍我半年以来的学习经历 祝生网站&#xff1a;星辰诞愿(用户列表里第一位就是我妹妹&#xff0c;希望大家能献上自己的祝福&#xff0c;能分享转发更好&#xff0c;我在此感谢大家。如果使用手机&…

基于STM32单片机的智能粮仓温湿度检测蓝牙手机APP设计

基于STM32单片机的智能粮仓温湿度检测蓝牙手机APP设计 1 系统功能介绍 本系统是一款基于STM32单片机的智能粮仓环境监测与控制装置&#xff0c;核心目标是通过传感器实时采集粮仓内的温度和湿度信息&#xff0c;并结合蓝牙通信模块将数据传输至手机端&#xff0c;实现对粮仓环境…

简单视频转换器 avi转mp4

直接上代码package com.example.videoconverter;import ws.schild.jave.Encoder; import ws.schild.jave.EncoderException; import ws.schild.jave.MultimediaObject; import ws.schild.jave.encode.AudioAttributes; import ws.schild.jave.encode.EncodingAttributes; impor…

Kafka 与 RocketMQ 核心概念与架构对比

Kafka 与 RocketMQ 核心概念与架构对比DeepSeek生成&#xff0c;便于记忆大概逻辑核心概念对比图 #mermaid-svg-dEbo1XpAjfzOjvUW {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-dEbo1XpAjfzOjvUW .error-icon{fill…

30分钟深度压测cuBLAS:从FP64到INT8全精度性能剖析

在深度学习和高性能计算领域&#xff0c;GPU的矩阵运算性能是衡量系统算力的核心指标之一。NVIDIA的cuBLAS库作为CUDA平台上最基础的线性代数计算库&#xff0c;其性能表现直接影响着上层应用的运行效率。本文将详细介绍如何使用cublasmatmulbench工具对多GPU进行全面的性能基准…

超越模仿:探寻智能的本源

引言&#xff1a;超越模仿&#xff0c;探寻智能的本源近年来&#xff0c;以大语言模型&#xff08;LLM&#xff09;为代表的自然语言处理&#xff08;NLP&#xff09;技术&#xff0c;在模仿人类语言生成方面取得了令人瞩目的成就。从流畅的对话到精炼的文本摘要&#xff0c;机…

ROS/ROS2课程笔记00-大纲-25-26-1

大纲 AI版 以下是基于第四代高校课程核心理念设计的《ROS2机器人程序设计&#xff08;ROS2 Jazzy版&#xff09;》课程大纲&#xff0c;突出智能互联、跨学科融合、终身学习等特征&#xff0c;并融入技术赋能、生态重塑、素养导向等要求&#xff1a; 课程名称&#xff1a;ROS…

Linux内核进程管理子系统有什么第四十六回 —— 进程主结构详解(42)

接前一篇文章&#xff1a;Linux内核进程管理子系统有什么第四十五回 —— 进程主结构详解&#xff08;41&#xff09; 本文内容参考&#xff1a; Linux内核进程管理专题报告_linux rseq-CSDN博客 《趣谈Linux操作系统 核心原理篇&#xff1a;第三部分 进程管理》—— 刘超 《…

Linux网络连接不上?NetworkManager提示“device not managed“!

#操作系统 #Linux #NetworkManager适用环境kylin v10Centos 8Redhat 8一、故障现象在CentOS/RHEL(同样适用于kylin v10&#xff09;系统中&#xff0c;管理员执行 nmcli connection up ens160 命令尝试激活名为 ens160 的网络连接时&#xff0c;遇到以下错误&#xff1a;[roo…

【系统分析师】第2章-基础知识:数学与工程基础(核心总结)

更多内容请见: 备考系统分析师-专栏介绍和目录 文章目录 一、数学统计基础 1.1 概率论基础 1.2 数理统计基础 1.3 常用统计分析方法 二、图论应用 2.1 基本概念 2.2 核心算法与应用 三、预测与决策 3.1 预测方法 3.2 决策方法 四、数学建模 4.1 建模过程 4.2 常用模型类型 五、…

StrUtil.isBlank()

这段代码是一个条件判断&#xff0c;用于检查变量 shopJson 是否为空或空白&#xff0c;如果是&#xff0c;就直接返回 null。我们来逐句讲解&#xff1a;原始代码&#xff1a; if(StrUtil.isBlank(shopJson)) {// 3.存在&#xff0c;直接返回return null; }逐句解释&#xff1…

mysql 回表查询(二次查询,如何检查,如何规避)

h5打开以查看 “回表查询”通常发生在使用二级索引&#xff08;Secondary Index&#xff09;的查询中。当查询所需的数据列并不全部包含在二级索引中时&#xff0c;即使使用了索引&#xff0c;MySQL 也需要根据索引记录中的主键值&#xff0c;回到聚簇索引&#xff08;Cluster…

深度学习(二):神经元与神经网络

在人工智能的浪潮中&#xff0c;神经网络&#xff08;Neural Networks&#xff09;无疑是驱动核心技术的引擎&#xff0c;它赋予了计算机前所未有的学习和识别能力。而这一切的起点&#xff0c;是受到生物大脑中基本单元——神经元&#xff08;Neurons&#xff09;的深刻启发。…

JavaScript 行为型设计模式详解

1. 观察者模式1.1. 使用场景观察者模式用于对象间的一对多依赖关系&#xff0c;当一个对象的状态发生变化时&#xff0c;所有依赖于它的对象都能收到通知并自动更新。常用于事件处理、通知系统。在前端中&#xff0c;观察者模式用于实现事件监听、数据绑定等功能。1.2. 代码实现…

指令查找表LUT

本文整理自22. FlexSPI—读写外部SPI NorFlash — [野火]i.MX RT库开发实战指南——基于i.MXRT1052 文档 用作个人学习和分享 指令查找表LUT 访问FLASH存储器通常包含一些读写功能的的控制指令&#xff0c;主控设备可通过这些指令访问FLASH存储器。 为了适应这种需求&#…