CodeForces - Domino Effect
来源:互联网 发布:淘宝一手货源一件代发 编辑:程序博客网 时间:2024/05/21 19:15
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
"L", if the i-th domino has been pushed to the left;
"R", if the i-th domino has been pushed to the right;
".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Sample test(s)
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
"L", if the i-th domino has been pushed to the left;
"R", if the i-th domino has been pushed to the right;
".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Sample test(s)
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
/*AC*/#include <stdio.h>char s[3005];int main() { int n, i, flag; scanf("%d", &n); scanf("%s", &s[1]); int cnt = 0; for (i = 1; i <= n; i++) { if (s[i] == '.') { if (i < n) continue; else { cnt += n; break; } } else if (s[i] == 'R') { cnt += i - 1; flag = i; break; } else if (s[i] == 'L') { flag = -i; break; } } for (; i <= n; i++) { if (flag > 0) { if (s[i] == '.') continue; else if (s[i] == 'L') { if ((i - flag) % 2 == 0) cnt++; flag = -i; } } else if (flag < 0) { if (s[i] == '.') cnt++; else if (s[i] == 'R') flag = i; } } printf("%d\n", cnt); return 0;}
0 0
- CodeForces - Domino Effect
- codeforces#238_div2_B Domino Effect
- codeforces 405B. Domino Effect
- Codeforces 405B Domino Effect
- CodeForces 405B Domino Effect【模拟】
- CodeForces - 405B Domino Effect (模拟)
- codeforces 405 B Domino Effect (模拟)
- Codeforces Round #238 (Div. 2)B:Domino Effect
- Codeforces Round #238 (Div. 2)-B.Domino Effect
- JOJ 1133 Domino Effect
- zju 1298 Domino Effect
- poj 1135 Domino Effect
- poj1135 Domino Effect
- 1135 Domino Effect
- POJ 1135Domino Effect
- poj_1135 Domino Effect
- poj1135 - Domino Effect
- zoj1298-Domino Effect
- c# 互斥锁(Mutex)使用详解
- golang动态解析xml
- 数据结构-van emde boas 树
- 大电容并小电容
- UVA 409 - Excuses, Excuses!
- CodeForces - Domino Effect
- EnumMap学习
- Dynamics CRM 2013 Claim Based Authentication & IFD Configuration Tips
- UIWebView指南
- 第二周作业
- nginx源码学习资源
- 操作格子(线段树)
- shell——变量、数学运算、数组
- Android 入门 - 使用日志