zoukankan      html  css  js  c++  java
  • Codeforces Round #564 (Div. 2) B. Nauuo and Chess

    链接:https://codeforces.com/contest/1173/problem/B

    题意:

    Nauuo is a girl who loves playing chess.

    One day she invented a game by herself which needs nn chess pieces to play on a m×mm×mchessboard. The rows and columns are numbered from 11 to mm. We denote a cell on the intersection of the rr-th row and cc-th column as (r,c)(r,c).

    The game's goal is to place nn chess pieces numbered from 11 to nn on the chessboard, the ii-th piece lies on (ri,ci)(ri,ci), while the following rule is satisfied: for all pairs of pieces ii and jj, |rirj|+|cicj||ij||ri−rj|+|ci−cj|≥|i−j|. Here |x||x| means the absolute value of xx.

    However, Nauuo discovered that sometimes she couldn't find a solution because the chessboard was too small.

    She wants to find the smallest chessboard on which she can put nn pieces according to the rules.

    She also wonders how to place the pieces on such a chessboard. Can you help her?

    思路:

    构造x*x的矩阵,左上角放1,右下角放n,

    因为(n-x)=(n-x)

    所以矩阵第一行填满1-x,最后一行从右到左填充n-(x+1)。

    代码:

    #include <bits/stdc++.h>
    
    using namespace std;
    
    typedef long long LL;
    const int MAXN = 1e3 + 10;
    const int MOD = 1e9 + 7;
    int n, m, k, t;
    int x, y;
    
    int A[MAXN][MAXN];
    
    int main()
    {
        cin >> n;
        if (n == 1)
        {
            cout << 1 << endl;
            cout << 1 << ' ' << 1 << endl;
            return 0;
        }
        for (int i = 2;i <= n;i++)
            if ((i-1)*2 >= n-1)
            {
                x = y = i;
                break;
            }
        for (int i = 1;i <= x;i++)
            A[1][i] = i;
        for (int i = x, v = n;i >= 1 && v > x;i--,v--)
            A[x][i] = v;
    
        cout << x << endl;
        for (int i = 1;i <= x;i++)
            for (int j = 1;j <= y;j++)
                if (A[i][j] <= n && A[i][j] >= 1)
                    cout << i << ' ' << j << endl;
    
        return 0;
    }
    

      

  • 相关阅读:
    css滑动门技术02
    ASP.NET2.0中创建自定义配置节处理程序(声明性模型)
    怎样看到ASP.NET从ASPX产生的代码?
    PetShop 4.0 详解之六(PetShop表示层设计)
    如何让Office 2003通过正版验证
    在windows 2003中安装mysql5
    Agile PLM 界面操作变慢优化
    Agile PLM 数据库密码修改
    Agile PLM 文件服务器报错解决
    pyautogui
  • 原文地址:https://www.cnblogs.com/YDDDD/p/10990876.html
Copyright © 2011-2022 走看看