本文主要是介绍CodeForces - 298A(雪地走步),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
奇妙的一个题 最后一轮的A点击打开链接
我把题目看错了!,请zzh仔细阅读红色字体部分!!!
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 ton from left to right. If one moves from thei-th block to the (i + 1)-th block, he will leave a right footprint on thei-th block. Similarly,if one moves from thei-th block to the(i - 1)-th block, he will leave a left footprint on thei-th block. If there already is a footprint on thei-th block, the new footprint will cover the old one.
At the beginning, there were no footprints. Then polar bear Alice starts from thes-th block, makes a sequence of moves and ends in thet-th block. It is known that Alice never moves outside of the road.
You are given the description of Alice's footprints. Your task is to find a pair of possible values ofs, t by looking at the footprints.
The first line of the input contains integer n(3 ≤ n ≤ 1000).
The second line contains the description of the road — the string that consists ofn characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
Print two space-separated integers — the values of s andt. If there are several possible solutions you can print any of them.
9 ..RRLL...
3 4
11 .RRRLLLLL..
7 5
The first test sample is the one in the picture.
怕是个傻子!!! 他是走过一个路 走过去才会留下脚印,也就是说他当前的位置是不会有脚印的
然后经过一番研究发现,奇妙的是,他不会存在LR的情况,也就是说,只要他走,就只有三种情况,
1 全是L
2 全是R
3 先R再L (并且R L 一定是连续出现的不会有RLR或者LR 或者LRL )
关于起点,三种情况是一样的就是说:起点全部都是第一个出现脚印的点
关于终点: 1,在起点的左边
2,在最后一个R的右边
3,在第一个L出现的位置的左边
就是这样,,,,好有规律的一个题目
wa了n次总算是得出一个清晰地结论不错不错,虽然是个水题
上代码:
#include <iostream>
#include<cstring>using namespace std;
const int maxn=1000+5;
char s[maxn];
int main()
{int n;cin>>n;memset(s,0,sizeof(s));for(int i=1;i<=n;i++)cin>>s[i];int be=0,en=0;int flag=0;int r=0;for(int i=1;i<=n;i++){if(s[i-1]=='R'&&s[i]=='L'){flag=1;en=i-1;}if((s[i-1]=='.'&&s[i]=='R')||(s[i-1]=='.'&&s[i]=='L'))be=i;if(s[i]=='R')r=1;if(!flag&&(s[i]=='R'&&s[i+1]=='.'))en=i+1;}if(s[1]=='R'||s[1]=='L')be=1;if(!flag&&s[n]=='R')en=n+1;if(!r)en=be-1;cout << be<<" "<<en << endl;return 0;
}
或者这样来
#include <iostream>using namespace std;
const int maxn=1000+5;
char s[maxn];
int main()
{int n;while(cin>>n){for(int i=1;i<=n;i++)cin>>s[i];int be=0,en=0;int flag=0;int x=0,y=0;for(int i=1;i<=n;i++){if(!flag&&(s[i]=='L'||s[i]=='R')){be=i;flag=1;}if(s[i]=='L')y=1;if(s[i]=='R')x++;}if(y)cout << be<<" "<<be+x-1<< endl;elsecout<<be<<" "<<be+x<<endl;}return 0;
}
这篇关于CodeForces - 298A(雪地走步)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!