zoukankan      html  css  js  c++  java
  • Dima and Magic Guitar CodeForces

    Dima and Magic Guitar CodeForces - 366E

    题意:

    http://blog.csdn.net/u011026968/article/details/38716425
    http://vawait.com/2013/11/codeforces-366e/
    http://www.cnblogs.com/jianglangcaijin/archive/2013/11/25/3441319.html

    对于s中任意相邻两个数x和y,都要求在矩形中找出任意两个分别等于x和y的点,然后求其曼哈顿距离,本题要求所有求出的曼哈顿距离的最大值最大。容易想到,应当是让一对点的曼哈顿距离最大,其他点任意即可。也就是对于s中所有相邻两个数,找出矩形中分别等于这两个数且之间曼哈顿距离最大的两个点。

    曼哈顿距离等于以下的最大值:

    (xa-xb)+(ya-yb)
    (xa-xb)-(ya-yb)
    -(xa-xb)+(ya+yb)
    -(xa-xb)-(ya-yb)

    也就是这些的最大值:

    (xa+ya)-(xb+yb)
    (xa-ya)-(xb-yb)
    (-xa+ya)-(-xb+yb)
    (-xa-ya)-(-xb-yb)

    因此要求值分别为a和b的点间最大的曼哈顿距离,就是这四种的最大值,而每种的最大值都是被减数最大,减数最小。也就是分别记录所有值为a的点中xa+ta,xa-ya,-xa+ya,-xa-ya的最大与最小值。

    (这题没有讲不可能完成时怎么处理,也没有这样的数据。)

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 int a[100110];
     6 int max1[11][4],min1[11][4];
     7 int n,m,k,s,ans;
     8 int main()
     9 {
    10     int i,j,t;
    11     scanf("%d%d%d%d",&n,&m,&k,&s);
    12     memset(min1,0x3f,sizeof(min1));
    13     memset(max1,140,sizeof(max1));
    14     for(i=1;i<=n;i++)
    15         for(j=1;j<=m;j++)
    16         {
    17             scanf("%d",&t);
    18             max1[t][0]=max(max1[t][0],i+j);
    19             max1[t][1]=max(max1[t][1],i-j);
    20             max1[t][2]=max(max1[t][2],-i+j);
    21             max1[t][3]=max(max1[t][3],-i-j);
    22             min1[t][0]=min(min1[t][0],i+j);
    23             min1[t][1]=min(min1[t][1],i-j);
    24             min1[t][2]=min(min1[t][2],-i+j);
    25             min1[t][3]=min(min1[t][3],-i-j);
    26         }
    27     scanf("%d",&a[1]);
    28     for(i=2;i<=s;i++)
    29     {
    30         scanf("%d",&a[i]);
    31         for(j=0;j<=3;j++)
    32             ans=max(ans,max(max1[a[i-1]][j]-min1[a[i]][j],max1[a[i]][j]-min1[a[i-1]][j]));
    33     }
    34     printf("%d",ans);
    35     return 0;
    36 }
  • 相关阅读:
    Java枚举和反射
    Java网络编程
    django 中文乱码问题
    chrome 开发人员工具
    js 编码问题
    js 复制内容到剪切板
    网页获取页面上选择的内容
    git命令
    Jquery和Javascript对象之间的转换
    Spring Data Elasticsearch
  • 原文地址:https://www.cnblogs.com/hehe54321/p/cf-366e.html
Copyright © 2011-2022 走看看