C题:一道简单的C题卡了半天,我太菜了

题意:给你一个n*2的矩阵,每个位置有一个数字,对应一种管道,要求通道可不可以从左上通到右下

由提议可以看出,1,2对应的是直管道,3,4,5,6对应弯管道,只有弯管道成对才可以换行,直管道只能换列

只需直管道的时候往右走,弯管的时候判断一下对应的下一行情况,同时弯管就换行,不是就输出“NO”

  1. #include <iostream>
  2. #include <cstring>
  3. #include <string>
  4. #include <cmath>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8. typedef long long ll;
  9. string s[];
  10.  
  11. int main()
  12. {
  13. int q;
  14. cin >> q;
  15. while(q--)
  16. {
  17. int n;
  18. bool flag =false;
  19. cin >> n;
  20. cin >> s[]>>s[];
  21. int num =;
  22. int i=;
  23. int j=;
  24. while(i<n)
  25. {
  26. if(s[j][i]<'')i++;
  27. else if(s[j][i]>'')
  28. {
  29. j^=;
  30. if(s[j][i]>'')i++;
  31. else{
  32. break;
  33. }
  34. }
  35. }
  36. if(j==&&i==n)
  37. {
  38. cout <<"YES"<<endl;
  39. }
  40. else{
  41. cout <<"NO"<<endl;
  42. }
  43. }
  44. return ;
  45. }

D题

题意:给你一个字符串,然后有q次操作,操作分为两种:第一种操作是改变一个位置的字母为另一个指定字母;第二种操作是查询区间(L~R)上有多少个不同的字符

思路:第一想法是线段树模板,线段树一直还没看,也没有看板子,当时就没有做,后来补题看别人交的代码,发现竟然可以用set来优化查询,果然我就连STL都不会用,留下菜的泪水。。。。。。。

就是我们字母总共就只有26个,我就开26个set来存,每个字母的位置,修改时只需将那个点的字母去掉那个位置,在给定的字母里面加上这个为位置,查询时就将26个字母都查一遍

  1. #include <iostream>
  2. #include <cstring>
  3. #include <string>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <set>
  7. using namespace std;
  8. typedef long long ll;
  9.  
  10. int main()
  11. {
  12. string s;
  13. set<int>p[];
  14. cin >> s;
  15. for(int i=;i<s.size();i++)
  16. {
  17. p[s[i]-'a'].insert(i+);
  18. }
  19. int q;
  20. cin >> q;
  21. while(q--)
  22. {
  23. int a;
  24. scanf("%d",&a);
  25. if(a==){
  26. int b;
  27. char cc[];
  28. scanf("%d",&b);
  29. scanf("%s",cc);
  30. //cout <<cc[0]<<endl;
  31. p[s[b-]-'a'].erase(b);
  32. s[b-]=cc[];
  33. p[cc[]-'a'].insert(b);
  34.  
  35. }
  36. else{
  37. int l,r;
  38. int ans = ;
  39. scanf("%d%d",&l,&r);
  40. for(int i=;i<;i++)
  41. {
  42. if(p[i].size())
  43. {
  44. auto j =p[i].lower_bound(l);
  45. if(*j<=r&&j!=p[i].end())ans++;
  46. }
  47. }
  48. cout << ans<<endl;
  49. }
  50. }
  51. return ;
  52. }

