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( ...
随机推荐
- 浅谈JS的作用域链(二)
上一篇文章中介绍了Execution Context中的三个重要部分:VO/AO,scope chain和this,并详细的介绍了VO/AO在JavaScript代码执行中的表现. 本文就看看Exec ...
- iOS APP 中H5视频默认全屏播放问题解决
问题描述:在Android中,视频可以正常在H5页面局部播放,iOS中则自动切换至全屏模式. 查看资料得以解决,20190301记录下来. 解决方法:IOS10及以后,在 video标签页中只包含 w ...
- 猫咪记单词Beta版使用说明
猫咪记单词Beta版使用说明 一.项目背景 英语四级考试.六级考试.托福.雅思等英语方面的考试是现在大学生必须面对的问题.同时因为学生对手机的使用越来越频繁,而且仅仅通过书本背诵单词又比较无聊坚持的时 ...
- C# wkhtmltopdf 将html转pdf(详解)
https://www.cnblogs.com/louby/p/905198.html转自,看文章只放了代码看起来云里雾里的,在此做些解析 使用说明: 1.首先呢,得安装下软件,地址下面有链接,文件里 ...
- Zookeeper 3.4.8分布式安装
1.机器信息 五台centos 64位机器 2.集群规划 Server Name Hadoop Cluster Zookeeper Ensemble HBase Cluster Hadoop01 ...
- PHP开发:Eclipse版环境配置
软件: 1.eclipse php版本下载地址:http://www.eclipse.org/downloads/packages/eclipse-php-developers/heliosr 2.A ...
- Github链接及git学习心得总结
众所周知GitHub已经是当下非常流行的代码托管库了,全世界有无数的程序员把他们的代码放在GitHub里.那比起云盘之类的工具,用GitHub有什么好处呢:1. 以后在帖子里只需要扔一个链接,大家就能 ...
- spring 注入DI
web 项目的搭建 以注入对象的方式
- Node post请求 通常配合ajax
//处理客户post请求//*1:加载相应模块 http express querystring//*2:创建web服务器//*3:监听端口8080const http = require(" ...
- scipy线性模块liner(linalg)
#liner import numpy as np from scipy import linalg as lg arr=np.array([[1,1],[0,1]]) matr=np.mat('[1 ...