zoukankan      html  css  js  c++  java
  • bzoj1413: [ZJOI2009]取石子游戏

    ORZ

    做法跟网上是一样的,自己照着手推一次好了。

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    
    int a[1100],L[1100][1100],R[1100][1100];
    int main()
    {
        freopen("a.in","r",stdin);
        freopen("a.out","w",stdout);
        int T;
        scanf("%d",&T);
        while(T--)
        {
            int n;
            scanf("%d",&n);
            for(int i=1;i<=n;i++)
                scanf("%d",&a[i]),L[i][i]=R[i][i]=1;
                
            for(int C=1;C<=n;C++)
                for(int l=1;l<=n;l++)
                {
                    int r=l+C-1;if(r>n)break;
                    
                    if(R[l][r-1]==a[r])L[l][r]=0;
                    else if(L[l][r-1]> a[r]&&R[l][r-1]>a[r])L[l][r]=a[r];
                    else if(L[l][r-1]> a[r]&&R[l][r-1]<a[r])L[l][r]=a[r]-1;
                    else if(L[l][r-1]<=a[r]&&R[l][r-1]>a[r])L[l][r]=a[r]+1;
                    else if(L[l][r-1]< a[r]&&R[l][r-1]<a[r])L[l][r]=a[r];
                    
                    if(L[l+1][r]==a[l])R[l][r]=0;
                    else if(R[l+1][r]> a[l]&&R[l+1][r]>a[l])R[l][r]=a[l];
                    else if(R[l+1][r]> a[l]&&R[l+1][r]<a[l])R[l][r]=a[l]-1;
                    else if(R[l+1][r]<=a[l]&&R[l+1][r]>a[l])R[l][r]=a[l]+1;
                    else if(R[l+1][r]< a[l]&&R[l+1][r]<a[l])R[l][r]=a[l];
                }
            printf("%d
    ",(L[2][n]==a[1])?0:1);
        }
        return 0;
    }
  • 相关阅读:
    多线程---同步函数的锁是this(转载)
    函数
    流程控制
    基本语句和运算
    基本数据库类型
    迷宫问题
    Dungeon Master(逃脱大师)-BFS
    HTML元素常用属性整理
    Java_hutool 发起请求
    jQuery Autocomplete
  • 原文地址:https://www.cnblogs.com/AKCqhzdy/p/10184461.html
Copyright © 2011-2022 走看看