CodeForces 374 B. Inna and Nine
2013-12-19 17:05
627 查看
B. Inna and Nine
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large
number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and
replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 → 1945181 → 194519 → 19919.
Also, she can use this method to transform number 14545181 into number 19991.
Inna will not transform it into 149591 as she can get numbers 19919and 19991 which
contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 ≤ a ≤ 10100000).
Number a doesn't have any zeroes.
Output
In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams
or the %I64dspecifier.
Sample test(s)
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.
In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.
xyxyxy....xy 时有1种变换方法
xyxyxy....xyx 时可以空出任意一个x
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large
number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and
replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 → 1945181 → 194519 → 19919.
Also, she can use this method to transform number 14545181 into number 19991.
Inna will not transform it into 149591 as she can get numbers 19919and 19991 which
contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 ≤ a ≤ 10100000).
Number a doesn't have any zeroes.
Output
In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams
or the %I64dspecifier.
Sample test(s)
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.
In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.
xyxyxy....xy 时有1种变换方法
xyxyxy....xyx 时可以空出任意一个x
#include <iostream> #include <cstring> #include <cstdio> #include <string> using namespace std; string a; int main() { unsigned long long int cnt=1; cin>>a; unsigned long long int len=a.size(); unsigned long long int last=1; for(int i=0;i<len;i++) { if(a[i]=='9') continue; if(a[i]+a[i+1]==9+2*'0') last++; else if(last) { if(last%2) cnt*=(last+1)/2; last=1; } } cout<<cnt<<endl; return 0; }
相关文章推荐
- CodeForces 374 B.Inna and Nine(组合数学)
- CodeForces 374 D. Inna and Sequence
- CodeForces 374 A. Inna and Pink Pony
- Codeforces 374A - Inna and Pink Pony
- codeforces 400C - Inna and Huge Candy Matrix
- B. Inna and Nine----思维题
- codeforces 374C C. Inna and Dima(DFS)
- 【打CF,学算法——二星级】CodeForces 374A Inna and Pink Pony (水题/坑题)
- codeforces 400C Inna and Huge Candy Matrix
- CodeForces 400E Inna and Binary Logic
- codeforces 390A Inna and Alarm Clock
- Codeforces 390C Inna and Candy Boxes(dp)
- Codeforces 400E Inna and Binary Logic(位运算+暴力)
- Codeforces 400A Inna and Choose Options
- codeforces 390C Inna and Candy Boxes
- B. Inna and Nine
- Codeforces 400 A. Inna and Choose Options 【Codeforces Round #234 (Div. 2)】
- Codeforces 390C Inna and Candy Boxes RMQ简单变化 或 前缀和dp一下
- Codeforces 400 C. Inna and Huge Candy Matrix
- 220 DIV2 B. Inna and Nine