cf E. Dima and Magic Guitar
http://codeforces.com/contest/366/problem/E
|x1-x2|+|y1-y2|有四种情况
1.-(x1-x2)+(y1-y2);
2.(x1-x2)-(y1-y2);
3.-(x1-x2)-(y1-y2);
4.(x1-x2)+(y1-y2);
可以先把没一个数的坐标分为上面的四种情况存起来,然后在S序列相邻的两个数的曼哈顿距离最大就是两个数中的一个数的四种情况最大值减去另一个数的最小值。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#define maxn 20000
using namespace std;
const int inf=<<; int n,m,k,s;
int a[maxn];
int g[][][]; int main()
{
while(scanf("%d%d%d%d",&n,&m,&k,&s)!=EOF)
{
for(int i=; i<=k; i++)
{
for(int j=; j<; j++)
{
g[i][j][]=-inf;
g[i][j][]=inf;
}
}
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
int c;
scanf("%d",&c);
g[c][][]=max(g[c][][],i+j);
g[c][][]=min(g[c][][],i+j);
g[c][][]=max(g[c][][],-i+j);
g[c][][]=min(g[c][][],-i+j);
g[c][][]=max(g[c][][],-i-j);
g[c][][]=min(g[c][][],-i-j);
g[c][][]=max(g[c][][],i-j);
g[c][][]=min(g[c][][],i-j);
}
}
int x;
scanf("%d",&x);
int last=x;
int max1=;
for(int i=; i<=s; i++)
{
scanf("%d",&x);
for(int j=; j<; j++)
{
max1=max(max1,abs(g[x][j][]-g[last][j][]));
max1=max(max1,abs(g[x][j][]-g[last][j][]));
}
last=x;
}
printf("%d\n",max1);
}
return ;
}
cf E. Dima and Magic Guitar的更多相关文章
- CF 366E Dima and Magic Guitar(最远哈密顿距离)
题目链接:http://codeforces.com/problemset/problem/366/E 题意:给出一个n*m的数字矩阵A,每个矩阵元素的范围[1,K].给出一个长度为s的数字串B,B的 ...
- CF 366E - Dima and Magic Guitar 最远曼哈顿距离
题目:http://codeforces.com/problemset/problem/366/E 事实上就是找 n * m 矩阵中数字 x 和 数字 y 的最远距离. 方法參照武森的论文<浅谈 ...
- Dima and Magic Guitar CodeForces - 366E
Dima and Magic Guitar CodeForces - 366E 题意: http://blog.csdn.net/u011026968/article/details/38716425 ...
- cf D. Dima and Trap Graph
http://codeforces.com/contest/366/problem/D 遍历下界,然后用二分求上界,然后用dfs去判断是否可以. #include <cstdio> #in ...
- cf C. Dima and Salad
http://codeforces.com/contest/366/problem/C 转化为背包问题,可以将a[i]-b[i]*k看成重量,a[i]为价值: 因为a[i]-b[i]*k可以为负数,所 ...
- cf B. Dima and To-do List
http://codeforces.com/contest/366/problem/B 从0到k枚举起点,然后i+k判断是不是i+k>=n如果是i=(i+k)%n;否则i=i+k; #inclu ...
- cf D. Dima and Hares
http://codeforces.com/contest/358/problem/D 题意:ai代表相邻的两个野兔都没有吃食物情况下的快乐系数,bi代表的是在相邻的两个野兔中有一个吃到食物的快乐系数 ...
- cf C. Dima and Containers
http://codeforces.com/contest/358/problem/C 将最大的放在stack里面,第二大的放在queue中,第三大的放在deck里面.然后模拟就可以了. #inclu ...
- cf B. Dima and Text Messages
http://codeforces.com/contest/358/problem/B 先按照题意说的构造一个字符串s,然后与对比的字符串T比较,看看在字符串T中顺序查找有没有字符串S的所有字符,有输 ...
随机推荐
- PL/SQL 0.几秒出结果,SQL效率一定高吗?
今天开发问我一个问题,PL/SQL很快出结果了,为什么应用还是很慢 create index F_AGT_SAVB_ACCTINFO_H_idx4 on F_AGT_SAVB_ACCTINFO_H ( ...
- 开启Apache mod_rewrite模块(解决404 Not Found)
网站搭建完成了,进入登录界面就是访问不了. 原因大概是没有开启Apache mod_rewrite模块,或者没有配置完全. 步骤1: 启用mod_rewrite模块 在conf目录的httpd.con ...
- Highcharts 异步加载数据曲线图表
导入 data.js 文件 异步加载数据需要引入以下js 文件: <script src="http://code.highcharts.com/modules/data.js&quo ...
- StoryBoard 页面传值
如图新建一个viewController和DetailViewController VC 和DetailVC 联线的Idetnifier 设置为:GoDetailVC ViewController主要 ...
- 转载:mybatis和hibernate 解析
第一章 Hibernate与MyBatis Hibernate 是当前最流行的O/R mapping框架,它出身于sf.net,现在已经成为Jboss的一部分. Mybatis 是另外一种优秀 ...
- android音乐播放器开发 SweetMusicPlayer 实现思路
一,实现效果 眼下还不是特别完好,主要有下面几个功能, 1,载入歌曲列表(实现a-z字母检索) 2,播放本地音乐 3.智能匹配本地歌词 4.智能载入在线歌词(事实上不算智能.发现歌词迷api提供的歌词 ...
- Python 文件I/O (转)
Python 文件I/O 本章只讲述所有基本的的I/O函数,更多函数请参考Python标准文档. 打印到屏幕 最简单的输出方法是用print语句,你可以给它传递零个或多个用逗号隔开的表达式.此函数把你 ...
- thinkphp 中 使用七牛云上传
利用七牛云私有空间存储文件 第一步,注册七牛云,创建空间,将空间设为私有 需要记下的东西: AK,SK,bucket 第二步配置ThinkPHP 在config.php添加 'UPLOAD_SITEI ...
- Android -------- 网络访问数据
- 【nodejs学习】3.进程管理及异步编程
进程管理 1.调用终端命令实现目录目录拷贝 var child_procress = require('child_procress'); var util = require('util'); fu ...