IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 游戏开发 -> E. Gojou and Matrix Game -> 正文阅读

[游戏开发]E. Gojou and Matrix Game

Problem - E - Codeforces

E. Gojou and Matrix Game

time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Marin feels exhausted after a long day of cosplay, so Gojou invites her to play a game!

Marin and Gojou take turns to place one of their tokens on an?n×nn×n?grid with Marin starting first. There are some restrictions and allowances on where to place tokens:

  • Apart from the first move, the token placed by a player must be more than Manhattan distance?kk?away from the previous token placed on the matrix. In other words, if a player places a token at?(x1,y1)(x1,y1), then the token placed?by the other player?in the next move must be in a cell?(x2,y2)(x2,y2)?satisfying?|x2?x1|+|y2?y1|>k|x2?x1|+|y2?y1|>k.
  • Apart from the previous restriction, a token can be placed anywhere on the matrix,?including cells where tokens were previously placed by any player.

Whenever a player places a token on cell?(x,y)(x,y), that player gets?vx,?yvx,?y?points. All values of?vv?on the grid are?distinct. You still get points from a cell even if tokens were already placed onto the cell. The game finishes when each player makes?1010010100?moves.

Marin and Gojou will play?n2n2?games. For each cell of the grid, there will be exactly one game where Marin places a token on that cell on her first move. Please answer for each game, if Marin and Gojou play optimally (after Marin's first move), who will have more points at the end? Or will the game end in a draw (both players have the same points at the end)?

Input

The first line contains two integers?nn,?kk?(3≤n≤20003≤n≤2000,?1≤k≤n?21≤k≤n?2). Note that under these constraints it is always possible to make a move.

The following?nn?lines contains?nn?integers each. The?jj-th integer in the?ii-th line is?vi,jvi,j?(1≤vi,j≤n21≤vi,j≤n2). All elements in?vv?are distinct.

Output

You should print?nn?lines. In the?ii-th line, print?nn?characters, where the?jj-th character is the result of the game in which Marin places her first token in the cell?(i,j)(i,j). Print 'M' if Marin wins, 'G' if Gojou wins, and 'D' if the game ends in a draw. Do not print spaces between the characters in one line.

Example

input

Copy

3 1
1 2 4
6 8 3
9 5 7

output

Copy

GGG
MGG
MGG

?

#include <bits/stdc++.h>

using i64 = long long;
constexpr int inf=1E9;

int main() {
	//freopen("in.txt","r",stdin);
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n, k;
	std::cin >> n >> k;

	std::vector<std::vector<int>> v(n, std::vector<int>(n));
    std::vector<std::array<int, 2>> pos(n*n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            std::cin>>v[i][j];
            v[i][j]--;
            pos[v[i][j]]={i,j};
        }
    }

    int pp=-inf,pn=-inf,np=-inf,nn=-inf;
    std::vector<std::string> ans(n,std::string(n,'G'));
    for(int i=n*n-1;i>=0;i--){
        auto [x,y]=pos[i];
        if(pp>x+y+k||pn>x-y+k||np>-x+y+k||nn>-x-y+k){continue;}
        ans[x][y]='M';
        pp=std::max(pp,x+y);
        pn=std::max(pn,x-y);
        np=std::max(np,-x+y);
        nn=std::max(nn,-x-y);
    }

    for(int i=0;i<n;i++)
        std::cout<<ans[i]<<"\n";
	return 0;
}

首先,找到肯定赢的位置,然后逐步扩散O(n)

https://codeforces.com/blog/entry/101302?

这里还要转换一下距离的比较方式?

  游戏开发 最新文章
6、英飞凌-AURIX-TC3XX: PWM实验之使用 GT
泛型自动装箱
CubeMax添加Rtthread操作系统 组件STM32F10
python多线程编程:如何优雅地关闭线程
数据类型隐式转换导致的阻塞
WebAPi实现多文件上传,并附带参数
from origin ‘null‘ has been blocked by
UE4 蓝图调用C++函数(附带项目工程)
Unity学习笔记(一)结构体的简单理解与应用
【Memory As a Programming Concept in C a
上一篇文章      下一篇文章      查看所有文章
加:2022-03-30 18:59:49  更:2022-03-30 19:05:17 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2025年1日历 -2025/1/16 17:55:40-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码