zoukankan      html  css  js  c++  java
  • B

    #include <bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    const int Maxn = 1e5+10;
    const int Inf = 0x7f7f7f7f;
    const int Mod = 1e9+7;
    
    int a[Maxn],v[Maxn];
    int l_0[Maxn],r_1[Maxn];
    double ans[Maxn];
    int _1[Maxn],tol1,_0[Maxn],tol0;
    
    int main(){
        int n,l;
        scanf("%d %d",&n,&l);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        for(int i=1;i<=n;i++)
            scanf("%d",&v[i]);
    
        for(int i=1;i<=n;i++)
            if( v[i] == 1 )
                r_1[i] = r_1[i-1] + 1,_1[++tol1] = a[i];
            else r_1[i] = r_1[i-1];
        for(int i=n;i>=1;i--)
            if( v[i] == 0 )
                l_0[i] = l_0[i+1] + 1,_0[++tol0] = a[i];
            else l_0[i] = l_0[i+1];
        
        for(int i=1;i<=n;i++)
        {
            double time,dis;
            int dir;
            if( v[i] == 1 )
            {
                if( l_0[i] >= r_1[i] )
                {
                    int tmp = l_0[i] - r_1[i];
                    dir = 0;
                    dis = 1.0*(_1[1] + _0[tmp + 1])/2;
                    time= -1.0*(_1[1] - _0[tmp + 1])/2;
                }
                else 
                {
                    int tmp = r_1[i] - l_0[i];
                    dir = 1;
                    dis = 1.0*(_1[tmp] + _0[1])/2;
                    time= -1.0*(_1[tmp] - _0[1])/2;
                }
            }
            else 
            {
                if( r_1[i] >= l_0[i] )
                {
                    int tmp = r_1[i] - l_0[i];
                    dir = 1;
                    dis = 1.0*(_1[tmp+1] + _0[1])/2;
                    time= -1.0*(_1[tmp+1] - _0[1])/2;
                }
                else 
                {
                    int tmp = l_0[i] - r_1[i];
                    dir = 0;
                    dis = 1.0*(_1[1] + _0[tmp])/2;
                    time= -1.0*(_1[1] - _0[tmp])/2;
                }
            }
            // cout<<dir<<" "<<dis<<" "<<time<<endl;
            if( dir == 0 )  ans[i] = time + dis;
            else ans[i] = time + l-dis;
        }
        for(int i=1;i<=n;i++)
            printf("%lld ",(ll)(ans[i]+0.5));
        return 0;
    }
    
  • 相关阅读:
    linux基础知识-17
    linux基础知识-16
    linux基础知识-15
    linux基础知识-14
    linux基础知识-13
    phone 调试三种工具
    ANT_HOME is set incorrectly or ant could not be located .Please set ANT_HOME.
    如何解决google ping不通的问题。
    weinre targets none 的问题
    phonegap3.5了结
  • 原文地址:https://www.cnblogs.com/HexQwQ/p/12943393.html
Copyright © 2011-2022 走看看