随笔分类 -  算法基础—构造性算法

摘要:题目大意是给定一棵树,每次选择两个叶子将其删除,同时将两个叶子之间的简单路径长度加到答案上,找到一种方案使答案最大化,并输出删除的顺序。 首先有一个结论是,距离树上某个节点最远的节点一定是某条直径的某个端点。 证明:反证法。设树上某条直径左端点为L,右端点为R,距离当前节点x最远的点为P。如果x就在 阅读全文
posted @ 2022-11-14 17:01 脂环 阅读(41) 评论(0) 推荐(0) 编辑
摘要:A. Reverse and Concatenate 如果k为0直接输出1,否则如果s为回文串的话输出1,其他情况输出2(经过一次变换后必然为回文)。注意不能特判k = 1的情况,用这个样例hack了一发23333 #include <bits/stdc++.h> #define pii pair< 阅读全文
posted @ 2022-02-07 01:26 脂环 阅读(133) 评论(0) 推荐(0) 编辑
摘要:After the last network breakdown, you've been assigned to redesign the signal transmission network of ICPC (Internet Clogging Prevention Corporation)! 阅读全文
posted @ 2021-11-08 09:41 脂环 阅读(255) 评论(0) 推荐(0) 编辑
摘要:链接:https://ac.nowcoder.com/acm/contest/11255/C 来源:牛客网 题目描述 Let LCS(s1,s2)LCS(s1,s2) denote the length of the longest common subsequence (not necessary 阅读全文
posted @ 2021-07-26 18:41 脂环 阅读(94) 评论(0) 推荐(0) 编辑
摘要:链接:https://ac.nowcoder.com/acm/contest/11176/B 来源:牛客网 题目描述 A + B ProblemA + B Problem 往往是大家在各Online JudgeOnline Judge通过的第一道题目,刚刚学会写程序的嘟嘟也不例外。然而,单纯的读入两 阅读全文
posted @ 2021-07-10 11:41 脂环 阅读(102) 评论(0) 推荐(0) 编辑
摘要:随便VP了一下大概是四题的样子 B. Build Roads 链接:https://ac.nowcoder.com/acm/contest/15600/B 来源:牛客网 题目描述 In the cat country, there are nnn cities. The cat country ki 阅读全文
posted @ 2021-05-13 19:54 脂环 阅读(327) 评论(0) 推荐(0) 编辑
摘要:We will consider the numbers 𝑎a and 𝑏b as adjacent if they differ by exactly one, that is, |𝑎−𝑏|=1|a−b|=1. We will consider cells of a square matr 阅读全文
posted @ 2021-05-06 19:06 脂环 阅读(123) 评论(0) 推荐(0) 编辑
摘要:链接:https://ac.nowcoder.com/acm/contest/15590/L 来源:牛客网 题目描述 输入描述: 输出描述: 示例1 输入 复制 7 4 2 6 1 5 7 3 输出 复制 337 34 3401 7 780 7803 79 示例2 输入 复制 4 4 1 3 2 输 阅读全文
posted @ 2021-05-02 21:32 脂环 阅读(85) 评论(0) 推荐(0) 编辑
摘要:You are given three integers a, 𝑏b and c. Find two positive integers x and y (x>0, y>0) such that: the decimal representation of x without leading ze 阅读全文
posted @ 2021-04-14 14:27 脂环 阅读(132) 评论(0) 推荐(0) 编辑
摘要:Let's define the cost of a string 𝑠s as the number of index pairs i and j (1≤i<j<|s|) such that si=sj and si+1=sj+1. You are given two positive integ 阅读全文
posted @ 2021-04-14 09:18 脂环 阅读(98) 评论(0) 推荐(0) 编辑
摘要:Codeforces Round #712 (Div. 2) A. Déjà Vu 暴力瞎搞即可,只有全a是不满足的,否则挑选a更多的一端加上a,当然也可以分别加a进行判断。 #include <bits/stdc++.h> using namespace std; int main() { int 阅读全文
posted @ 2021-04-06 23:47 脂环 阅读(73) 评论(0) 推荐(1) 编辑
摘要:链接:https://ac.nowcoder.com/acm/contest/12548/J 来源:牛客网 题目描述 As a master of parallel computing, schwer is recently considering about the method to achie 阅读全文
posted @ 2021-04-06 12:01 脂环 阅读(336) 评论(0) 推荐(0) 编辑
摘要:https://ac.nowcoder.com/acm/contest/9981#question A. 串 考虑先搞出来一个串然后逐渐添加。设dp[i]为长度为i的含有us子串的串的个数,则当dp[i - 1]已经求出来的情况下,第i个位置: 前面已经有us,第i个位置随便添加 dp[i] += 阅读全文
posted @ 2021-02-07 23:44 脂环 阅读(108) 评论(0) 推荐(0) 编辑
摘要:You are given an array [𝑎1,𝑎2,…,𝑎𝑛][a1,a2,…,an] such that 1≤𝑎𝑖≤1091≤ai≤109. Let 𝑆S be the sum of all elements of the array 𝑎a. Let's call an a 阅读全文
posted @ 2020-12-18 08:49 脂环 阅读(258) 评论(1) 推荐(0) 编辑
摘要:Problem Description S is a string of length n. S consists of lowercase English alphabets. Your task is to count the number of different S with the min 阅读全文
posted @ 2020-07-21 18:54 脂环 阅读(434) 评论(0) 推荐(0) 编辑
摘要:You have been blessed as a child of Omkar. To express your gratitude, please solve this problem for Omkar! An array aa of length nn is called complete 阅读全文
posted @ 2020-07-12 22:01 脂环 阅读(336) 评论(0) 推荐(0) 编辑
摘要:Shubham has a binary string ss. A binary string is a string containing only characters "0" and "1". He can perform the following operation on the stri 阅读全文
posted @ 2020-06-01 10:48 脂环 阅读(502) 评论(0) 推荐(0) 编辑
摘要:You are given an undirected graph without self-loops or multiple edges which consists of nn vertices and mm edges. Also you are given three integers n 阅读全文
posted @ 2020-05-18 23:59 脂环 阅读(249) 评论(0) 推荐(0) 编辑
摘要:Petya and Vasya are competing with each other in a new interesting game as they always do. At the beginning of the game Petya has to come up with an a 阅读全文
posted @ 2020-05-16 23:22 脂环 阅读(314) 评论(0) 推荐(1) 编辑
摘要:A. Sum of Round Numbers 把一个数拆成几个整十/百/千...的数的和。 #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int i,num,ans=0; 阅读全文
posted @ 2020-05-11 10:33 脂环 阅读(190) 评论(0) 推荐(1) 编辑

点击右上角即可分享
微信分享提示
主题色彩