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. 如何获取drawable目录下的图片绝对路径

    Uri uri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + r.getResourcePackage ...

  2. Python web.py 实例和源码分析:

    示例: http://jyd.me/python/cookie-and-session/ simple to do:http://simple-is-better.com/news/309 http: ...

  3. 为什么 HTTP 有时候比 HTTPS 好?

    做为一家安全公司,我们在站点Stormpath上经常被开发者问到的是有关安全方面最优做法的问题.其中一个被经常问到的问题是: 我是否应当在站点上运行HTTPS? 很不幸,查遍整个因特网,你大多数情况下 ...

  4. PHPSTORM实用快捷键

    alt + F7 find usages 功能,可以很方便的找到函数在哪里调用了 Ctrl + E 可查看最近打开文件或项目 项目名右键选择"Local History | Show His ...

  5. 自适应网页设计(Responsive Web Design)(转)

    作者: 阮一峰 出处:http://www.ruanyifeng.com/blog/2012/05/responsive_web_design.html 随着3G的普及,越来越多的人使用手机上网. 移 ...

  6. cocos2dx 利用CCOrbitCamera实现扑克牌翻牌效果

    [cpp] view plaincopy #include "HelloWorldScene.h" #include "SimpleAudioEngine.h" ...

  7. Flexbox属性查询列表

    1.任何一个flexbox布局的第一步是需要创建一个flex容器.为此给元素设置display属性的值为flex.在Safari浏览器中,你依然需要添加前缀-webkit. .flexcontaine ...

  8. CSS投影实现方式

    备用素材: 1.png    shadow.png 第一种方式: 利用负边距实现 最终效果图: <!DOCTYPE html> <html lang="en"&g ...

  9. 在C#、Java中,为什么不能用[返回值]区别重载方法?

    为什么方法签名只包含方法名和参数列表,而没有把返回值考虑进去? 如下有两个方法: void Func(){} string Func() { return string.Empty; } 编辑器可以根 ...

  10. 64位系统 IIS不支持 Excel导入的问题

    64位系统不支持读取excel的问题: 应用程序池-常规选项 启用32应用程序 启用23应用程序是为了保证32应用程序能够正常运行