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的更多相关文章

  1. CF 366E Dima and Magic Guitar(最远哈密顿距离)

    题目链接:http://codeforces.com/problemset/problem/366/E 题意:给出一个n*m的数字矩阵A,每个矩阵元素的范围[1,K].给出一个长度为s的数字串B,B的 ...

  2. CF 366E - Dima and Magic Guitar 最远曼哈顿距离

    题目:http://codeforces.com/problemset/problem/366/E 事实上就是找 n * m 矩阵中数字 x 和 数字 y 的最远距离. 方法參照武森的论文<浅谈 ...

  3. Dima and Magic Guitar CodeForces - 366E

    Dima and Magic Guitar CodeForces - 366E 题意: http://blog.csdn.net/u011026968/article/details/38716425 ...

  4. cf D. Dima and Trap Graph

    http://codeforces.com/contest/366/problem/D 遍历下界,然后用二分求上界,然后用dfs去判断是否可以. #include <cstdio> #in ...

  5. cf C. Dima and Salad

    http://codeforces.com/contest/366/problem/C 转化为背包问题,可以将a[i]-b[i]*k看成重量,a[i]为价值: 因为a[i]-b[i]*k可以为负数,所 ...

  6. 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 ...

  7. cf D. Dima and Hares

    http://codeforces.com/contest/358/problem/D 题意:ai代表相邻的两个野兔都没有吃食物情况下的快乐系数,bi代表的是在相邻的两个野兔中有一个吃到食物的快乐系数 ...

  8. cf C. Dima and Containers

    http://codeforces.com/contest/358/problem/C 将最大的放在stack里面,第二大的放在queue中,第三大的放在deck里面.然后模拟就可以了. #inclu ...

  9. cf B. Dima and Text Messages

    http://codeforces.com/contest/358/problem/B 先按照题意说的构造一个字符串s,然后与对比的字符串T比较,看看在字符串T中顺序查找有没有字符串S的所有字符,有输 ...

随机推荐

  1. v4l2采集视频和图片源码

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h&g ...

  2. 新博客——That

    很久没写博客了,打算换个地方重新开始. 旧博客地址如下: http://blog.csdn.net/that163

  3. LeetCode - 204. Count Primes - 埃拉托斯特尼筛法 95.12% - (C++) - Sieve of Eratosthenes

    原题 原题链接 Description: Count the number of prime numbers less than a non-negative number, n. 计算小于非负数n的 ...

  4. CASE工具

    1.Rational Rose和PowerDesigner建模工具 作为世界最著名的两大CASE工具,Rational Rose和PowerDesigner的名声可谓如雷贯耳.Rose是当时全球最大的 ...

  5. struts2.1.*中再实现了一个servlet的方法

    学习Struts2也有一段时间了,今天用Servlet写了一个验证码,然后搬到Struts2中,惊奇地发现Servlet无法访问,出现404错误!后来折腾了半天,终于找出原因了.这也算我学习中的一个重 ...

  6. C++中的四种转型操作符

    在具体介绍C++中的四种转型操作符之前,我们先来说说旧式转型的缺点: ①它差点儿同意将不论什么类型转换为不论什么其它类型,这是十分拙劣的.假设每次转型都可以更精确地指明意图,则更好. ②旧式转型难以辨 ...

  7. iOS 捕获系统外异常

    iOS 捕获系统外异常 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太 ...

  8. Android中BroadCast与Activity之间的通信

    在看本文之前,假设你对于Android的广播机制不是非常了解.建议先行阅读我转载的一篇博文:图解 Android 广播机制. 因为本案例比較简单,故直接在此贴出代码,不做过多的阐述. 先上效果截图: ...

  9. mvc中使用jsonp进行跨域请求详细说明

    在web开发中,如果你要在不同域下进行数据异步请求,会出现一个No ‘Access-Control-Allow-Origin’ header is present on the requested r ...

  10. smbpasswd命令常用选项

    smbpasswd命令的常用方法 smbpasswd -a 增加用户(该账户必须存在于/etc/passwd文件中)smbpasswd -d 冻结用户,就是这个用户不能在登录了smbpasswd -e ...