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. ACM学习历程—ZOJ 3868 GCD Expectation(莫比乌斯 || 容斥原理)

    Description Edward has a set of n integers {a1, a2,...,an}. He randomly picks a nonempty subset {x1, ...

  2. bzoj 3091: 城市旅行 LCT

    题目: http://www.lydsy.com/JudgeOnline/problem.php?id=3091 题解: 首先前三个操作就是裸的LCT模板 只考虑第四个操作. 要求我们计算期望,所以我 ...

  3. photon server (1)

    Photon是一套使用广泛的socket server引擎,服务端底层C++编写,客户端C#编写,跨多平台,收费,效率可观的一款引擎.实用上前有九城游戏(原魔兽世界代理),现在笔者发现多款腾讯旗下3D ...

  4. Android的缓存图片不在系统图库中显示的解决办法

    Android的图库会在开机的时候扫描SD卡中的图片,视频等文件,有很多App的私有图片不想在图库中显示,就需要另外处理了. 解决办法:在缓存图片的文件夹中创建 .nomedia 文件. 1. &qu ...

  5. POJ2442:Sequence

    浅谈堆:https://www.cnblogs.com/AKMer/p/10284629.html 题目传送门:http://poj.org/problem?id=2442 我们先简化题意,假设只有两 ...

  6. Java精度计算与舍入

    用到的类: 类 BigDecimal:不可变的.任意精度的有符号十进制数.BigDecimal 由任意精度的整数非标度值 和 32 位的整数标度 (scale) 组成.如果为零或正数,则标度是小数点后 ...

  7. java代码GUI简单的。。。

    总结:觉得 package com.da; import java.awt.*; //逆向思维:important //创建一个String对象的数组,然后执行读取文本,把文本每一行存入数组,它将读取 ...

  8. python并发编程之多进程2数据共享及进程池和回调函数

    一.数据共享 尽量避免共享数据的方式 可以借助队列或管道实现通信,二者都是基于消息传递的. 虽然进程间数据独立,但可以用过Manager实现数据共享,事实上Manager的功能远不止于此. 命令就是一 ...

  9. python 爬虫 之BeautifulSoup

    BeautifulSoup是一个模块,该模块用于接收一个HTML或XML字符串,然后将其进行格式化,之后便可以使用他提供的方法进行快速查找指定元素,从而使得在HTML或XML中查找指定元素变得简单. ...

  10. mysql主从服务器复制操作

    master主机ip:192.168.1.19  用户名sunzy 密码123456slave主机ip:192.168.1.20 1.配置master1)接下来对master进行配置,包括打开二进制日 ...