Codeforces Round 1043 (Div.3)

比賽連接:Codeforces Round 1043 (Div.3)

A. Homework

題目鏈接:A - Homework
Vlad and Dima have been assigned a task in school for their English class. They were given two strings aaa and bbb and asked to append all characters from bbb to string aaa in any order. The guys decided to divide the work between themselves and, after lengthy negotiations, determined who would add each character from string bbb to aaa.

Due to his peculiarities, Vlad can only add characters to the beginning of the word, while Dima can only add them to the end. They add characters in the order they appear in string bbb. Your task is to determine what string Vlad and Dima will end up with.
Input

Each test consists of several test cases. The first line contains a single integer ttt (1≤t≤10001 \le t \le 10001t1000) — the number of test cases. The description of the test cases follows.

The first line contains an integer nnn (1≤n≤101 \le n \le 101n10) — the length of the string aaa.

The second line contains the string aaa, consisting of lowercase letters of the English alphabet.

The third line contains an integer mmm (1≤m≤101 \le m \le 101m10) — the length of the strings bbb and ccc.

The fourth line contains the string bbb, consisting of lowercase letters of the English alphabet.

The fifth line contains the string ccc, consisting of the characters ‘V’ and ‘D’ — the distribution of the characters of string bbb between Dima and Vlad. If cic_ici? = ‘V’, then the iii-th letter is added by Vlad; otherwise, it is added by Dima.
Output

For each test case, output the string that will result from Dima and Vlad’s work.
這是一道很簡單的模擬題,按照題意進行模擬即可。

// Problem: A. Homework
// Contest: Codeforces - Codeforces Round 1043 (Div. 3)
// URL: https://codeforces.com/contest/2132/problem/0
// 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
const int inf = 0x3f3f3f3f;void solve()
{int n;cin>>n;string s;cin>>s;int m;cin>>m;string t;cin>>t;string op;cin>>op;string ans = s;for(int i=0;i<op.size();i++){if(op[i] == 'D'){ans += t[i];}else{string tt;tt += t[i];ans = tt + ans;}}cout<<ans<<endl;
//	cout<<fixed<<setprecision(x)<< ; 
}signed main()// Don't forget pre_handle!
{IOSint T=1;cin>>T;while(T--) solve(); return 0;
} 

B. The Secret Number

題目鏈接:B. The Secret Number
Vadim has thought of a number xxx. To ensure that no one can guess it, he appended a positive number of zeros to the right of it, thus obtaining a new number yyy. However, as a precaution, Vadim decided to spread the number n=x+yn = x + yn=x+y. Find all suitable xxx that Vadim could have thought of for the given nnn.
Input

Each test consists of several test cases. The first line contains a single integer ttt (1≤t≤104)(1 \le t \le 10^4)(1t104) — the number of test cases. The following lines describe the test cases.

In a single line of each test case, there is an integer nnn — the number spread by Vadim (11≤n≤1018)(11 \le n \le 10^{18})(11n1018).
Output

For each number nnn, output 000 if there are no suitable xxx. Otherwise, output the number of suitable xxx, followed by all suitable xxx in ascending order.

已知 n = x + y,其中 y 是 x 右邊添加若干個 0 得到的數。假設 x 是 k 位數,在 x 右邊添加 m 個 0 后,y = x * 10^m 。那么 n = x + x * 10^m = x * (1 + 10^m) ,所以 x = n / (1 + 10^m),需要滿足 x 是整數,并且 y = x * 10^m 是 x 右邊添加 m 個 0 得到的(即 x 和 y 的數字組成符合要求 )。

所以我們只需要暴力地求出來所有的可能的數即可。

#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
const int inf = 0x3f3f3f3f;void solve()
{int n;cin>>n;vector<int> ans;int k = 10;for(int i=1;i<=18;i++){int x = 1LL + k;if(x > n) break;if(n % x == 0){int y = n / x;string t = to_string(y);string tt = t + string(i,'0');if(to_string(y * k) == tt) ans.push_back(y);}if(k * 10 > n) break;k *= 10;}if(ans.size() == 0){cout<<0<<endl;return ;}sort(ans.begin(),ans.end());cout<<ans.size()<<endl;for(auto &i : ans) cout<<i<<' ';cout<<endl;
//	cout<<fixed<<setprecision(x)<< ; 
}signed main()// Don't forget pre_handle!
{IOSint T=1;cin>>T;while(T--) solve(); return 0;
}

