• <搜索> Rake It In ICPC 2017 Nanning


    The designers have come up with a new simple game called “Rake It In”. Two players, Alice and Bob, initially select an integer k and initialize a score indicator. An 4 × 4 board is created with 16 values placed on the board.
    Starting with player Alice, each player in a round selects a 2 × 2 region of the board, adding the sum of values in the region to the score indicator, and then rotating these four values 90 degrees counterclockwise.
    After 2k rounds in total, each player has made decision in k times. The ultimate goal of Alice is to maximize the final score. However for Bob, his goal is to minimize the final score.
    In order to test how good this game is, you are hired to write a program which can play the game. Specifically, given the starting configuration, they would like a program to determine the final score when both players are entirely rational.

    输入

    The input contains several test cases and the first line provides an integer t (1 ≤ t ≤ 200) which is the number of test cases.
    Each case contains five lines. The first line provides the integer k (1 ≤ k ≤ 3). Each of the following four lines contains four integers indicating the values on the board initially. All values are integers between 1 to 10.

    输出

    For each case, output an integer in a line which is the predicted final score.

    样例输入

    4
    1
    1 1 2 2
    1 1 2 2
    3 3 4 4
    3 3 4 4
    2
    1 2 3 4
    1 2 3 4
    1 2 3 4
    1 2 3 4
    3
    1 1 4 4
    4 4 1 1
    1 1 4 4
    1 4 1 4
    3
    1 2 3 4
    5 1 2 3
    4 5 1 2
    3 4 5 1
    

    样例输出

    20
    40
    63
    71

    不难想到是搜索,但这样有先后手的搜索,还是第一次遇到。而且,这样搜索里带上下界记录答案的方法,也要记录下来...
    #include <iostream>
    #include <bits/stdc++.h>
    using namespace std;
    int a[6][6]={0};
    int sum=0;
    int k;
    void swaparray(int x,int y)
    {
        int temp=a[x][y];
        a[x][y]=a[x][y+1];
        a[x][y+1]=a[x+1][y+1];
        a[x+1][y+1]=a[x+1][y];
        a[x+1][y]=temp;
        sum+=a[x][y]+a[x][y+1]+a[x+1][y]+a[x+1][y+1];
    }
    void restorearray(int x,int y)
    {
        int temp=a[x][y];
        a[x][y]=a[x+1][y];
        a[x+1][y]=a[x+1][y+1];
        a[x+1][y+1]=a[x][y+1];
        a[x][y+1]=temp;
        sum-=a[x][y]+a[x][y+1]+a[x+1][y]+a[x+1][y+1];
    }
     
    int dfs_max(int n,int s1,int s2);
    int dfs_min(int n,int s1,int s2);
    int dfs_min(int n,int s1,int s2)
    {
        if(n==k)
        {
            return sum;
        }
        int sum1=0,sum2=0;
        int i,j,xx,yy;
        for(i=1;i<=3;i++)
        {
            for(j=1;j<=3;j++)
            {
                swaparray(i,j);
                int val=dfs_max(n+1,s1,s2);
                restorearray(i,j);
                if(val<=s1)
                    return s1;
                if(val<s2)
                    s2=val;
            }
        }
        return s2;
    }
    int dfs_max(int n,int s1,int s2)
    {
        if(n==k)
        {
            return sum;
        }
        int i,j,xx,yy;
        for(i=1;i<=3;i++)
        {
            for(j=1;j<=3;j++)
            {
                swaparray(i,j);
                int val=dfs_min(n+1,s1,s2);
                restorearray(i,j);
                if(val>=s2)
                    return s2;
                if(val>s1)
                    s1=val;
            }
        }
        return s1;
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&k);
            k*=2;
            int i,j;
            for(i=1;i<=4;i++)
            {
                for(j=1;j<=4;j++)
                {
                    scanf("%d",&a[i][j]);
                }
            }
            int ans=dfs_max(0,0,10000000);
            printf("%d
    ",ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    Toad 常用快捷键
    Oracle Form删除list项
    不得重新使用的登录口令
    OE_ORDER_PUB.PROCESS_ORDER to Release a hold on sales order in R12
    OE_ORDER_PUB.PROCESS_ORDER to Apply hold on a sales order
    说明性弹性域段
    使用VPD解决EBS中信息屏蔽问题
    Oracle EBS客户化程序中格式化金额
    Form开发中组件控制的几个常用方法
    .Net的差评
  • 原文地址:https://www.cnblogs.com/zyf3855923/p/8763325.html
Copyright © 2020-2023  润新知