| |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
-> 数据结构与算法 -> Codeforces Round #787 (Div. 3)补题 -> 正文阅读 |
|
[数据结构与算法]Codeforces Round #787 (Div. 3)补题 |
官网链接E. Replace With the Previous, MinimizeYou are given a string s of lowercase Latin letters. The following operation can be used: select one character (from ‘a’ to ‘z’) that occurs at least once in the string. And replace all such characters in the string with the previous one in alphabetical order on the loop. For example, replace all ‘c’ with ‘b’ or replace all ‘a’ with ‘z’. The string a=a1a2…an is lexicographically smaller than the string b=b1b2…bn if there exists an index k (1 ≤ k ≤ n) such that a1 = b1, a2 = b2, …, ak?1 = bk?1, but ak < bk. Input This is followed by descriptions of the test cases. The first line of each test case contains two integers n and k (1 ≤ n ≤ 2?105, 1 ≤ k ≤ 109) — the size of the string s and the maximum number of operations that can be performed on the string s. The second line of each test case contains a string s of length n consisting of lowercase Latin letters. It is guaranteed that the sum n over all test cases does not exceed 2?105. Output Example
F. Vlad and Unfinished BusinessVlad and Nastya live in a city consisting of n houses and n?1 road. From each house, you can get to the other by moving only along the roads. That is, the city is a tree. Vlad lives in a house with index x, and Nastya lives in a house with index y. Vlad decided to visit Nastya. However, he remembered that he had postponed for later k things that he has to do before coming to Nastya. To do the i-th thing, he needs to come to the ai-th house, things can be done in any order. In 1 minute, he can walk from one house to another if they are connected by a road. Vlad does not really like walking, so he is interested what is the minimum number of minutes he has to spend on the road to do all things and then come to Nastya. Houses a1,a2,…,ak he can visit in any order. He can visit any house multiple times (if he wants). Input The first line of each test case contains two integers n and k (1 ≤ k ≤ n ≤ 2?105) — the number of houses and things, respectively. The second line of each test case contains two integers x and y (1 ≤x,y ≤ n) — indices of the houses where Vlad and Nastya live, respectively. The third line of each test case contains k integers a1,a2,…,ak (1 ≤ ai ≤ n) — indices of houses Vlad need to come to do things. The following n?1 lines contain description of city, each line contains two integers vj and uj (1 ≤ uj,vj ≤ n) — indices of houses connected by road j. It is guaranteed that the sum of n for all cases does not exceed 2?105. Output 3 1 6 4 6 2
G. Sorting PancakesNastya baked m pancakes and spread them on n dishes. The dishes are in a row and numbered from left to right. She put ai pancakes on the dish with the index i. Seeing the dishes, Vlad decided to bring order to the stacks and move some pancakes. In one move, he can shift one pancake from any dish to the closest one, that is, select the dish i (ai > 0) and do one of the following: if i > 1, put the pancake on a dish with the previous index, after this move ai=ai?1 and ai?1=ai?1+1; The array a=[a1,a2,…,an] is called non-increasing if ai ≥ ai+1 for all i from 1 to n?1. Input The second line contains n numbers ai (0 ≤ ai ≤ m), the sum of all ai is equal to m. Output Examples |
|
|
上一篇文章 下一篇文章 查看所有文章 |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 | -2024/11/26 3:51:37- |
|
网站联系: qq:121756557 email:121756557@qq.com IT数码 |