题解:P8048 [COCI 2015/2016 #4] ENDOR
P8048 [COCI 2015/2016 #4] ENDOR
模拟赛写正解发现思路错了,所以来补篇题解。
首先我们考虑
- 我们可以不处理反弹,而是把两个碰撞的变色龙看作互相穿过。
- 于是在两个变色龙相遇相遇后:
- 向右的看作不变。
- 而向左的变色龙颜色变为
(a+b) \bmod k 。
:::info[写完暴力我们发现瓶颈在于:] 对于每个向左走的变色龙都需要把所有在它前面的向右走的变色龙给扫一下来计算答案。 :::
我们考虑优化,但是我们发现计算答案的
- 我们发现每一个向左的变色龙总是从右到左依次和在它左边的变色龙碰撞。
- 在经过同一个向右的变色龙时,相同颜色的变色龙行为相同所以我们尝试统一处理。
Ac Code:
#include <bits/stdc++.h>
using namespace std;
#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc _getchar_nolock
#define pc _putchar_nolock
#endif
#define rint register int
#define int long long
#define _ read<int>()
#define R register
inline bool blank(const char &x)
{
return !(x^10)||!(x^9)||!(x^32)||!(x^13);
}
template<class T>inline T read()
{
R T r=0,f=1;R char c=gc();
while(!isdigit(c))
{
if(c=='-') f=-1;
c=gc();
}
while(isdigit(c)) r=(r<<1)+(r<<3)+(c^48),c=gc();
return f*r;
}
inline void out(rint x)
{
if(x<0) pc('-'),x=-x;
if(x<10) pc(x+'0');
else out(x/10),pc(x%10+'0');
}
inline void read(R char &x)
{
for(x=gc();blank(x)&&(x^-1);x=gc());
}
const int N=1e5+10;
struct oi
{
int d,cl;
}a[N],b[N];
int cntl,cntr,r[N],lastc,lastd,sd;
double ans[50],cnt[50];
signed main()
{
rint n=_,k=_,L=_;
for(rint i=1;i<=n;i++)
{
rint d=_,cl=_;
R char c;
read(c);
if(c=='D')
{
if(sd) cnt[lastc]+=(d-lastd)*0.5;
else sd=d;
ans[cl]+=L-d;
lastc=(lastc+cl)%k;
lastd=d;
}
else
{
ans[cl]+=d-(d+lastd)*0.5;
ans[(cl+lastc)%k]+=(d+sd)*0.5;
for(rint j=0;j<=k;j++) ans[j]+=cnt[(cl+lastc-j+k)%k];
}
}
for(rint i=0;i<k;i++)
{
printf("%.1lf",ans[i]);
pc('\n');
}
return 0;
}