We call a string as a 0689-string if this string only consists of digits '0', '6', '8' and '9'. Given a 0689-string $s$ of length $n$, one must do the following operation exactly once: select a non-empty substring of $s$ and rotate it 180 degrees.

More formally, let $s_i$ be the $i$-th character in string $s$. After rotating the substring starting from $s_l$ and ending at $s_r$ 180 degrees ($1 \le l \le r \le n$), string $s$ will become string $t$ of length $n$ extracted from the following equation, where $t_i$ indicates the $i$-th character in string $t$: $$t_i = \begin{cases} s_i & \text{if } 1 \le i < l \text{ or } r < i \le n \\ \text{'0'} & \text{if } l \le i \le r \text{ and } s_{l+r-i} = \text{'0'} \\ \text{'6'} & \text{if } l \le i \le r \text{ and } s_{l+r-i} = \text{'9'} \\ \text{'8'} & \text{if } l \le i \le r \text{ and } s_{l+r-i} = \text{'8'} \\ \text{'9'} & \text{if } l \le i \le r \text{ and } s_{l+r-i} = \text{'6'} \\ \end{cases}$$

What's the number of different strings one can get after the operation?

We hereby explain the first sample test case.

Substring Result   Substring Result
0 0689   68 0899
6 0989   89 0668
8 0689   068 8909
9 0686   689 0689
06 9089   0689 6890

It's easy to discover that we can get 8 different strings after the operation.


题意:给定一个含有0689的串,你可以中心旋转子串,询问旋转任意子串产生的不同的串一共最多哟多少种?

我们假设从前往后统计,能么0和后面非0位置的串都可以统计,如果两个0之间有非0,能么会在非0的时候进行统计,这样就不重不漏了,同理8也是,但是6和9不行,9和6也不行,但是6和6以及自身还有9和9以及自身都是可以的

 1 #include <cstdio>
 2 #include <cstring>
 3
 4 const int MAXN = (int)1e6 + 5;
 5 int t;
 6 char str[MAXN];
 7 long long num[MAXN][5];
 8
 9 int main() {
10     scanf("%d", &t);
11     while (t--) {
12         scanf("%s", str + 1);
13         int n = strlen(str + 1);
14         for (int i = 1; i <= n + 1; i++) num[i][1] = num[i][2] = num[i][3] = num[i][4] = 0;
15         for (int i = n; i >= 1; i--) {
16             num[i][1] = num[i + 1][1] + (str[i] == '0');
17             num[i][2] = num[i + 1][2] + (str[i] == '8');
18             num[i][3] = num[i + 1][3] + (str[i] == '6');
19             num[i][4] = num[i + 1][4] + (str[i] == '9');
20         }
21         long long ans = 1;
22         for (int i = 1; i <= n; i++) {
23             if (str[i] == '0') {
24                 ans += num[i + 1][2];
25                 ans += num[i + 1][3];
26                 ans += num[i + 1][4];
27             }
28             if (str[i] == '8') {
29                 ans += num[i + 1][1];
30                 ans += num[i + 1][3];
31                 ans += num[i + 1][4];
32             }
33             if (str[i] == '6') {
34                 ans += num[i + 1][1];
35                 ans += num[i + 1][2];
36                 ans += num[i][3];
37             }
38             if (str[i] == '9') {
39                 ans += num[i + 1][1];
40                 ans += num[i + 1][2];
41                 ans += num[i][4];
42             }
43         }
44         if (num[1][3] == n || num[1][4] == n) ans--;
45         printf("%lld\n", ans);
46     }
47     return 0;
48 }

