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+13?x+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=41?3+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^52n2?105).

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

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^52?105.
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-1?1 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,ba?b1018).
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^51n2?105).

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

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

For each test case, output ?1-1?1 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 n1ai?n.
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
英文地址,請注明出處:http://en.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存儲器。 為了適應這種需求&#…