Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path
http://codeforces.com/contest/1072/problem/D
bfs
走1步的最佳状态 -> 走2步的最佳状态 -> ……
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf 1e9
#define pi 3.1415926536
#define nl 2.7182818284
const ll mod=1e9+;//
const int maxn=2e3+; struct node
{
int x,y;
}q[maxn*][maxn]; int ci[maxn][maxn],g[maxn*];
char ch[maxn][maxn],s[maxn][maxn],str[maxn*]; int main()
{
int n,maxci,x,y,c,xx,yy,u,v,i,ii,j;
scanf("%d%d",&n,&maxci);
for (i=;i<=n;i++)
scanf("%s",s[i]+);
for (i=;i<=n;i++)
for (j=;j<=n;j++)
ch[i][j]='z'+; g[]=,q[][].x=,q[][].y=;
if (maxci== && s[][]!='a')
{
ci[][]=;
ch[][]=s[][];
}
else
{
ci[][]=maxci-(s[][]!='a');
ch[][]='a';
}
printf("%c",ch[][]); for (i=;i<=n+n-;i++)
{
ii=i-;
for (j=;j<=g[ii];j++)
{
x=q[ii][j].x;
y=q[ii][j].y;
c=ci[x][y];
if (x!=n)
{
xx=x+;
yy=y; if (c== && s[xx][yy]!='a')
{
u=;
v=s[xx][yy];
}
else
{
u=c-(s[xx][yy]!='a');
v='a';
} if (v<ch[xx][yy] || (v==ch[xx][yy] && u>ci[xx][yy]))
ci[xx][yy]=u,ch[xx][yy]=v;
} if (y!=n)
{
xx=x;
yy=y+; if (c== && s[xx][yy]!='a')
{
u=;
v=s[xx][yy];
}
else
{
u=c-(s[xx][yy]!='a');
v='a';
} if (v<ch[xx][yy] || (v==ch[xx][yy] && u>ci[xx][yy]))
ci[xx][yy]=u,ch[xx][yy]=v;
}
} v='z';
for (x=;x<=n;x++)
{
y=i+-x;
if (y>= && y<=n && ch[x][y]!='z'+)
{
if (ch[x][y]<v)
{
v=ch[x][y];
g[i]=;
q[i][].x=x,q[i][].y=y;
}
else if (ch[x][y]==v)
{
g[i]++;
q[i][g[i]].x=x,q[i][g[i]].y=y;
}
}
}
printf("%c",v);
}
return ;
}
Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path的更多相关文章
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)
Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)
https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)D(思维,DP,字符串)
#include<bits/stdc++.h>using namespace std;char c[2007][2007];char ans[4007];int s[2007][2007] ...
- (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round
A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】
传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...
- Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket 【。。。】
任意门:http://codeforces.com/contest/1058/problem/C C. Vasya and Golden Ticket time limit per test 1 se ...
- Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences(DP)
题目链接:http://codeforces.com/contest/1058/problem/E 题意:给出 n 个数,对于一个选定的区间,区间内的数可以通过重新排列二进制数的位置得到一个新的数,问 ...
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup
题意:把一长串字符串 排成矩形形式 使得行最小 同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可 每行不能相差大于等于两个字符相当于 ...
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) C. Playing Piano
题意:给出一个数列 a1 a2......an 让你构造一个序列(该序列取值(1-5)) 如果a(i+1)>a(i) b(i+1)>b(i) 如果a(i+1)<a(i) 那么b( ...
随机推荐
- devstack 安装(centos7)
1. 创建devstack用户 sudo useradd -s /bin/bash -d /opt/stack -m stackecho "stack ALL=(ALL) NOPASSWD: ...
- sublime text3 安装package control 出现问题解决过程记录
1.安装package control 失败 通过最简单的自动安装 package control 失败(详见package control官网). 报错展示: File "./python ...
- 【2016.4.6】结对编程 终章 THE END
- maven依赖的描述
maven的坐标和依赖 坐标和依赖,主要涉及的就是pom文件的头部和<dependencies>标签部分(1)pom文件的头部 这里头部不是指pom文件的开头<project> ...
- JS创建事件的三种方式(实例)
1.普通的定义方式 <input type="button" name="Button" value="确定" onclick=&qu ...
- stratMove方法
/* * elem: 操作哪一个元素 * json:表示多个属性 * attr: 操作的那个元素的css中的什么属性 * value: 操作的那个元素的css中的那个属性的目标值 * cb:回调函数, ...
- TCP 三次握手理解和过程
1:TCP为什么要三次握手,不是两次四次? 2:TCP协议三次握手过程分析
- Win10 1803 Spring Creators update Consumer edition的版本记录
安装时可选择的版本列表 安装完之后的版本: 3. 时间线更新 4. Focus assistant
- ACDsee的安装过程
http://www.ddooo.com/softdown/76175.htm ACDSee 18中文版安装教程: 1.ACDSee 18分为32位和64位版本,我们先选择合适系统的中文版本开始安装, ...
- 好文章之——PHP系列(一)
注:最近实习的公司是一家做电商企业,后台主要是php开发,好久不怎么接触php的我看了几篇相关文章,提高下对它的认识与理解,发现里面的学习思路还是非常好的,当然也会重新拾一下基础知识啦! 其实自己心中 ...