C.0689-The 2019 ICPC China Shaanxi Provincial Programming Contest的更多相关文章

  1. B.Grid with Arrows-The 2019 ICPC China Shaanxi Provincial Programming Contest

    BaoBao has just found a grid with $n$ rows and $m$ columns in his left pocket, where the cell in the ...

  2. 计蒜客 39272.Tree-树链剖分(点权)+带修改区间异或和 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest E.) 2019ICPC西安邀请赛现场赛重现赛

    Tree Ming and Hong are playing a simple game called nim game. They have nn piles of stones numbered  ...

  3. 计蒜客 39280.Travel-二分+最短路dijkstra-二分过程中保存结果,因为二分完最后的不一定是结果 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest M.) 2019ICPC西安邀请赛现场赛重现赛

    Travel There are nn planets in the MOT galaxy, and each planet has a unique number from 1 \sim n1∼n. ...

  4. 计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛

    Swap There is a sequence of numbers of length nn, and each number in the sequence is different. Ther ...

  5. 计蒜客 39270.Angel's Journey-简单的计算几何 ((The 2019 ACM-ICPC China Shannxi Provincial Programming Contest C.) 2019ICPC西安邀请赛现场赛重现赛

    Angel's Journey “Miyane!” This day Hana asks Miyako for help again. Hana plays the part of angel on ...

  6. 计蒜客 39268.Tasks-签到 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest A.) 2019ICPC西安邀请赛现场赛重现赛

    Tasks It's too late now, but you still have too much work to do. There are nn tasks on your list. Th ...

  7. The 2019 ACM-ICPC China Shannxi Provincial Programming Contest (西安邀请赛重现) J. And And And

    链接:https://nanti.jisuanke.com/t/39277 思路: 一开始看着很像树分治,就用树分治写了下,发现因为异或操作的特殊性,我们是可以优化树分治中的容斥操作的,不合理的情况只 ...

  8. The 2018 ACM-ICPC China JiangSu Provincial Programming Contest快速幂取模及求逆元

    题目来源 The 2018 ACM-ICPC China JiangSu Provincial Programming Contest 35.4% 1000ms 65536K Persona5 Per ...

  9. The 2018 ACM-ICPC China JiangSu Provincial Programming Contest J. Set

    Let's consider some math problems. JSZKC has a set A=A={1,2,...,N}. He defines a subset of A as 'Meo ...

随机推荐

  1. codeforces 631A A. Interview

    A. Interview time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  2. 【遍历二叉树】09判断二叉树是否关于自己镜像对称【Symmetric Tree】

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 给定一个二叉树,判断是否他自己的镜 ...

  3. 20179215《Linux内核原理与分析》第一周作业

    一.Linux介绍 我们现在很常见Windows系统,对于Linux则显得尤为陌生.当然我也不例外,初识Linux过程中遇到一些困惑,但我也在实验的同时通过不断查找资料与实践中慢慢解决问题.那么下面我 ...

  4. HDU1698(线段树入门题)

    Just a Hook Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Descrip ...

  5. 多puppetmaster,多ca,keepalived+haproxy(nginx)puppet集群搭建

    多puppetmaster,多ca,keepalived+haproxy(nginx)puppet集群搭建 一.服务器详情 192.168.122.111 pm01.jq.com pm01 #(pup ...

  6. java web基础知识

    1)TCP三次握手 第一次握手:客户端A将标志位SYN置为1,随机产生一个值为seq=J(J的取值范围为=1234567)的数据包到服务器,客户端A进入SYN_SENT状态,等待服务端B确认: 第二次 ...

  7. C#设计模式(11)——外观模式

    一.概念 外观模式提供了一个统一的接口,用来访问子系统中的一群接口.外观定义了一个高层接口,让子系统更容易使用.使用外观模式时,我们创建了一个统一的类,用来包装子系统中一个或多个复杂的类,客户端可以直 ...

  8. CCNet说明文档

    1.CCNet安装步骤 1)    安装CCNet服务器端:CruiseControl.NET-1.8.5.0-Setup.exe 2)    安装CCNet客户端:CruiseControl.NET ...

  9. linux日常管理-防火墙netfilter工具-iptables-1

    防火墙的名字叫 netfilter 工具/命令叫iptables 命令:iptables 选项: -t   指定表 -A 在最上面增加一条规则 -I 在最下面增加一条规则 -D 删除一条规则 -A-I ...

  10. linux日常管理-系统进程查看工具-ps

    查看系统有那些进程 命令有ps aux 和命令 ps -elf USER  哪个用户使用了这个进程 PID  进程的id %CPU 占用CPU的百分比 %MEM 占用内存的百分比 VSZ 虚拟内存的大 ...