CodeForces 405B Domino Effect【模拟】
来源:互联网 发布:淘宝拆分订单发货 编辑:程序博客网 时间:2024/05/22 15:41
Description
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 Input
14.L.R...LR..L..
4
5R....
0
1.
1
Hint
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.
/* 题意:有一堆骨牌,现在告诉你骨牌的初始状态,'.'表示直立,'L'表示向左倒,'R'表示向右倒,问你最后有几个骨牌是直立的 类型:模拟 分析:注意RL这种情况两者不是直立,按照规则模拟就行了*/#include<cstdio>#include<iostream>#include<algorithm>#include<vector>#include<set>#include<cstring>using namespace std;typedef long long ll;const int maxn = 3005;char s[maxn];int res[maxn];int main(){ int n;cin>>n; scanf("%s",s); int ans=n; int f1=0; int f2=-1; int sign; for(int i=0;i<n;i++){ if(s[i]=='L'){ ans-=i-f1+1; f1=i+1; } L1: if(s[i]=='R'){ sign=0; f1=i; for(int j=i+1;j<n;j++){ if(s[j]=='R'){ ans-=j-i+1; i=j; f1=i; goto L1; } if(s[j]=='L'){ if((j-i+1)%2)ans++; ans-=j-i+1; i=j; f1=i; sign=1; break; } } } } if(!sign)ans-=n-f1; printf("%d\n",ans); return 0;}
- CodeForces 405B Domino Effect【模拟】
- CodeForces - 405B Domino Effect (模拟)
- codeforces 405 B Domino Effect (模拟)
- codeforces 405B. Domino Effect
- Codeforces 405B Domino Effect
- codeforces 405B Domino Effect (模拟题,中等难度,细心就能一遍AC)
- CF 405B Domino Effect
- code forces 405B Domino Effect
- CodeForces - Domino Effect
- CF: B. Domino Effect
- B. Domino Effect
- Codeforces Round #238 (Div. 2)B:Domino Effect
- Codeforces Round #238 (Div. 2)-B.Domino Effect
- codeforces#238_div2_B Domino Effect
- cf——B. Domino Effect
- codeforces 269B B. Greenhouse Effect(dp)
- codeforces 269B - Greenhouse Effect DP
- codeforces 269B Greenhouse Effect (贪心+dp)
- hdu 2104 hide handkerchief
- 网站分析(七)
- Arduino 2.4G通信实验 nRF24L01模块的简单例子
- VS2013的bug
- js识别手机或PC
- CodeForces 405B Domino Effect【模拟】
- 设计模式-单一职责原则[SRP]
- jquery 实现回车登陆详解及实例代码
- 配置Windows的java环境(用于java解压版)
- noip2012:疫情控制
- 以前和同学俩做的一套比较经典的数据结构算法Flash教学课件
- /etc/ansible/hosts
- Codeforces 733 C. Epidemic in Monstropolis By Assassin
- Android:安装时提示:INSTALL_FAILED_INSUFFICIENT_STORAGE