题意:给定k个长度为n的字符串,每个字符串有一个魅力值ai,在k个字符串中选取字符串组成回文串,使得组成的回文串魅力值最大. 分析: 1.若某字符串不是回文串a,但有与之对称的串b,将串a和串b所有的魅力值分别从大到小排序后,若两者之和大于0,则可以放在回文串的两边. 2.若某字符串是回文串,将其魅力值从大到小排序后,两两依次分析:(mid---可能放在回文串中间的串的最大魅力值) (1)若两个数都是正的,那么就将其放在两边,并将结果计入ans.(ans---回文串两边的串的魅力值之和) (2)…
雅礼集训期间我好像考完试就开始划水了啊 给出k个长度相同的字符串,每个串有一个权值,选出一些串连成一个回文串.使得选中的串的总权值最大. 如果选一个串,必须同时选一个对称的串.还有一个特殊情况是可以在最中间放一个回文的串,求一下这种情况带来的额外的收入即可. 卡自然溢出hash....需要树同构那种奇奇怪怪的hash... #include <cstdio> #include <string> #include <iostream> #include <algor…
D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus likes palindromes very much. There was his birthday recently. k of his friends came to him to co…
Santa Claus and a Palindrome 题目链接:http://codeforces.com/contest/752/problem/D 贪心 很自然地,可以想到,若subS不是回文串,那么只要贪心取subS中的最大值和reverse_subS中的最大值,若他们和大于零,则加入到结果回文序列中:而当subS本身就为回文串时,需要分类讨论(可以放在结果回文序列的最中间): 为了方便理解,定义: 若subS中的最大值与次大值的和小于零(或subS中只有一个值),那么称该最大值(或该…
Santa Claus and a Palindrome Time Limit: 20 Sec  Memory Limit: 512 MB Description 有k个串,串长都是n,每个串有一个ai的贡献. 选出若干个串,若它们可以通过任意组合,形成一个回文串,则可以获得它们的贡献之和. 求最大贡献. Input 第一行两个整数k,n. 之后k行,每行分别是一个串si,与贡献ai. Output 一个整数表示答案. Sample Input 7 3 abb 2 aaa -3 bba -1 z…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus likes palindromes very much. There was his birthday recently. k of his friends came to him to congratulate him, and each of them…
题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus has Robot which lives on the infinite grid and can move along its lines. He…
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus has n tangerines, and the i-th of them consists of exactly ai slices. Santa Claus came to a school…
题面: 传送门 B. Santa Claus and Keyboard Check Input file: standard input Output file: standard output Time limit: 2 second Memory limit: 256 megabytes   Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he su…
题目链接:http://codeforces.com/contest/752/problem/D 题意:给长度为k的n个字符串,每一个字符串有权值,求构造一个大回文串.使得权值最大. 因为字符串长度都一样,所以想构成回文串,必须两两配对,在中间加或者不加一个本身就是回文的字符串. 1.考虑非回文串的配对,把所有可以构成回文的非回文串凑起来,必须两两权值和>0才有意义.那么就扔到优先队列里配对. 2.考虑回文串的配对,配对成功的话要看下是不是两个回文串都是>0,如果不是,要额外在一个vector…
题意:给定一个机器人的行走路线,求最少的点能使得机器人可以走这样的路线. 析:每次行走,记录一个方向向量,每次只有是相反方向时,才会增加一个点,最后再加上最后一个点即可. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #…
原来set,priority_queue也可以映射..涨姿势2333 比较麻烦的应该就是判断自身回文的串是选2个还是选一个吧. #include<bits/stdc++.h> #define INF 0x7fffffff #define LL long long #define N 100005 #define pill pair<int ,int > using namespace std; inline int ra() { ,f=; char ch=getchar(); ;…
题意:将n个蛋糕分给k个人,要保证每个人都有蛋糕或蛋糕块,蛋糕可切, 1.若蛋糕值为偶数,那一次可切成对等的两块. 2.若蛋糕值为奇数,则切成的两块蛋糕其中一个比另一个蛋糕值多1. 3.若蛋糕值为1,则不可切. 问每个人拥有的蛋糕中最小蛋糕值可能的最大值是多少. 分析: 1.若每个蛋糕都分成蛋糕值为1,即n个蛋糕的蛋糕值总和<k,则输出-1. 2.验证mid是否成立,若某蛋糕值x大于mid,则可切,并将该蛋糕可切成的块数保存在vis[x]中. 3.若mid为5,而x为11,则有必要切蛋糕x,若x…
题意:机器人在网格线上行走,从p1点开始,沿最短路径到p2,再沿最短路径到p3,依此类推.在此过程中留下了行走的运动轨迹,由“RLDU”表示.问若只给出运动轨迹,求最少的pi点的个数. 分析:pi到pi+1是沿最短路径走的,因此在此路径中不可能同时出现“UD”两个方向(“LR”同理).因此只要同时出现,那一定证明此刻已往下一个目标点走. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio&g…
题意:给定两个字符串a和b,问有多少种不同的字母组合对,使得将这些字母对替换字符串b后,可以变成字符串a.注意字母对彼此各不相同. 分析:vis[u]记录与u可形成关系的字母,若u与v不同,则形成字母对.若之后该关系被打破,则输出-1. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio> #include<cstring> #include<cstdlib>…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus has n tangerines, and the i-th of them consists of exactly ai slices. Santa Claus came to a school which has k pupils. Santa dec…
题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ Author :Running_Time Created Time :2015-8-3 9:14:02 File Name :B.cpp *************************************************/ #include <cstdio> #include &…
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus has n tangerines, and the i-th of them consists of exactly ai slices. Santa Claus came to a school…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of m pointsp1, p2, ..., …
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of ke…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom t…
Santa Claus and Tangerines 题目链接:http://codeforces.com/contest/752/problem/E 二分 显然直接求答案并不是很容易,于是我们将其转化为判定性问题:二分解x,验证是否能分成k个x. 于是要点就在于check函数: 由于奇偶的原因,每个ai分出来的并不是2的幂次(比如当ai=11,x=3时,可以将ai分成3部分5,3,3). 但是稍作思考,可以发现还是与2的幂次有关: 例如,当ai=6:48,x=3时, ai part1 part…
C. Santa Claus and Robot time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence…
/* Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are n lanes of m desks each, and there are two working places at each of the desks. The lanes are numb…
题目: In your childhood you most likely had to solve the riddle of the house of Santa Claus. Do you remember that the importance was on drawing the house in a stretch without lifting the pencil and not drawing a line twice? As a reminder it has to look…
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus has n tangerines, and the i-th of them consists of exactly ai slices. Santa Claus came to a school…
本博客将会收录一些贪心/构造的我认为较有价值的题目,这样可以有效的避免日后碰到 P7115 或者 P7915 这样的题就束手无策进而垫底的情况/dk 某些题目虽然跟贪心关系不大,但是在 CF 上有个 greedy 的 tag,这种题目大概率也会被我收录进来(比方说这篇博客里大概率会收录不少 DP 题,因为 CF 上不少 DP 题都莫名其妙地打上了一个 greedy 的 tag 1. CF1592F1 Alice and Recoloring 1 首先很明显我们不会选择翻转包含 \((1,m),(…
由于换了台电脑,而我的贪心 & 构造能力依然很拉跨,所以决定再开一个坑( 前传: 贪心/构造/DP 杂题选做 u1s1 我预感还有Ⅲ(欸,这不是我在多项式Ⅱ中说过的原话吗) 24. P5912 [POI2004]JAS 一开始直接莽了个点分治,当我测过了样例美滋滋地一交,发现自己获得了 20 分的好成绩之后,才发现事情有那么亿点点不对劲( 不难发现,题目等价于求高度最小的点分树的高度,直接求有点困难,我们不妨来对其进行一些转化:我们考虑给每个点一个标号,那么问题可以转化为,求使得任意两个标号相同…
颓!颓!颓!(bushi 前传: 贪心/构造/DP 杂题选做 贪心/构造/DP 杂题选做Ⅱ 51. CF758E Broken Tree 讲个笑话,这道题是 11.3 模拟赛的 T2,模拟赛里那道题的名字叫猛张(orz ztr),而我刚好在 11.4 把这题 A 了.乍一看好像也没啥问题,不过模拟赛时间是 2020.11.3,而我 AC 这道题的时间是 2021.11.4((( 首先看到这样的题我们肯定会想到贪心,具体来说我们 DFS 一遍整棵树,DFS 到一个节点 \(x\) 时,我们考虑用最…
C. Make Palindrome Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/problem/C Description A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo&q…