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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈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;可以实现输入信号的上升沿检测和下降沿的检测。…