C1. The Cunning Seller (easy version)

題目鏈接:C1. The Cunning Seller (easy version)
這道題依舊是暴力,從大到小一直遍歷就行了(感覺比B題還水)

// Problem: C1. The Cunning Seller (easy version)
// Contest: Codeforces - Codeforces Round 1043 (Div. 3)
// URL: https://codeforces.com/contest/2132/problem/C1
// 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
const int inf = 0x3f3f3f3f;void solve()
{int n;cin>>n;int ans = 0;for(int i=18;i>=0;i--){int k = pow(3LL,i+1LL) + i * pow(3LL,i-1);int num = pow(3,i);if(num > n) continue;int cnt = n / num;n -= cnt * num;ans += k * cnt;}// cout<<"n = "<<n<<endl;cout<<ans<<endl;
//	cout<<fixed<<setprecision(x)<< ; 
}signed main()// Don't forget pre_handle!
{IOSint T=1;cin>>T;while(T--) solve(); return 0;
} 

C2. The Cunning Seller (hard version)

題目鏈接:C2. The Cunning Seller (hard version)
首先還是用C1的思路求出最少需要的交易次數,然后看能不能用交易次數來換交易金幣數(貪心的思想),通過列式子就能發現貪心的思路:詳解見代碼:

// Problem: C2. The Cunning Seller (hard version)
// Contest: Codeforces - Codeforces Round 1043 (Div. 3)
// URL: https://codeforces.com/contest/2132/problem/C2
// 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; 
const int N = 20;
int n,k;void solve()
{cin>>n>>k;int ans = 0;vector<int> cs(N,0);for(int i=19;i>=0;i--){int num = pow(3,i);if(num > n) continue;int cnt = n / num;n -= cnt * num;ans += cnt;cs[i] = cnt;//用cs數組存當前的i所需要的交易次數}if(ans > k)//如果最少的操作次數都達不到的話就是-1啦{cout<<"-1"<<endl;return ;}k -= ans;//計算還能“浪費多少次數來使得花費更小”for(int i=19;i>=1;i--){if(k < 2) break;//因為是三進制 所以我們可以用一次高位交易抵三次的低位交易 所以每一次的貪心操作都能“浪費2次交易”int x = k / 2;int y = cs[i];//k小于2了就貪心不了了,所以就要退出int mi = min(x,y);cs[i] -= mi;cs[i-1] += 3 * mi;//每一次貪心就相當于是低位上多了三次交易k -= 2 * mi;//浪費了2 * mi次交易}/*想一下為什么這樣就貪心了?首先對于x來說:我們所需要花費的金幣數是:3^(x+1) + x*3^(x-1)對于更高位來說:我們所需要的金幣數是:3^(x+2) + (x+1)*(3^x)我們知道對于三進制來說,一次高位操作等于3個低位操作(高位 = 低位 * 3)那么我們計算3次低位所需要花費的金幣數:3 * (3^(x+1) + x*3^(x-1))即:3^(x+2) + x * 3^x我們與之和高位所需要花費的金幣數來進行比較,是不是少了3^x?這就是貪心的過程:浪費交易次數使得高位的交易盡量少 盡量轉移到低位上去*/int res = 0;for(int i=0;i<=19;i++){int t = pow(3, i+1) + i * pow(3, i-1);res += t * cs[i];}cout<<res<<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/web/94129.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/94129.shtml
英文地址,請注明出處:http://en.pswp.cn/web/94129.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

GPS欺騙式干擾的產生

我們在GNSS抗干擾天線的選型、測試方法以及為什么不能做RTK&#xff1f;&#xff08;抗干擾內容全集&#xff09;中提到的抗干擾天線&#xff0c;針對的是GPS壓制式干擾。對于GPS欺騙式干擾&#xff0c;抗干擾天線是無能為力的。 簡單來說&#xff0c;壓制式干擾是通過發射強功…

[PV]AXI R/W/RW帶寬計算的tcl腳本

AXI R/W/RW帶寬計算的tcl腳本 我基于前述的axi_read_bw_per_id.tcl腳本進行了修改,使其支持: 讀通道(Read Channel):計算基于rvalid && rready的有效周期(已在前述實現)。 寫通道(Write Channel):計算基于wvalid && wready的有效周期,考慮wstrb的ac…

阿里云AnalyticDB同步數據至華為云taurusdb

1 概述 AnalyticDB和taurusdb都是高度兼容mysql協議的數據庫&#xff0c;從現有的AnalyticDB官方數據同步方案來看&#xff0c;只有FlinkSQL合適。 同步方案官方文檔&#xff1a; https://help.aliyun.com/zh/analyticdb/analyticdb-for-mysql/user-guide/flink-subscribes-b…

學習嵌入式之驅動——系統移植(二)

一、uboot常用命令與環境變量1.命令&#xff1a;&#xff08;1&#xff09;環境變量操作命令命令功能格式printenv 查看環境變量printenvsetenv新建/修改環境變量setenv 環境變量名 環境變量值saveenv保存環境變量saveenv&#xff08;2&#xff09;內存操作命令命令功能格式示例…

EasyExcel 合并單元格最佳實踐:基于注解的自動合并與樣式控制

EasyExcel 合并單元格最佳實踐&#xff1a;基于注解的自動合并與樣式控制 前言 在日常開發中&#xff0c;我們經常需要導出 Excel 報表&#xff0c;而合并單元格是提升報表可讀性的常見需求。本文將介紹如何基于 EasyExcel 實現智能的單元格合并功能&#xff0c;通過自定義注解…

Unity設置UI顯示區域

系列文章目錄 untiy工具 文章目錄 系列文章目錄 ??前言 ??一、效果圖 ??二、制作過程(檢測中心點位置) ??2-1、代碼實現 ??三、優化為檢測整個UI四個角點 ??四、性能優化建議 ??壁紙分享 ??總結 ??前言 思路: 獲取屏幕的寬度和高度,定義中間區域的范圍…

Qt中用于圖像縮放的核??法QPixmap::scaled

QPixmap::scaled是Qt中用于圖像縮放的核??法&#xff0c;其作?和?法如下&#xff1a;?一、核心作用??圖像尺寸調整?根據指定尺寸對圖像進?等?例或?等?例縮放&#xff0c;?持放?和縮?操作。?保持寬高比?通過AspectRatioMode參數控制是否保持原始圖像的寬??。…

SQL Workbench/J:一款免費開源、跨平臺的通用SQL查詢工具

SQL Workbench/J 是一款基于 Java 開發的免費開源、跨平臺的通用 SQL 查詢工具。 SQL Workbench/J 主要專注于 SQL 腳本開發和數據導入導出功能&#xff0c;不提供各種數據庫管理功能。 功能特性 跨平臺&#xff1a;可以在任何安裝了 Java 運行時環境的操作系統上運行&#xf…

DOLO 上漲:Berachain 生態爆發的前奏?

在 Berachain 生態逐漸進入公眾視野之際&#xff0c;Dolomite&#xff08;簡稱 Dolomite&#xff0c;代幣 DOLO&#xff09;成為鏈上表現最為突出的明星協議。其代幣價格在短短兩個月內&#xff0c;從 $0.03 飆升至 $0.3&#xff0c;漲幅接近 10 倍。市場不僅將其視作 Berachai…

吉利汽車與芯鼎微成立聯合創新實驗室共譜車規級LCoS顯示新篇章

2025年8月20日&#xff0c;吉利汽車研究院技術規劃中心副主任李莉、光學實驗室負責人李金樺博士等一行四人蒞臨芯鼎微&#xff0c;雙方共同為"吉利汽車-芯鼎微聯合創新實驗室"揭牌&#xff0c;標志著兩家企業在車載先進顯示技術領域邁入深度協同創新的新階段。 在這汽…

NPM組件 @angular_devkit/core 等竊取主機敏感信息

【高危】NPM組件 angular_devkit/core 等竊取主機敏感信息 漏洞描述 當用戶安裝受影響版本的 angular_devkit/core 等NPM組件包時會竊取用戶的主機名、用戶名、IP地址信息并發送到攻擊者可控的服務器地址。 MPS編號MPS-1jf5-s6ix處置建議強烈建議修復發現時間2025-08-14投毒…

docker cuda版安裝 dockercuda版安裝

目錄 1.一鍵安裝docker 測試ok 2.安裝cuda支持 通用的應該沒問題 安裝工具包 配置 runtime&#xff1a; 3.檢查 Docker 是否支持 NVIDIA 運行時 1.一鍵安裝docker 測試ok curl -fsSL https://get.docker.com | sh 2.安裝cuda支持 通用的應該沒問題 也可以搜索安裝 cuda版d…

Spring發布訂閱模式詳解

Spring 的發布訂閱模式&#xff08;Publish-Subscribe Pattern&#xff09;是一種基于事件驅動的設計模式&#xff0c;通過 "事件" 作為中間載體實現組件間的解耦。在這種模式中&#xff0c;"發布者"&#xff08;Publisher&#xff09;負責產生事件并發布&…

服務器硬件中的磁盤SSD與HDD性能區別,以及分別適用于什么業務?

SSD&#xff08;固態硬盤&#xff09;和 HDD&#xff08;機械硬盤&#xff09;是服務器中常見的存儲設備類型&#xff0c;兩者在性能、可靠性、成本等方面存在顯著差異。根據這些特性&#xff0c;它們適用于不同的業務需求。以下是詳細的對比與應用場景分析&#xff1a;1. SSD …

AI驅動的SEO關鍵詞優化秘籍

內容概要人工智能技術的飛速發展正重塑SEO關鍵詞優化領域&#xff0c;為從業者帶來全新機遇與挑戰。本文將系統解析AI如何革新關鍵詞策略&#xff0c;覆蓋從語義搜索深度解析到長尾詞智能挖掘的核心環節。通過工具驅動的內容優化路徑&#xff0c;讀者將掌握提升流量轉化率的關鍵…

自然語言處理(NLP)技術的發展歷史

自然語言處理&#xff08;NLP&#xff09;作為人工智能的重要分支&#xff0c;其發展歷程跨越了大半個世紀&#xff0c;從早期的規則式嘗試到如今的大模型時代&#xff0c;技術路徑不斷迭代&#xff0c;核心目標始終是實現人機間的自然語言交互。以下從關鍵階段、技術突破和標志…

Swift 解法詳解 LeetCode 361:轟炸敵人,用動態規劃輕松拿下

文章目錄摘要描述題解答案題解代碼分析代碼解析示例測試及結果時間復雜度空間復雜度總結摘要 “轟炸敵人”這道題名字聽起來就很帶感&#xff0c;它其實是一個二維網格搜索問題。我們要找到一個能放置炸彈的位置&#xff0c;讓炸掉的敵人最多。雖然題目看起來復雜&#xff0c;…

如何高效推進將科技創新成果轉化為標準?

2024年10月26日&#xff0c;全國標準信息公共服務平臺正式發布了國家標準《科技成果評估規范》&#xff08;GB/T 44731-2024 &#xff09;&#xff0c;并從發布之日起正式實施。這一標準的正式推出&#xff0c;標志著政府在推進科技成果轉化、提升科技服務能力方面邁出了重要一…

CMake 快速開始

CMake 快速開始 CMake 安裝 編輯環境&#xff1a;VS Code 編譯環境&#xff1a;VS Code Remote SSH模式 Ubuntu 24.04 CMake 官?源代碼下載地址&#xff1a;https://cmake.org/download/ CMake 官?英? 檔地址&#xff1a;https://cmake.org/cmake/help/latest/index.html S…

STM32F1 EXTI介紹及應用

第三章 EXTI介紹及應用 1. EXTI介紹 EXTI&#xff08;External interrupt/event controller&#xff09;—外部中斷/事件控制器&#xff0c;管理了控制器的 20 個中斷/事件線。每個中斷/事件線都對應有一個邊沿檢測器&#xff0c;可以實現輸入信號的上升沿檢測和下降沿的檢測。…