Educational Codeforces Round 52D(ARRAY,模拟最短路)
#include<bits/stdc++.h>
using namespace std;
int n,x;
int chess[17*17];//记录棋盘上的number
array<int,2>pace[17*17*3][17*17*3],dp[17*17][3];//first记录root,second记录change
array<int,2>operator+(const array<int,2>a,const array<int,2> b){
return {a[0]+b[0],a[1]+b[1]};
}
int main(){
memset(pace,1,sizeof(pace));//最大为1
memset(dp,1,sizeof(dp));//最大为1
scanf("%d",&n);
for(int i=0;i<n*n;i++){
scanf("%d",&x);
x--;
chess[x]=i;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
for(int k=0;k<3;k++){
for(int l=0;l<3;l++){
pace[(i*n+j)*3+k][(i*n+j)*3+l]={1,1};//i*n后+j可以表示棋盘上n*n的所有位置,*3后可以用一维表示位置和用哪一种棋子走到这里的,不*3多开一维也可以
}
}
for(int k=0;k<n;k++){
for(int l=0;l<n;l++){
if(i==k||j==l)//车一步可以走到
pace[(i*n+j)*3][(k*n+l)*3]={1,0};
else if(abs(i-k)+abs(j-l)==3)//骑士一步可以走到
pace[(i*n+j)*3+2][(k*n+l)*3+2]={1,0};//+1用来区分是谁走的
if(i+j==k+l||i-j==k-l)//皇后一步可以走到
pace[(i*n+j)*3+1][(k*n+l)*3+1]={1,0};//+2用于区分
}
}
}
}
for(int k=0;k<n*n*3;k++){
for(int i=0;i<n*n*3;i++){
for(int j=0;j<n*n*3;j++){
pace[i][j]=min(pace[i][k]+pace[k][j],pace[i][j]);//最短路
}
}
}
dp[0][0]=dp[0][1]=dp[0][2]={};
for(int i=1;i<n*n;i++){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
dp[i][j]=min(dp[i-1][k]+pace[chess[i-1]*3+k][chess[i]*3+j],dp[i][j]);
}
}
}
array<int,2>a=min({dp[n*n-1][0],dp[n*n-1][1],dp[n*n-1][2]});//分别为初始的三种棋子,首先比较第一个元素选取最小,依次比较后续元素选取最小
printf("%d %d",a[0],a[1]);
return 0;
}
Educational Codeforces Round 52D(ARRAY,模拟最短路)的更多相关文章
- [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)
Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...
- Educational Codeforces Round 117 (Rated for Div. 2)
Educational Codeforces Round 117 (Rated for Div. 2) A. Distance https://codeforces.com/contest/1612/ ...
- Educational Codeforces Round 32
http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 58 (Rated for Div. 2) 题解
Educational Codeforces Round 58 (Rated for Div. 2) 题目总链接:https://codeforces.com/contest/1101 A. Min ...
- Educational Codeforces Round 35 A. Nearest Minimums【预处理】
[题目链接]: Educational Codeforces Round 35 (Rated for Div. 2) A. Nearest Minimums time limit per test 2 ...
- Educational Codeforces Round 26
Educational Codeforces Round 26 困到不行的场,等着中午显示器到了就可以美滋滋了 A. Text Volume time limit per test 1 second ...
随机推荐
- java读取pdf文档
import java.io.*;import org.pdfbox.pdmodel.PDDocument;import org.pdfbox.pdfparser.PDFParser;import o ...
- IDT 数据预览查询
前面做了一件非常愚蠢的事情,由于不会预览数据.我都是直接发布到webi去查看的.可以想象一下了.真是太年轻了.为自己感到十分的汗颜. 在数据基础层做好连接之后,可以查看数据基础 .会显示相应的join ...
- codeforces 622B B. The Time
B. The Time time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- 【leetcode刷题笔记】Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...
- swiper轮播 swiper整屏轮播
近期坐了几个移动端 整屏轮播的 效果 之前都是自己一个个写,之前听说过swiper插件,没有使用过,今天一尝试,果然,爽 使用方法示例 <div class="swiper-cont ...
- 2017.10.1北京清北综合强化班DAY1
a[问题描述]你是能看到第一题的 friends 呢.——hja何大爷对字符串十分有研究,于是天天出字符串题虐杀 zhx. 何大爷今天为字符串定义了新的权值计算方法.一个字符串 由小写字母组成,字符串 ...
- 找工作-——网络IO
网络层 主要任务是把网络协议数据单元或分组从源计算机经过适当的路径发送到目的地计算机.从源计算机到目的计算机可能要经过若干个中间节点,这需要在通信子网中进行路由选择. 网络层与数据链路层有很大的差别, ...
- Centos6.5命令行快捷键
ctrl+a打开一个新的终端 ctrl+l 清除屏幕内容 ctrl+a 切换到命令行开始ctrl+e 切换到命令行末尾ctrl+u 剪切光标之前的内容ctrl+k 剪切光标之后的内容 Ctrl+-&g ...
- Azure PIP (Instance Level Public IP)
微软的Azure平台已经支持Instance Level Public IP功能.当有复杂协议的情况下,需要开启多个端口的情况下,可以考虑开启PIP功能. 先介绍几个概念: VIP – virtual ...
- CSS3 日常小结
1. pointer-events:none; 2. flex 今天看到一个牛X的CSS3属性 flex, 称为弹性盒子. 这中属性完全可以替代媒体查询啦 使用方法: 父元素使用属性display ...