AtCoder Beginner Contest 136 D - Gathering Children

我最近做的都是什么shabi题,这道题顶多noip(最近听说ccf给鸽了)Day 1 T2 ,或者noip提高组都不到,像我这么菜只能做普及-的题;


D - Gathering Children

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 400 points

Problem Statement

Given is a string S consisting of L and R.

Let N be the length of S. There are N squares arranged from left to right, and the i-th character of from the left is written on the i-th square from the left.

The character written on the leftmost square is always R, and the character written on the rightmost square is always L.

Initially, one child is standing on each square.

Each child will perform the move below 10100 times:

  • Move one square in the direction specified by the character written in the square on which the child is standing. L denotes left, and R denotes right.

Find the number of children standing on each square after the children performed the moves.

Constraints

  • SS is a string of length between 2 and 105 (inclusive).
  • Each character of S is L or R.
  • The first and last characters of S are R and L, respectively.

Input

Input is given from Standard Input in the following format:

SS

Output

Print the number of children standing on each square after the children performed the moves, in order from left to right.


Sample Input 1 

RRLRL

Sample Output 1 

0 1 2 1 1
  • After each child performed one move, the number of children standing on each square is 0,2,1,1,10,2,1,1,1 from left to right.
  • After each child performed two moves, the number of children standing on each square is 0,1,2,1,10,1,2,1,1 from left to right.
  • After each child performed 1010010100 moves, the number of children standing on each square is 0,1,2,1,10,1,2,1,1 from left to right.

Sample Input 2 

RRLLLLRLRRLL

Sample Output 2 

0 3 3 0 0 0 1 1 0 2 2 0

Sample Input 3 

RRRLLRLLRRRLLLLL

Sample Output 3 

0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0

题目大意:随机输入一个由L,R组成的串串,L表示向左跳跃,R表示向右跳跃,对于每个串串的第一个字符一定是R(因为第一位要向右跳,否则向左岂不是GG),同理最后一位一定是L。
每个位置上最开始有1个跳跳蛙(https://www.luogu.org/space/show?uid=100285),每次跳跃根据自身所在位置的字符方向,每只青蛙最多跳10
100
次,若跳完,他最终停在的位置+1;
求最终的状态;
是不是感觉这道题很水,我的做法是从左向右一组R和一组L进行计算,因为最后只会在分解的两个R,L之间不断跳跃,注意判断一下每组R和L的strlen奇偶性,然后判断实在临界点的R位置+1
还是临界点的L+1;
太水了这道题,我开始把dis算错了,然后又是临界值判断错,菜~~~;
代码如下:
 1 /*
 2 author:cmathpo8&&yuanchen&&qiyujun
 3 date:2019/8/17 10:11 
 4 */
 5 #include
 6 #define re register
 7 using namespace std;
 8 int h[100010],t,cnt;
 9 char a[100010];
10 struct node{
11     int fro;
12     int to;
13 }el[100010];
14 int main(){
15        scanf("%s",a+1);
16        int cntl=0;
17        int sst=strlen(a+1);
18        memset(h,0,sizeof(h));
19        t=-1;
20     for(re int i=1;i<=sst;i++){
21         if(a[i]=='L'){
22             if(t==-1){
23                 el[++cnt].fro=i;
24                 el[cnt].to=i;
25                 t=0;
26             }else el[cnt].to=i;
27         }else t=-1;
28     } 
29     el[0].to=0;
30     for(re int i=1;i<=cnt;i++){
31         int dis=(el[i].fro-el[i-1].to-1);
32         int disl=(el[i].to-el[i].fro+1);
33         if(dis%2==1){
34             h[el[i].fro]+=(dis/2);
35             h[el[i].fro-1]+=(dis/2)+1;
36         }else{
37             h[el[i].fro]+=(dis/2);
38             h[el[i].fro-1]+=(dis/2);
39         }
40         if(disl%2==1){
41             h[el[i].fro-1]+=(disl/2);
42             h[el[i].fro]+=(disl/2)+1;
43         }else{
44             h[el[i].fro-1]+=(disl/2);
45             h[el[i].fro]+=(disl/2);
46         }
47     }
48     for(re int i=1;i<=sst;i++){
49         printf("%d ",h[i]);
50     } 
51     /*for(re int i=1;i<=cnt;i++){
52         cout<53     }*/
54     return 0;
55 }
View Code

如果有更好的,更巧妙的方法欢迎分享啊!!!


 

转载于:https://www.cnblogs.com/cmath-po8/p/11368097.html

你可能感兴趣的:(AtCoder Beginner Contest 136 D - Gathering Children)