Codeforces Round #741 (Div. 2), problem: (D1) Two Hundred Twenty One (easy version), 1700
Problem - D1 - Codeforces
题意:
给n个符号(+或-), +代表+1, -代表-1, 求最少删去几个点, 使得
题解(仅此个人理解):
1. 这题打眼一看, 肯定和奇偶有关系, 奇数为+, 偶数为-, 但是删去点这一操作是动态的, 删去某点后, 后面的点的正负随之颠倒, 即奇数位+变偶数位-, 偶数位-变奇数位+, 恰好可以利用该特质
也就是说可以这样理解: 找到一个位置,删去该点并使得后面的点正负颠倒, 最后满足条件.
2. 对于奇数个数, 必须变成偶数个个数才可能满足条件, 它一定存在个地方, 删去该点并且后面的点正负颠倒后满足条件, 结果为1
3. 对于偶数个数, 如果已经满足条件, 则输出0,
否,则先变成奇数个数再操作(和上面一样), 结果为2
AC代码
#include<iostream>
#include<string>
#include <cmath>
#include <algorithm> using namespace std;
const int N = 3e5+10;
int num[N]; void solve()
{
int n, q;
string s;
cin >> n >> q >>s;
for(int i = 0; i <= n; i ++)
// num[i+1] = num[i] + ((i&1)?-1:1) * ((s[i]=='+')?1:-1);
if(i%2==0&&s[i]=='+' || i%2==1&& s[i]=='-')num[i+1]=num[i]+1;
else num[i+1] = num[i]-1; while(q --)
{
int l, r;
cin >> l >> r;
if((r-l+1)&1)
{
puts("1");
continue;
}
if((num[r]-num[l-1])==0)puts("0");
else puts("2");
} return;
}
int main()
{
int t;
cin >> t;
while(t --)
solve(); return 0;
}
Codeforces Round #741 (Div. 2), problem: (D1) Two Hundred Twenty One (easy version), 1700的更多相关文章
- Codeforces Round #741 (Div. 2)部分题题解
我果然还是太菜了,就写了两道题....真是水死了.... A The Miracle and the Sleeper 简化题意:给定\(l,r\),求\(a\)%\(b\)的最大值,其中\(r> ...
- Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维
& -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...
- Codeforces Round #741 (Div. 2)
全部题目跳转链接 A - The Miracle and the Sleeper 题意 给定\([l, r]\) 求出在这个区间内的两个数字a和b的取模的最大值 (\(a \ge b\)) 分析 上届 ...
- Codeforces Round #753 (Div. 3), problem: (D) Blue-Red Permutation
还是看大佬的题解吧 CFRound#753(Div.3)A-E(后面的今天明天之内补) - 知乎 (zhihu.com) 传送门 Problem - D - Codeforces 题意 n个数字,n ...
- Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读
http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...
- Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense ...
- Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...
随机推荐
- sqli-labs下载与安装
Sqli-labs 下载 Sqli-labs是一个印度程序员写的,用来学习sql注入的一个游戏教程. 博客地址为:http://dummy2dummies.blogspot.hk/, 博客当中有一些示 ...
- LinuxCNC中RS-274/NGC解析器的编译和使用
原文 http://blog.sina.com.cn/s/blog_a2a6dd380102vrai.html LinuxCNC是一个著名的开源数控软件,目前最新发行版本是:LinuxCNC 2.6. ...
- K8S原来如此简单(八)ServiceAccount+RBAC
ServiceAccount ServiceAccount是给运行在Pod的程序使用的身份认证,Pod容器的进程需要访问API Server时用的就是ServiceAccount账户. Service ...
- 小白都能看懂的 Spring 源码揭秘之Spring MVC
目录 前言 Spring MVC 请求流程 Spring MVC 两大阶段 初始化 HttpServletBean#init() FrameworkServlet#initServletBean Fr ...
- SQL语句分为哪几种?
SQL语句主要可以划分为以下几类: DDL(Data Definition Language):数据定义语言,定义对数据库对象(库.表.列.索引)的操作. 包括:CREATE.DROP.ALTER.R ...
- jvm-learning-类加载器分类
public class ClassLoaderTest { public static void main(String[] args) { //获取系统类加载器 ClassLoader syste ...
- MariaDB数据库设置用户密码
SET PASSWORD [FOR user] = { PASSWORD('some password') | OLD_PASSWORD('some password') | 'encrypted p ...
- 面试问题之C++语言:多态
什么是多态? 概念:同一操作作用于不同的对象,可以有不同的解释,产生不同的执行结果,这就是多态性.简单的说,就是用基类的引用指向子类的对象. 为什么要用多态呢? 原因:封装可以隐藏实现细节,使得代码模 ...
- spring-boot-learning-使用jsp
加入依赖: <!-- jsp--> <!--引入Spring Boot内嵌的Tomcat对JSP的解析包--> <dependency> <groupId&g ...
- http和https到底区别在哪
一.Http和Https的基本概念 Http:超文本传输协议(Http,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.设计Http最初的目的是为了提供一 ...