codeforce 298 A Snow Footprints
2013-04-21 00:10
253 查看
A. Snow Footprints
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from
left to right. If one moves from the i-th block to the (i + 1)-th
block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th
block to the (i - 1)-th block, he will leave a left footprint on the i-th
block. If there already is a footprint on the i-th block, the new footprint will cover the old one.
At the beginning, there were no footprints. Then polar bear Alice starts from the s-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 of s, t by looking at the footprints.
Input
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 of n 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.
Output
Print two space-separated integers — the values of s and t.
If there are several possible solutions you can print any of them.
Sample test(s)
input
output
input
output
Note
The first test sample is the one in the picture.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
char input[1010];
int r1=0,r2=0,l1=0,l2=0;
void getr()
{
int i;
for(i=0;i<strlen(input);i++)
{
if(input[i]=='R')
{
r1=i;
break;
}
}
if(i==strlen(input))
{
r1=-1;
r2=-1;
return;
}
else
{
for(i=strlen(input)-1;i>=0;i--)
{
if(input[i]=='R')
{
r2=i;
break;
}
}
}
}
void getl()
{
int i;
for(i=strlen(input)-1;i>=0;i--)
{
if(input[i]=='L')
{
l2=i;
break;
}
}
if(i<0)
{
l1=-1;
l2=-1;
return;
}
else
{
for(i=0;i<strlen(input);i++)
{
if(input[i]=='L')
{
l1=i;
break;
}
}
}
}
void solve()
{
if(r1==-1)
{
printf("%d %d\n",l2+1,l1);
}
else if(l2==-1)
{
printf("%d %d\n",r1+1,r2+2);
}
else
{
printf("%d %d\n",r1+1,r2+1);
}
}
int main(int argc, char *argv[])
{
//freopen("data.in","r",stdin);
int len;
while(scanf("%d",&len)!=EOF)
{
scanf("%s",input);
getr();
getl();
solve();
}
return 0;
}
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from
left to right. If one moves from the i-th block to the (i + 1)-th
block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th
block to the (i - 1)-th block, he will leave a left footprint on the i-th
block. If there already is a footprint on the i-th block, the new footprint will cover the old one.
At the beginning, there were no footprints. Then polar bear Alice starts from the s-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 of s, t by looking at the footprints.
Input
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 of n 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.
Output
Print two space-separated integers — the values of s and t.
If there are several possible solutions you can print any of them.
Sample test(s)
input
9 ..RRLL...
output
3 4
input
11 .RRRLLLLL..
output
7 5
Note
The first test sample is the one in the picture.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
char input[1010];
int r1=0,r2=0,l1=0,l2=0;
void getr()
{
int i;
for(i=0;i<strlen(input);i++)
{
if(input[i]=='R')
{
r1=i;
break;
}
}
if(i==strlen(input))
{
r1=-1;
r2=-1;
return;
}
else
{
for(i=strlen(input)-1;i>=0;i--)
{
if(input[i]=='R')
{
r2=i;
break;
}
}
}
}
void getl()
{
int i;
for(i=strlen(input)-1;i>=0;i--)
{
if(input[i]=='L')
{
l2=i;
break;
}
}
if(i<0)
{
l1=-1;
l2=-1;
return;
}
else
{
for(i=0;i<strlen(input);i++)
{
if(input[i]=='L')
{
l1=i;
break;
}
}
}
}
void solve()
{
if(r1==-1)
{
printf("%d %d\n",l2+1,l1);
}
else if(l2==-1)
{
printf("%d %d\n",r1+1,r2+2);
}
else
{
printf("%d %d\n",r1+1,r2+1);
}
}
int main(int argc, char *argv[])
{
//freopen("data.in","r",stdin);
int len;
while(scanf("%d",&len)!=EOF)
{
scanf("%s",input);
getr();
getl();
solve();
}
return 0;
}
相关文章推荐
- Code Force 21B Intersection
- codeforce之 Bear and Colors
- codeforce 379(div.2)
- codeforce 675C Money Transfers (思维)
- CodeForce-245B-Internet Address
- codeforce 5B Center Alignment
- codeforce-600C. Make Palindrome(贪心)
- codeforce Maximum of Maximums of Minimums(区间划分 求区间最小值最大值问题)
- codeforce 67D - Optical Experiment(dp)
- CodeForce 526B Om Nom and Dark Park(dp + 递归)
- codeforce #387 D. Winter Is Coming
- codeforce 17 B
- CodeForce 448C 木片填涂问题
- Codeforce Gym 100015I Identity Checker 暴力
- Codeforce 527D Clique Problem题解
- Mushroom Scientists(Codeforce)
- codeforce 121E - Lucky Array
- Salesforce to Salesforce Config&Code实现
- Codeforce - 402C - Searching for Graph
- codeforce #126Div2 200A Cinema 【优化暴力枚举】