摘要: 题意是给定n个大写字母组成的字符串。选择尽量多的串,使得每个字母的出现次数为偶数。 可以把每个单词转化成01串,然后用异或操作处理。 这里如果枚举所有情况的话复杂度是2^n,白书上面介绍了一种中途相遇法,可以把复杂度降低到2^(n/2)*logn甚至更低 方法是先穷举前n/2异或的所有可能值,如果有相同的保留最大的,可以用hash或者map存储映射关系。 然后穷举后n/2的所有可能值... 阅读全文
posted @ 2014-02-16 15:54 acm_roll 阅读(506) 评论(0) 推荐(0) 编辑
摘要: 简单的扫描算法 #include #include #include using namespace std;const int maxn = 1005;int T,M,N,mat[maxn][maxn],right[maxn][maxn],left[maxn][maxn],up[maxn][maxn];int main() { scanf("%d",&T); while(T--) { int... 阅读全文
posted @ 2014-02-16 12:54 acm_roll 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 假设有两个小孩子在跑道上面跑,如果跑道视环形的,那么速度快的那个小孩一定能追上速度慢的那个。 #include #include #include #include #include using namespace std;int next(int k,int n) { long long s = (long long)n; s = s * s; int len = log10(s) + ... 阅读全文
posted @ 2014-02-16 11:00 acm_roll 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 寻找一个序列中和不小于S的最短子序列,n的时间预处理出前缀和,然后枚举末位置二分初始位置nlogn搞定#include #include #include using namespace std;const int maxn = 100001;int A[maxn],B[maxn];int main() { int n,S; while(~scanf("%d%d",&n,&S)) { int ans = 0; for(int i = 1;i = S) { if(ans == 0) ans = i - str + 1; else ans = min(ans,i 阅读全文
posted @ 2014-02-16 10:54 acm_roll 阅读(314) 评论(0) 推荐(0) 编辑