0689 ZOJ - 4128
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 s s of length n n n, one must do the following operation exactly once: select a non-empty substring of s s s and rotate it 180 degrees.
More formally, let s i s_i si be the i i i-th character in string s s s. After rotating the substring starting from s l s_l sl and ending at s r s_r sr 180 degrees ( 1 ≤ l ≤ r ≤ n 1 \le l \le r \le n 1≤l≤r≤n), string s s s will become string t t t of length n n n extracted from the following equation, where t i t_i ti indicates the i i i-th character in string t t t: t i = { s i if 1 ≤ i < l or r < i ≤ n ’0’ if l ≤ i ≤ r and s l + r − i = ’0’ ’6’ if l ≤ i ≤ r and s l + r − i = ’9’ ’8’ if l ≤ i ≤ r and s l + r − i = ’8’ ’9’ if l ≤ i ≤ r and s l + r − i = ’6’ 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} ti=⎩⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎧si’0’’6’’8’’9’if 1≤i<l or r<i≤nif l≤i≤r and sl+r−i=’0’if l≤i≤r and sl+r−i=’9’if l≤i≤r and sl+r−i=’8’if l≤i≤r and sl+r−i=’6’
What’s the number of different strings one can get after the operation?
Input
There are multiple test cases. The first line of the input contains an integer T T T, indicating the number of test cases. For each test case:
The first and only line contains a 0689-string s s s ( 1 ≤ ∣ s ∣ ≤ 1 0 6 1 \le |s| \le 10^6 1≤∣s∣≤106).
It’s guaranteed that the sum of ∣ s ∣ |s| ∣s∣ of all test cases will not exceed 1 0 7 10^7 107.
Output
For each test case output one line containing one integer, indicating the number of different strings one can get after applying the operation exactly once.
Sample Input
2
0689
08
Sample Output
8
2
Code:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<map>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
const int inf=0x3f3f3f3f;
const double PI=acos(-1.0);
const int mod=1e9+7;
string x;
int main()
{ll T;scanf("%lld",&T);while(T--){cin>>x;ll l=x.size();ll sum=(1+l)*l/2+1;ll a=0,b=0,xx=0,yy=0;for(ll i=0; i<l; i++){if(x[i]=='0')a++;if(x[i]=='8')b++;if(x[i]=='6')xx++;if(x[i]=='9')yy++;}if(xx==l||yy==l){printf("%lld\n",sum-1);continue;}sum-=(1+a)*a/2;sum-=(1+b)*b/2;sum-=xx*yy;printf("%lld\n",sum);}return 0;
}
0689 ZOJ - 4128相关推荐
- ZOJ 2723 Semi-Prime ||ZOJ 2060 Fibonacci Again 水水水!
两题水题: 1.如果一个数能被分解为两个素数的乘积,则称为Semi-Prime,给你一个数,让你判断是不是Semi-Prime数. 2.定义F(0) = 7, F(1) = 11, F(n) = F( ...
- zoj 1204 Additive equations
ACCEPT acm作业 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=204 因为老师是在集合那里要我们做这道题.所以我很是天 ...
- 【HDU/POJ/ZOJ】Calling Extraterrestrial Intelligence Again (素数打表模板)
http://poj.org/problem?id=1411 POJ http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=168 ...
- 模拟 ZOJ 3878 Convert QWERTY to Dvorak
题目传送门 1 /* 2 模拟:手敲map一一映射,累! 3 除了忘记读入字符串不能用gets用getline外还是很顺利的AC了:) 4 */ 5 #include <cstdio> 6 ...
- 矩阵连乘积 ZOJ 1276 Optimal Array Multiplication Sequence
题目传送门 1 /* 2 题意:加上适当的括号,改变计算顺序使得总的计算次数最少 3 矩阵连乘积问题,DP解决:状态转移方程: 4 dp[i][j] = min (dp[i][k] + dp[k+1] ...
- ZOJ 3597 Hit the Target! (线段树扫描线 -- 矩形所能覆盖的最多的点数)
ZOJ 3597 题意是说有n把枪,有m个靶子,每把枪只有一发子弹(也就是说一把枪最多只能打一个靶子), 告诉你第 i 把枪可以打到第j个靶, 现在等概率的出现一个连续的P把枪,在知道这P把枪之后,你 ...
- 九度OJ—题目1032:ZOJ
题目描写叙述: 读入一个字符串.字符串中包括ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出.当某个字符用完时,剩下的仍然依照ZOJ的顺序输出. 输入: 题目包括多组用例,每组用例占一行,包括ZOJ ...
- ZOJ 1410 题解
题目链接:http://acm.zju.edu.cn/show_problem.php?pid=1410 又是一道简单题,以前做过一次,结果放弃了,今天看了一下,觉得还是比较简单于是下手了. 题目的大 ...
- POJ 1201 amp; HDU1384 amp; ZOJ 1508 Intervals(差分约束+spfa 求最长路径)
题目链接: POJ:http://poj.org/problem?id=1201 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1384 ZOJ:htt ...
最新文章
- android api 中文 (73)—— AdapterView
- what should you do if you want to become an expert in one domain
- 回腾讯了......
- USACO-Section2.3 Money Systems
- Atitit 跨平台异常处理(2)--------异常转换 -----java c# js异常对象结构比较and转换
- GAN模型生成山水画,骗过半数观察者,普林斯顿大学本科生出品
- Unity运行失败,Unsafe code may only appear if compiling with /unsafe
- UML建模,用EA画机票预订系统类图和对象图
- 3、Kubernetes的基本使用
- DVD刻录工具(anymp4 dvd creator 7)pjb v7.2.58
- 7-28 实验3_11_鸡兔同笼吗? (100 分)
- 【算法•日更•第九期】树型动态规划详解:二叉苹果树
- go 源码工具解析-英文单复数变化 Inflection
- 先睹为快HTML6来了,看看它的新特性吧
- java连续多位相同字符判断的正则表达式_java连续多位相同字符判断的正则表达式...
- 计算机一级wpsoffice知识点,2016年计算机一级《WPS Office》考试大纲
- 数据仓库、数据整合、ETL、ELT和EII之间的区别?
- ppt流程图字体太小_拯救那一页PPT丨对于文字和流程图的修改
- C语言编写简单的朗读小工具
- 2021年安全员-C证最新解析及安全员-C证理论考试