Codeforces Round #590 (Div. 3) 万恶的自己WAC的更多相关文章

  1. Codeforces Round #590 (Div. 3) Editorial

    Codeforces Round #590 (Div. 3) Editorial 题目链接 官方题解 不要因为走得太远,就忘记为什么出发! Problem A 题目大意:商店有n件商品,每件商品有不同 ...

  2. Codeforces Round #590 (Div. 3)

    A. Equalize Prices Again 题目链接:https://codeforces.com/contest/1234/problem/A 题意:给你 n 个数 , 你需要改变这些数使得这 ...

  3. Codeforces Round #590 (Div. 3) E. Special Permutations

    链接: https://codeforces.com/contest/1234/problem/E 题意: Let's define pi(n) as the following permutatio ...

  4. Codeforces Round #590 (Div. 3) D. Distinct Characters Queries(线段树, 位运算)

    链接: https://codeforces.com/contest/1234/problem/D 题意: You are given a string s consisting of lowerca ...

  5. Codeforces Round #590 (Div. 3) C. Pipes

    链接: https://codeforces.com/contest/1234/problem/C 题意: You are given a system of pipes. It consists o ...

  6. Codeforces Round #590 (Div. 3) B2. Social Network (hard version)

    链接: https://codeforces.com/contest/1234/problem/B2 题意: The only difference between easy and hard ver ...

  7. Codeforces Round #590 (Div. 3) A. Equalize Prices Again

    链接: https://codeforces.com/contest/1234/problem/A 题意: You are both a shop keeper and a shop assistan ...

  8. Codeforces Round #590 (Div. 3)(e、f待补

    https://codeforces.com/contest/1234/problem/A A. Equalize Prices Again #include<bits/stdc++.h> ...

  9. Codeforces Round #590 (Div. 3) F

    传送门 题意: 给出一个只含前\(20\)个字符的字符串,现在可以选择一段区间进行翻转,问区间中字符各不相同时,最长长度为多少. 思路: 首先,容易将题意转换为选择两个字符各不相同的区间,然后长度相加 ...

随机推荐

  1. python_网络编程_基础

    基本的架构有C/S架构 和B/S架构 B/S架构优于C/S架构? 因为统一入口 , 都是从浏览器开始访问 两台电脑实现通信, 需要网卡, 网卡上有全球唯一的mac地址 ARP协议 #通过ip地址就能找 ...

  2. Feeding Time 【bfs求最大连通块】

    题目链接:https://ac.nowcoder.com/acm/contest/1870/J 题目大意:求最大的连通块是多大 主要是为了防止自己忘记bfs怎么写..... #include<s ...

  3. PCL学习(三) SAC-IA 估记object pose

    SAC-IA是基于RANSAC算法的对齐算法 通过降采样提高法向计算.FPFH特征的计算 最后通过SAC-IA计算得到对齐的旋转和平移 #include <Eigen/Core> #inc ...

  4. [转帖]AIDA64 6.10版发布:全面支持中国兆芯、海光x86 CPU

    AIDA64 6.10版发布:全面支持中国兆芯.海光x86 CPU https://www.cnbeta.com/articles/soft/892877.htm 支持国产x86了 作为硬件识别工具领 ...

  5. WUSTOJ 1241: 到底是几月几日?(Java)

    1241: 到底是几月几日? 题目   输入年月日,输出当前日期是当年的第几天,输入年份和第几天,输出当前日期.更多内容点击标题. 说明   算是水题吧,仅提供代码做参考,不做分析.代码没用JDK自带 ...

  6. EXIT(外部中断)控制实验

    实验目的 设计使用外接的按键来作为触发源,使得控制器产生中断,并在中断服务函数中实现控制小灯的亮灭. 按键硬件点路 编程要点 初始化用来产生中断的 GPIO: 初始化 EXTI: 配置 NVIC: 编 ...

  7. 【C#】课堂知识点#2

    课堂上老师讲了几点,自己觉得挺重要的,记录下来 1.代码字体调大,方便调试 2.虚心请教,没有谁比谁厉害,不会就虚心多请教,baidu并不能解决所有问题.沟通交流也是一种能力 3.只有每行写对了,才继 ...

  8. CSS定位以及z-index属性(层叠性)的详解(转)

    https://blog.csdn.net/weixin_41342585/article/details/79484879

  9. 安装本地jar包

    (1)安装在本地maven库 假设我们需要引入的包为 myjar-1.0.jar (1.1)打开cmd,进入myjar-1.0.jar所在的目录 (1.2)执行如下命令:mvn install:ins ...

  10. poj 3617 弱鸡贪心

    比赛的时候扣了一道贪心的题目,不会写,,现在补一补一些基础的贪心. 题意:给定一个字符串s,要求按下列操作生成一个新串t--每次从s串中的最前和最后取一个字符给t,要求生成的t字典序最小. 题解:由于 ...