//B. Delete from the Left #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <set> #include <map> #include <vector> using namespace std; const int inf=0x3f3f3f3f; ; char a[N],b[…
题意:给你一个巨长无比的数,你可以将这个数划成任意多个部分,求这些部分中最多有多少个能被\(3\)整除. 题解:首先我们遍历累加每个位置的数字,如果某一位数或者累加和能被\(3\)整除(基础知识,不会就去百度),那这就是一部分,再来,我们可以发现一个部分最长只有\(3\)个数字. 证:当我这个部分有\(3\)个数字的时候,前两个数字\(mod\ 3\)的余数肯定同时为\(1\)或\(2\),这个时候: 假如第三个数字\(mod\ 3=1\)且前两个数字\(mod\ 3 = 1\),那这个三个数加…
参考:http://www.cnblogs.com/widsom/p/9290269.html 传送门:http://codeforces.com/contest/1005/problem/E2 题意:求一段数列中,取其中中位数为m的子序列个数有几个: 思路:首先我们可以先求出——序列中大于等于 m的数占多数的子序列——有多少个.然后,再求出序列中大于等于m+1的数占多数的子序列有多少个. 前面序列的个数减去后面的序列个数,就是答案. 显然这两个个数的求法是一样的.具体来说, 因为要计算区间的大…
一如既往地四题...好久没切了 有点犯困了明显脑子感觉不够灵活. 为了熟练度还是用java写的,,,导致观赏性很差...我好不容易拉了个队友一起切结果过掉a就tm挂机了!!! A题竟然卡了,,,用了十分钟,幸好我蓝了,不然这罚时怕不是要gg. A: 想了很多乱七八糟的法子,蓦然回首,还是暴力大法好. 把所有 ai==1 的点的下标全存进去, 然后对 a(n-1) 判断一下是否 为 1 就行,   我不知道怎么打带下标的数组啊啊啊, int n = nextInt(); int a[] = new…
E1. Median on Segments (Permutations Edition) time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given a permutation p1,p2,…,pnp1,p2,…,pn. A permutation of length nn is a sequence suc…
F - Berland and the Shortest Paths 思路:还是很好想的,处理出来最短路径图,然后搜k个就好啦. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define pii pair<int, int> using namespace std; ; const int inf = 0x3f3f3f3f;…
E2 - Median on Segments (General Case Edition) 题目大意:给你一个数组,求以m为中位数的区间个数. 思路:很巧秒的转换,我们把<= m 数记为1, >m的数 记为-1, 求其前缀,  我们将问题转变成求以<= m 的数作为中位数的区间个数, 答案就变为ans(m) - ans(m - 1),我们可以用上面求得的前缀用bit就能求出答案. #include<bits/stdc++.h> #define LL long long #d…
题意:给你一个数组,求有多少子数组的中位数等于\(m\).(若元素个数为偶数,取中间靠左的为中位数). 题解:由中位数的定义我们知道:若数组中\(<m\)的数有\(x\)个,\(>m\)的数有\(y\)个,只有\(x=y\)或\(y-x\)=1时,中位数才能取到\(m\),记\(m\)在原数组的位置为\(pos\). ​ 于是,我们先遍历\([pos,n]\),记录区间\([pos,i]\)中大于\(m\)的数和小于\(m\)的数个数差,用桶记录差值的个数. 然后我们反着遍历\([1,pos]…
http://codeforces.com/contest/1017/problem/E 凸包模板+kmp #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <time.h> #include <string> #include <set> #include <map> #include <l…
http://codeforces.com/contest/868/problem/D 优化:两个串合并 原有状态+ 第一个串的尾部&第二个串的头部的状态 串变为第一个串的头部&第二个串的尾部 注意: 头尾不能重复 如串A合并串A 这就意味着串的头尾不能有重合, 详见代码 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <…