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. [LeetCode] 179. Largest Number 解题思路

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  2. SQL-Customers Who Never Order

    Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...

  3. Linux之V4L2视频采集编程详解

     V4L2(Video For Linux Two) 是内核提供给应用程序访问音.视频驱动的统一接口. Linux系统中,视频设备被当作一个设备文件来看待,设备文件存放在 /dev目录下,完整路径的设 ...

  4. 深入理解linux网络技术内幕读书笔记(十)--帧的接收

    Table of Contents 1 概述 1.1 帧接收的中断处理 2 设备的开启与关闭 3 队列 4 通知内核帧已接收:NAPI和netif_rx 4.1 NAPI简介 4.1.1 NAPI优点 ...

  5. 最牛逼的的shell命令

    参考 远程diff [root@jiangyi01.sqa.zmf /home/ahao.mah/ALIOS_QA/tools/iperf] #ssh ahao.mah@dnstest02.tbc c ...

  6. HTML5 简单实现刮刮乐效果

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. (转)iOS 各种控件默认高度(图示)

    1.状态栏 状态栏一般高度为20像素,在打手机或者显示消息时会放大到40像素高,注意,两倍高度的状态栏在好像只能在纵向的模式下使用.如下图 用户可以隐藏状态栏,也可以将状态栏设置为灰色,黑色或者半透明 ...

  8. 美丽的for循环语句

    美丽的for循环语句 题目:用for循环语句实现四个三角形不同的形状.   图案:    ---------------第一个三角形图形形状----------------**********第二个三 ...

  9. VS2010调试小技巧

    在VS下做开发的时候我们进行调试的时候路径是这个样子的:http://localhost:端口号/项目名称/index.aspx 但是发布到服务器上面的时候却是这个样子的:http://www.xxx ...

  10. VS2010中属性页中,C/C++ -->预处理器定义

    如上图中,在这里,WIN32._DEBUGE._UNICODE等其实是一些宏定义,在这里写上这些,相当于在本工程所有的文件中都写上了: #define WIN32 #define _DEBUG#def ...