C.0689-The 2019 ICPC China Shaanxi Provincial Programming Contest
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的更多相关文章
- 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 ...
- 计蒜客 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 ...
- 计蒜客 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. ...
- 计蒜客 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 ...
- 计蒜客 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 ...
- 计蒜客 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 ...
- The 2019 ACM-ICPC China Shannxi Provincial Programming Contest (西安邀请赛重现) J. And And And
链接:https://nanti.jisuanke.com/t/39277 思路: 一开始看着很像树分治,就用树分治写了下,发现因为异或操作的特殊性,我们是可以优化树分治中的容斥操作的,不合理的情况只 ...
- The 2018 ACM-ICPC China JiangSu Provincial Programming Contest快速幂取模及求逆元
题目来源 The 2018 ACM-ICPC China JiangSu Provincial Programming Contest 35.4% 1000ms 65536K Persona5 Per ...
- 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 ...
随机推荐
- poj3630 Phone List (trie树模板题)
Phone List Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26328 Accepted: 7938 Descr ...
- inux命令学习笔记(13):less 命令
less 工具也是对文件或其它输出进行分页显示的工具,应该说是linux正统查看文件内容的工具,功能极其强大. less 的用法比起 more 更加的有弹性.在 more 的时候,我们并没有办法向前面 ...
- [BZOJ2806][CTSC2012]熟悉的文章(Cheat)
bzoj luogu 题目描述 阿米巴是小强的好朋友. 在小强眼中,阿米巴是一个作文成绩很高的文艺青年.为了获取考试作文的真谛,小强向阿米巴求教.阿米巴给小强展示了几篇作文,小强觉得这些文章怎么看怎么 ...
- POJ1379:Run Away
我对模拟退火的理解:https://www.cnblogs.com/AKMer/p/9580982.html 我对爬山的理解:https://www.cnblogs.com/AKMer/p/95552 ...
- Poj 1019 Number Sequence( 数据分析和操作)
一.题目大意 有这样一个序列包含S1,S2,S3...SK,每一个Si包括整数1到 i.求在这个序列中给定的整数n为下标的数. 例如,前80位为1121231234123451234561234567 ...
- 【转】Pro Android学习笔记(五三):调试和分析(1):Debug视图和DDMS视图
目录(?)[-] Debug视图 DDMS视图 查看应用运行状态 进入debug状态 HPROF Thread信息 Method信息 Stop 截图 UI层次架构信息 其它的 Tab中提供的功能 我们 ...
- 安装LMS记
LMS学习管理系统,即英文Learning Management System的缩写.中文常用别名:在线学习系统. 尝试安装一款LMS,并进行二次开发. Moodle 首先想到的是Moodle.Moo ...
- ES6学习之Proxy
定义:“代理器”,用于修改某些操作的默认行为,等同于在语言层面做出修改,所以属于一种“元编程”(meta programming),即对编程语言进行编程.可以对外界的访问进行过滤和改写. 语法: va ...
- OS X 10.9 Mavericks下显示和隐藏文件(区别10.8.*)
我们常常在Windows系统下通过界面设置显示和隐藏文件,在Mac OS X通常采用defaults write命令来解决这个问题. 之前的OS X 10.8.*系统可以使用如下两条命令来开始或者关闭 ...
- 汉字转为unicode
在word中输入“立项申请阶段”,将光标移到每字之后时按下组合键Alt+X. 立项申请阶段 7ACB 9879 7533 8BF7 9636 6BB5 \u7ACB\u9879\u7533\ ...