codeforces 1186C Vus the Cossack and Strings
题目链接:https://codeforc.es/contest/1186/problem/C
题目大意:xxxxx(自认为讲不清。for instance)
例如:a="01100010" b="00110"。
我们把a截到b的长度就有4个字串。
a1=01100 a2=11000 a3=10001 a4=00010
f(s1,s2)表示是s1与s2异或后1的个数
题目要求每个a子串与b的f(ai,b)的值为偶数的个数。
ps:暑假第一天,签到写个稍微简单一点的题
思路:
如果在例子中b串是"00000"。那么题目变为求ai的1的个数为偶数的个数
这里我们用前缀和来求就非常好了。
a1= 01100 符合题意
a2= 11000 符合题意
a3= 10001 符合题意
a4= 00010 不符合题意
前缀和应该会吧。O(1)就可以知道和。然后判断一下奇偶就好了
但是b串不一定是"00000"
这时我们看一下如果b="00100"会怎么样?
a1= 01000 不符合题意
a2= 11100 不符合题意
a3= 10101 不符合题意
a4= 00110 符合题意
所以,我们可以得出当b串的1的个数为奇数是我们求a子串的1的个数为奇数的个数
反之,求偶数的个数
愉快的贴代码^-^
#include <bits/stdc++.h>
using namespace std;
#define N 1000100 int x[N];
int ser=;
signed main()
{
ios::sync_with_stdio(false);
string s,ss;
cin>>s>>ss; for(auto&c:s){
int a=(c=='');
x[++ser]=a;
x[ser]+=x[ser-];
} int b=;
for(auto&c:ss){
b^=(c=='');
}
int Ans=;
for(int i=ss.size();i<=ser;i++){
//cout<<x[i]<<" "<<x[i-ss.size()]<<endl;
Ans+=!((x[i]-x[i-ss.size()])&)^b;
}
cout<<Ans;
return ;
}
codeforces 1186C Vus the Cossack and Strings的更多相关文章
- Vus the Cossack and Strings(Codeforces Round #571 (Div. 2))(大佬的位运算实在是太强了!)
C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist ...
- CodeForces - 1186 C. Vus the Cossack and Strings (异或)
Vus the Cossack has two binary strings, that is, strings that consist only of "0" and &quo ...
- Codeforces F. Vus the Cossack and Numbers(贪心)
题目描述: D. Vus the Cossack and Numbers Vus the Cossack has nn real numbers aiai. It is known that the ...
- C Vus the Cossack and Strings ( 异或 思维)
题意 : 给你两个只包含 0 和 1 的字符串 a, b,定义函数 f ( A, B ) 为 字符串A和字符串B 比较 存在多少个位置 i 使得 A[ i ] != B[ i ] ,例如 f(0011 ...
- Codeforces 1186F - Vus the Cossack and a Graph 模拟乱搞/欧拉回路
题意:给你一张无向图,要求对这张图进行删边操作,要求删边之后的图的总边数 >= ceil((n + m) / 2), 每个点的度数 >= ceil(deg[i] / 2).(deg[i]是 ...
- @codeforces - 1186F@ Vus the Cossack and a Graph
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 n 点 m 边的图(n, m<=10^6),记第 ...
- Codeforces Round #571 (Div. 2)-D. Vus the Cossack and Numbers
Vus the Cossack has nn real numbers aiai. It is known that the sum of all numbers is equal to 00. He ...
- E. Vus the Cossack and a Field (求一有规律矩形区域值) (有一结论待证)
E. Vus the Cossack and a Field (求一有规律矩形区域值) 题意:给出一个原01矩阵,它按照以下规则拓展:向右和下拓展一个相同大小的 0 1 分别和原矩阵对应位置相反的矩阵 ...
- 『Codeforces 1186E 』Vus the Cossack and a Field (性质+大力讨论)
Description 给出一个$n\times m$的$01$矩阵$A$. 记矩阵$X$每一个元素取反以后的矩阵为$X'$,(每一个cell 都01倒置) 定义对$n \times m$的矩阵$A$ ...
随机推荐
- 【writeup】is_numeric函数矛盾运用
最近在BugkuCTF平台刷题,遇到‘矛盾’http://120.24.86.145:8002/get/index1.php,感觉蛮有意思的,记录下思路 目标代码如下: $num=$_GET['num ...
- Codeforces 985 最短水桶分配 沙堆构造 贪心单调对列
A B /* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a, ...
- Python核心技术与实战——十七|Python并发编程之Futures
不论是哪一种语言,并发编程都是一项非常重要的技巧.比如我们上一章用的爬虫,就被广泛用在工业的各个领域.我们每天在各个网站.App上获取的新闻信息,很大一部分都是通过并发编程版本的爬虫获得的. 正确并合 ...
- MySQL 表的增删查改
一.插入数据 1. INSERT ... VALUES ... INSERT INTO <表名> [ <列名1> [ , … <列名n>] ] VALUES (值1 ...
- 枚举类enum应用以及注解@transient应用
1.增加枚举类 public enum RightTypeEnum { AUTHORITY("访问权限") private String type; RightTypeEnum(S ...
- 【洛谷P2922】Secret Message
题目大意:给定 N 个字符串组成的字典,有 M 个询问,每次给定一个字符串,求字典中有多少个单词为给定字符串的前缀或前缀是给定的字符串. 题解:在 trie 上维护一个 tag 表示有多少字符串以当前 ...
- Python 元组Ⅱ
删除元组 元组中的元素值是不允许删除的,但我们可以使用del语句来删除整个元组,如下实例: 以上实例元组被删除后,输出变量会有异常信息,输出如下所示: 元组运算符 与字符串一样,元组之间可以使用 + ...
- 查看SSL证书的别名
1.把java目录下的keytool拷贝到证书目录下:2.进入证书目录,然后输入命令keytool -list -v -keystore file.jks -storepass password,发现 ...
- docker-compose命令及yaml文件
Docker-compose常用命令 docker-compose up -d nginx 构建建启动nignx容器 docker-compose exec nginx bash 登录到nginx容器 ...
- codevs 1020 孪生蜘蛛 x
题目描述 Description 在G城保卫战中,超级孪生蜘蛛Phantom001和Phantom002作为第三层防卫被派往守护内城南端一带极为隐秘的通道. 根据防护中心的消息,敌方已经有一只特种飞蛾 ...