传送门:D - RGB Triplets

 题意:给你一个只含‘R’,‘G’,‘B’的字符串,求有多少个长度为3且每个字符都不相等,并且第一第二和第二第三的区间长度不同的子序列.

题解:统计每个字符各有多少,算出所有两两不同的子序列个数然后减去区间长度相等的个数即可

代码:

 1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 #include <algorithm>
6 #include <stack>
7 #include <queue>
8 #include <vector>
9 #include <map>
10 #include <set>
11 #include <unordered_set>
12 #include <unordered_map>
13 #define ll long long
14 #define fi first
15 #define se second
16 #define pb push_back
17 #define me memset
18 const int N = 1e6 + 10;
19 const int mod = 1e9 + 7;
20 using namespace std;
21 typedef pair<int,int> PII;
22 typedef pair<long,long> PLL;
23
24 int n;
25 ll cnt=0;
26 ll r,g,b;
27 string s;
28
29 int main() {
30 ios::sync_with_stdio(false);
31 cin>>n>>s;
32 for(int i=0;i<n;++i){
33 for(int j=i+1;j<n;++j){
34 int k=j+(j-i);
35 if(k>n-1) continue;
36 if(s[i]!=s[j] && s[j]!=s[k] && s[i]!=s[k]) cnt++;
37 }
38 }
39
40 for(int i=0;i<n;++i){
41 if(s[i]=='R') r++;
42 else if(s[i]=='G') g++;
43 else b++;
44 }
45 printf("%lld\n",r*g*b-cnt);
46
47
48 return 0;
49 }

 

Atcoder ABC162 D - RGB Triplets的更多相关文章

  1. AtCoder Beginner Contest 162

    比赛链接:https://atcoder.jp/contests/abc162/tasks A - Lucky 7 #include <bits/stdc++.h> using names ...

  2. PASCAL VOC数据集The PASCAL Object Recognition Database Collection

    The PASCAL Object Recognition Database Collection News 04-Apr-07: The VOC2007 challenge development ...

  3. matlab colormap

    This table lists the built-in colormaps functions. Colormap Name Color Scale parula

  4. AtCoder Grand Contest 025 B - RGB Coloring

    B - RGB Coloring 求ax + by = k (0<=x<=n && 0<=y<=n)的方案数,最后乘上C(n, x)*C(n,y) 代码: #i ...

  5. AtCoder - 2567 RGB Sequence

    Problem Statement There are N squares arranged in a row. The squares are numbered 1, 2, …, N, from l ...

  6. AtCoder Regular Contest 074 E:RGB Sequence

    题目传送门:https://arc074.contest.atcoder.jp/tasks/arc074_c 题目翻译 给你一行\(n\)个格子,你需要给每个格子填红绿蓝三色之一,并且同时满足\(m\ ...

  7. Atcoder E - RGB Sequence(dp)

    题目链接:http://arc074.contest.atcoder.jp/tasks/arc074_c 题意:一共有3种颜色,红色,绿色,蓝色.给出m个要求l,r,x表示在区间[l,r]内要有x种不 ...

  8. Atcoder Regular-074 Writeup

    C - Chocolate Bar 题面 There is a bar of chocolate with a height of H blocks and a width of W blocks. ...

  9. 【arc074e】RGB Sequence(动态规划)

    [arc074e]RGB Sequence(动态规划) 题面 atcoder 洛谷 翻译见洛谷 题解 直接考虑暴力\(dp\),设\(f[i][j][k][l]\)表示当前考虑到第\(i\)位,最后一 ...

随机推荐

  1. Centos 6.5 Rabbitmq 安装和集群,镜像部署

    centos 6.5 rabbitmq 安装和集群,镜像部署 安装erlang: yum install gcc glibc-devel make ncurses-devel openssl-deve ...

  2. 同一个网段内所有服务器virtual_router_id设置相同的后果

    /var/log/messages中一直报的错 one or more VIP associated with VRID mismatch actual MASTER advert bogus VRR ...

  3. 【Linux】NFS相关小问题

    NFS一些小问题: 1. 由于实验环境中,给了rw权限,但是执行的时候,还是提示Permission denied 于是查看nfs服务端,查看/etc/exports文件是否配置有问题 网上很多人配置 ...

  4. pycharm工具的使用

    一.Pycharm常用快捷键 快捷键 作用 备注  ctrl + win + 空格  自动提示并导包  连按两次  ctrl + alt + 空格  自动提示并导包  连按两次  Alt + Ente ...

  5. python 编译EXE文件

    以labelme测试 标注工具labelimg和labelme 矩形标注工具:labelimg 多边形标准工具:labelme 前者官网发布了可执行文件,后者只有python源码,如果需要编译wind ...

  6. RPC 实战与原理 精简版

    什么是 RPC? RPC 有什么作用? RPC 步骤 为什么需要序列化? 零拷贝 什么是零拷贝? 为什么需要零拷贝? 如何实现零拷贝? Netty 的零拷贝有何不同? 动态代理实现 HTTP/2 特性 ...

  7. [APUE] 进程环境

    APUE 一书的第七章学习笔记. 进程终止 有 8 种方式可以使得进程终止,5 种为正常方式: Return from main Calling exit() Calling _exit or _Ex ...

  8. 免安装的tomcat转服务

    一:确保tomcat 在点击bin\startup 文件可以正常启动访问: 二:本机安装有JDK: 三:本机环境变量配置:JAVA_HOME:C:\Java\jdk1.7.0_17; 四:本机Tomc ...

  9. https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError

    https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError

  10. css水平、垂直居中的写法

    水平居中 行内元素: text-align: center 块级元素: margin: 0 auto position:absolute +left:50%+ transform:translateX ...