摘要
题目链接 |
难度等级 |
完成状态 |
完成分数 |
最后编辑时间 |
需要注意
|
Domino Effect
|
★☆☆☆☆
|
答案正确
|
100
|
2015-02-24 16:41:23
|
无
|
题意
多米诺骨牌,有的向左倾斜有的向右倾斜,让他们全部倒下,最后还有几个立着。
题解
- 统计一串连续没有倾斜的个数,然后碰到倾斜的的时候统计即可。
代码
405B.cpp代码已折叠
展开折叠内容
|
- #include<cstdio>
- #include<iostream>
- #include<string>
- #include<vector>
- #include<algorithm>
- #include<cstring>
- #include<cmath>
- #include<set>
- using namespace std;
- #define sqr(x) ((x)*(x))
- #define dsi(n) int n;scanf("%d",&n)
- #define si(n) scanf("%d",&n)
- #define f(i,n) for(int i=1;i<=n;++i)
- #define fi(n) f(i,n)
- #define f0(i,n) for(int i=0;i!=n;++i)
- #define fd(i,n) for(int i=n;i>=1;--i)
- #define ci const int&
- #define foreach(i,s) for(typeof(s.begin()) i=s.begin();i!=s.end();++i)
- int n;
- string s;
- int main()
- {
- cin>>n;
- cin>>s;
- int ans=0;
- int p=0;//0最左边1有个R
- int se=0;//连续的...
- foreach(i,s)
- {
- if(*i=='L')
- {
- if(p){ans+=(se%2);}
- p=0;
- se=0;
- }
-
- if(*i=='R')
- {
- if(!p){ans+=se;}
- p=1;
- se=0;
- }
- if(*i=='.')
- ++se;
- }
- if(!p)ans+=se;
- cout<<ans;
- }
|