COCI2015/2016 Contest#4 F Solution

来源:互联网 发布:教育行业发展分析知乎 编辑:程序博客网 时间:2024/06/03 00:46

Description
On the forest-filled moon of Endor there is, if we are to believe the Guinness Book of Records, the
longest stick in the whole galaxy. On that stick of L meters in length there are N cheerful chameleons.

Each chameleon is moving along the stick with constant speed of 1 m/s in one of two possible directions(left or right) and is colored in one of the possible K colors.

It is known that the chameleons of Endor worship the ancient ant laws that dictate that the walk
along the stick must be continued until the end of the stick is reached (which means getting off it),and when a collision with another chameleon takes place, you must turn 180 degrees and continue
the walk in the opposite direction. Additionally, after a chameleon colored in a moving to the left
collides with a chameleon colored in b moving to the right, the chameleon moving to the left before the collision takes the color of the chameleon moving to the right before the collision (so, color b), while the chameleon moving to the right before the collision takes a new color (a + b) mod K.

If you are given the initial positions, colors and directions of movement of all the chameleons, for each color determine the total trip taken by the chameleons in that color before getting off the stick.

Solution
这题比上题(戳这)要简单数倍==亏它是F题。
一看就知道是一道弹性形变。
向右的会一条道到黑我们把他们视为静止。
然后让向左的以两倍的速度向左移动。
这样的话我们向左扫一发即可。
有个坑就是在到达最后一个静止的点之前的差是不变的,但是到了最后一个点之后还要走一段路,这个不可以丢。
之前就是因为这里写错了导致没A==

#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int M=1e5+5;typedef double db;int n,k,L,post[M*20],run[M*20],last[50];db sum[M],s[M],tp[M];int cnt[M],tmp[M];inline int Mod(int a){return a>=k?a-k:a;}int main(){    cin>>n>>k>>L;    char opt[10];    memset(post,-1,sizeof(post));    memset(run,-1,sizeof(run));    memset(last,-1,sizeof(last));    int st=-1;    int p[10];    for(int i=1,dis,clr;i<=n;++i){        scanf("%d %d %s",&dis,&clr,opt);        switch(opt[0]){            case('D'):                post[dis]=clr;                sum[clr]+=L-dis;                if(st==-1)st=dis;                break;            case('L'):                if(st==-1)sum[clr]+=dis;                run[dis]=clr;                break;        }    }    for(int i=L;i>=st;--i){        for(int c=0;c<k;++c)            sum[c]+=0.5*cnt[c];        if(~run[i]){            ++cnt[run[i]];            s[run[i]]+=(double)(st+i)/2.0;        }        if(~post[i]){            for(int c=0;c<k;++c){                tmp[Mod(c+post[i])]=cnt[c];                tp[Mod(c+post[i])]=s[c];            }            for(int c=0;c<k;++c){                cnt[c]=tmp[c];tmp[c]=0;                s[c]=tp[c];tp[c]=0;            }        }//变色     }    for(int c=0;c<k;++c)        sum[c]+=(double)s[c];    for(int i=0;i<k;++i)        printf("%.1lf\n",(double)sum[i]);    return 0;}/**************************************************************    Problem: 1791    User: bblss123    Language: C++    Result: 正确    Time:200 ms    Memory:20448 kb****************************************************************/
0 0