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$ ...
随机推荐
- VxLAN、PAE、Telemetry简介
VxLAN VxLAN协议将 Ethernet帧 封装在UDP内,再加上8个字节的VXLAN header,用来标识不同的二层网络. VxLAN的角度看网络虚拟化:在一套物理网络设备上虚拟出多个二 ...
- Spring Data JPA基本了解
前言 自 JPA 伴随 Java EE 5 发布以来,受到了各大厂商及开源社区的追捧,各种商用的和开源的 JPA 框架如雨后春笋般出现,为开发者提供了丰富的选择.它一改之前 EJB 2.x 中实体 B ...
- Ubuntu下安装CUDA8.0及nvidia驱动
参考:https://blog.csdn.net/qq_35379989/article/details/80147630 cuda的历史版本下载地址:https://developer.nvidia ...
- jquery empty选择器 语法
jquery empty选择器 语法 作用::empty 选择器选取空的元素.空元素指的是不包含子元素或文本的元素.直线电机滑台 语法:$(":empty") jquery emp ...
- 用Java 实现断点续传 (HTTP)
在web项目中上传文件夹现在已经成为了一个主流的需求.在OA,或者企业ERP系统中都有类似的需求.上传文件夹并且保留层级结构能够对用户行成很好的引导,用户使用起来也更方便.能够提供更高级的应用支撑. ...
- 【HDU6667】Roundgod and Milk Tea【贪心】
题目大意:给你ai,bi,限制ai不能流向bi,求最大流 题解:贪心,对于第i个班级,考虑前i-1个班级匹配完剩余多少a,b,将这些ab对第i个班级进行贪心匹配 匹配完若第i个班级还有剩余的ab,考虑 ...
- windows Apache ab安装及压力测试
一:安装 ab是Apache自带的网站压力测试工具.使用起来非常的简单和方便.不仅仅是可以Apache服务器进行网站访问压力测试,还可以对其他类型的服务器进行压力测试.比如nginx,tomcat,I ...
- PO,BO,VO和POJO的区别
PO:persistent object 持久对象 1 .有时也被称为Data对象,对应数据库中的entity,可以简单认为一个PO对应数据库中的一条记录. 2 .在hibernate持久化框架中与i ...
- Java文件中代码
public class MyTextView extends TextView { //在用代码创建的时候调用 public MyTextView(Context context) { this(c ...
- pymysql 处理数据的几种方式
1.表中提取数据 sql = "SELECT * FROM table WHERE name='%s'AND time='%s'" % (name,time)多个选择条件用AND连 ...