codeforces#238_div2_B Domino Effect
题目地址:戳这里
简单的模拟
从左到右扫一遍,注意维护一下,temp 表示积累没有操作的 Domino数目,每次操作后要对temp 清零
然后是维护上一个操作的操作类型和位置,要注意的是,初始值应该设置为一个取不到的,比如‘#’,这样知道是不是第一次遇到操作
然后就是顺着逻辑顺序往后走了,应该注意走到第n+1 项,只要lastone!=‘R’ 就把temp加进去吧
R....L 这种类型应该是L的index-R的index 是偶数的时候会对ans贡献1
代码:
#include<iostream>
#include<vector>
using namespace std;
char p[3005];
vector<char> v;
int main()
{
int n;
cin>>n;
char ch;
for(int i=0;i<n;i++)
{
cin>>p[i];
}
// for(int i=0;i<n;i++)
// {
// v.push_back(p[i]);
// if(p[i]=='L')
// {
//
// }
// }
char lastone='#';
int lastindex=0;
int ans=0;
int temp=0;
p[n]='$';
for(int i=0;i<n+1;i++)
{
if(i==n)
{
if(lastone!='R')
{
ans+=temp;
}
break;
}
if(p[i]=='.') temp++;
else
{
if(p[i]=='L')
{
if(lastone=='#')
{
temp=0;
lastone='L';
lastindex=i;
}
else if(lastone=='R')
{
if((i-lastindex)%2==0)
{
ans++;
}
temp=0;
lastone='L';
lastindex=i;
}
}
else // R
{
if(lastone=='#')
{
ans+=temp;
temp=0;
lastone='R';
lastindex=i;
}
else if(lastone=='L')
{
ans+=temp;
temp=0;
lastone='R';
lastindex=i;
}
}
}
}
cout<<ans<<endl;
}posted on 2014-03-25 01:20 814jingqi的ACM 阅读(143) 评论(0) 收藏 举报
浙公网安备 33010602011771号