题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的反转就不超时了:) */ #include <cstdio> #include <algorithm> #include <cstring> using namespace std; ; const int INF = 0x3f3f3f3f; char s[MAXN]; i…
Codeforces Round #297 (Div. 2)B. Pasha and String Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  Solved: 2xx 题目连接 http://codeforces.com/contest/525/problem/B Description Pasha got a very beautiful string s for his birthday, the string consists o…
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  Solved: 2xx 题目连接 http://codeforces.com/contest/525/problem/A Description After a hard day Vitaly got very hungry and he wants to eat his favorite pot…
Codeforces Round #297 (Div. 2)E. Anya and Cubes Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx  Solved: 2xx 题目连接 http://codeforces.com/contest/525/problem/E Description Anya loves to fold and stick. Today she decided to do just that. Anya has n c…
Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx  Solved: 2xx 题目连接 http://codeforces.com/contest/525/problem/D Description Finally it is a day when Arthur has enough money for buying an apartment. H…
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  Solved: 2xx 题目连接 http://codeforces.com/contest/525/problem/C Description In the evening, after the contest Ilya was bored, and he really felt like ma…
题目传送门 /* 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 在2*2的方格里,若只有一个是'*',那么它一定要被替换掉 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <queue> using namespace std; ;…
题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long ll; ; const int INF = 0x3f3f3f3f; in…
题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> #include <iostream> #include <algorithm> #include <cstring> using namespace std; ; const int INF = 0x3f3f3f3f; ]; char s[MAXN]; int main(…
题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他选择的那个字符串分成了两个独立的字符串 现在问,先手是否必胜,如果先手必胜,输出第一步应该删掉第几个字符,有多解的话,输出序号最小的那个 字符串的长度不超过5000,只包含小写英文字母 做法分析 可以这样考虑:将所有的长度大于等于 3(其实只需要找长度为 3 的就行)的奇回文串的中心标记出来 我们将…
题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <string> using namespace std; ; const int INF = 0x3f3f3f3f; char s[MAXN]; bool check(int x, int y) { for…
题目传送门 /* 题意:给出一系列名字变化,问最后初始的名字变成了什么 字符串处理:每一次输入到之前的找相印的名字,若没有,则是初始的,pos[m] 数组记录初始位置 在每一次更新时都把初始pos加上去,那么就保证更新了初始的名字,这也是唯一要思考的地方了:) */ #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <cmath&…
题目链接:http://codeforces.com/contest/877/problem/B Nikita and string time limit per test2 seconds memory limit per test256 megabytes Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of t…
题目链接:https://codeforces.com/contest/1379/problem/A 题意 给出一个由 '?' 和小写字母组成的字符串,可以将 '?' 替换为小写字母,判断是否存在一种替换方案使得字符串只包含一个 'abacaba' 子串. 题解 首先计算原字符串中所求子串的个数: 如果个数多于一,则不存在满足要求的替换方案 如果个数等于一,将所有 '?' 替换为 'abc' 外的字母即可 如果个数少于一,判断是否有可以替换的子串,以及替换后是否只有一个子串,如 'abaca?a…
A题 题目大意: 给你一个字符串,奇数的时候是钥匙,偶数的时候是门,一把钥匙只能开对应的门,然后问你最少额外需要多少把钥匙. 分析: 用的数组记录一下就行,(注意的是先开门,再拿钥匙!开始错在这里了,决心好好学英语) #include<cstdio> #include<cstring> #include<iostream> #include<cmath> #include<algorithm> #include<queue> #inc…
http://codeforces.com/contest/525/problem/E 学习了传说中的折半DFS/双向DFS 先搜前一半数,记录结果,然后再搜后一半数,匹配之前结果. #include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<map> #define LL long long us…
传送门 D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Finally it is a day when Arthur has enough money for buying an apartment. He found a great option close to the cente…
传送门 E. Anya and Cubes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Anya loves to fold and stick. Today she decided to do just that. Anya has n cubes lying in a line and numbered from 1…
题意:有两个字符串\(S\)和\(T\),判断\(T\)是否能由\(S\)通过交换某位置的相邻字符得到,如果满足,输出交换次数及每次交换的位置,否则输出\(-1\). 题解:首先判断不满足的情况,只有当两个字符串中出现的字母次数不同时不满足条件,用桶判断一下即可.然后我们再来看有解的情况,我们对\(T\)的每个字符标上序号,如样例1中:\(abdfec\)对应\(123456\),则\(S\)中与之对应的是\(abcdef\)->\(126354\),所以要想让\(S\)变成\(T\),就要让其…
题目传送门 /* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include <string> #include <map>…
题目传送门 /* WA了好几次,除了第一次不知道string不用'\0'外 都是欠考虑造成的 */ #include <cstdio> #include <cmath> #include <string> #include <cstring> #include <iostream> #include <algorithm> #include <map> #include <set> #include <v…
当时打比赛的时候卡在D题了,没有看E.现在看来E还是不难的. 将n个数排序后,其实不排序也是可以的,只是排序能快一半的时间. 枚举前一半能得到多少种和,放到map里面: 然后在后一半数中枚举,然后在map里面查找. #include <bits/stdc++.h> using namespace std; typedef long long LL; ; LL a[maxn], f[maxn], S, ans; int n, m, k; map<int, LL> cnt[maxn];…
D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Finally it is a day when Arthur has enough money for buying an apartment. He found a great option close to the center of…
C. Ilya and Sticks time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of …
C. Vasya and String 题目连接: http://www.codeforces.com/contest/676/problem/C Description High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as th…
题目链接: http://codeforces.com/contest/676/problem/C 题解: 把连续的一段压缩成一个数,对新的数组求前缀和,用两个指针从左到右线性扫一遍. 一段值改变一部分的情况考虑的不够周到,wa了两次. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<vect…
A. Pasha and Stick 题目连接: http://www.codeforces.com/contest/610/problem/A Description Pasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive…
B. Pasha and Tea Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/problem/B Description Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of w milliliters and…
B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/problem/B Description Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of ex…
B. Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consis…