zoukankan      html  css  js  c++  java
  • ZJNU 1370

    ZJNU 1370 - 飙车

    题面

    des


    思路

    由于是双向行驶,所以如果我们假设其余跑车都不动,那么每次跑车在(Y)方向上会行驶两格

    于是根据题意模拟即可,如果某一秒赛车换道了,那就判断到达的点是否有赛车即可,最多会有一次碰撞

    如果不换道,可能会产生两次碰撞

    使用(dp[i][j])表示跑车实际开到(Y=i),此时在第(j)道上的最少碰撞次数

    双向行驶,所以实际上跑车开到(Y=lfloorfrac n 2 floor +1)即可得出答案


    #include<bits/stdc++.h>
    #define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
    #define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
    #define rep(i,a,b) for(int i=(a);i<=(b);i++)
    #define repp(i,a,b) for(int i=(a);i<(b);i++)
    #define per(i,a,b) for(int i=(a);i>=(b);i--)
    #define perr(i,a,b) for(int i=(a);i>(b);i--)
    #define all(a) (a).begin(),(a).end()
    #define SUM(a) accumulate(all(a),0LL)
    #define MIN(a) (*min_element(all(a)))
    #define MAX(a) (*max_element(all(a)))
    #define mst(a,b) memset(a,b,sizeof(a))
    #define pb push_back
    #define eb emplace_back
    #define fi first
    #define se second
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int,int> pii;
    const int INF=0x3f3f3f3f;
    const ll LINF=0x3f3f3f3f3f3f3f3f;
    const double eps=1e-12;
    const double PI=acos(-1.0);
    const ll mod=998244353;
    const int dx[8]={0,1,0,-1,1,1,-1,-1},dy[8]={1,0,-1,0,1,-1,1,-1};
    void debug(){cerr<<'
    ';}template<typename T,typename... Args>void debug(T x,Args... args){cerr<<"[ "<<x<< " ] , ";debug(args...);}
    mt19937 mt19937random(std::chrono::system_clock::now().time_since_epoch().count());
    ll getRandom(ll l,ll r){return uniform_int_distribution<ll>(l,r)(mt19937random);}
    ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
    ll qmul(ll a,ll b){ll r=0;while(b){if(b&1)r=(r+a)%mod;b>>=1;a=(a+a)%mod;}return r;}
    ll qpow(ll a,ll n){ll r=1;while(n){if(n&1)r=(r*a)%mod;n>>=1;a=(a*a)%mod;}return r;}
    ll qpow(ll a,ll n,ll p){ll r=1;while(n){if(n&1)r=(r*a)%p;n>>=1;a=(a*a)%p;}return r;}
    
    int n,m;
    char mp[105][105];
    int dp[105][105];
    
    void solve()
    {
        cin>>n>>m;
        rep(i,1,n)
            cin>>mp[i]+1;
        mst(dp,INF);
        rep(j,1,m)
            dp[n+1][j]=0;
        for(int i=n;i>=n/2+1;i--)
        {
            int a=n-(n-i)*2-1,b=a+1; //a表示这一次赛车相对其他赛车开到的位置,假设其余赛车不动
            rep(j,1,m)
            {
                if(j-1>=1)
                    dp[i][j]=min(dp[i][j],dp[i+1][j-1]+(mp[a][j]-'0'));
                if(j+1<=m)
                    dp[i][j]=min(dp[i][j],dp[i+1][j+1]+(mp[a][j]-'0'));
                dp[i][j]=min(dp[i][j],dp[i+1][j]+(mp[a][j]-'0')+(mp[b][j]-'0'));
            }
        }
        cout<<*min_element(dp[n/2+1]+1,dp[n/2+1]+m+1)<<'
    ';
    }
    int main()
    {
        closeSync;
        //multiCase
        {
            solve();
        }
        return 0;
    }
    

  • 相关阅读:
    Nancy 寄宿IIS
    原子操作
    CSRF跨站请求伪造
    CORS跨域
    C# 运算符
    Mysql 函数
    Mongodb for .Net Core 驱动的应用
    Mongodb for .Net Core 封装类库
    制作项目模板
    压缩图片
  • 原文地址:https://www.cnblogs.com/stelayuri/p/15138207.html
Copyright © 2011-2022 走看看