今日头条杯2018湖北省赛 F.flower road

链接: https://www.nowcoder.com/acm/contest/104/E
来源:牛客网

时间限制:C/C++ 3秒,其他语言6秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

(受限于评测机,此题数据范围与现场赛不一致,请谅解)

Once upon a time, there was a beautiful princess named TQM, and a handsome prince named GSS. One day, the prince would like to visit the princess. While in front of the princess' house, there was a flower-beds with blooming flowers. The prince was supposed to go through the flower-beds choosing the best ``Flower Road''.

Here is the task. The flower-beds is presented by a matrix with integers on each grid representing the princess' satisfaction of the flowers on it. Now, the prince was on the top left point (1, 1) and the princess was on the bottom right point (N, N). While the princess didn't want this to be so easy, she operated M times ``rotation'' on the flower-beds according to the order. Each time, she would choose a matrix whose top left point was . Then, four disjoint parts of the matrix whose length of size was rotated clockwise. Here is an example to make the ``rotation'' clearly.

今日头条杯2018湖北省赛 F.flower road_第1张图片

Then, your task is to help the prince to choose a best ``Flower Road'' after these operations with the largest sum of the satisfaction. By the way, the prince will take the shortest way, which means he will only go down (from point (x, y) to point (x+1, y)) and right (from point (x, y) to point (x, y+1)).

输入描述:

The first line of input contains two integers, N () and M (), indicating the numbers N and M described above.
 Then N lines follow, and each line N integers, representing the matrix. Then M lines follow, each line has three integers ,
 where xi and yi are coordinates of the top right point of i-th rotation matrix, th - side length of the matrix.

输出描述:

Output the max sum of the satisfaction.

示例1

输入

4 1
1 2 5 6
3 4 7 8
13 14 9 10
15 16 11 12
1 1 2

输出

81
十字链表

让你在xi,yi点,以li为边长进行2li*2li中四块的顺时针变换

变换m次后,输出1,1->n,n的最大和,每次只能向右或向下走

相当于

一、二      变      四、一  

四、三      成      三、二

得到每个节点的上下左右,并且最开始初始化,这样可以得到左顶点的节点

每次通过它找到13个点,进行变化

以1,1,2做样例

s1        t1        s2        s6

dot2               dot4   

s3        dot3    s4        s5

s7                    s8        s9

变换第三块、第四块、第一块、第二块的上、左、下、右    不知道为什么顺序有关

最聪明的想法是:得到最后节点的实际存数(详情见putting函数)

极其感谢我的大巨轮!!!!!!!

爱你,么么哒!

@还是太年轻!


#include 
#include 
#include 
#include 
using namespace std;
const int maxn=3250000;
const int maxx=2500;
int n,m;
int x1,x2;
int D[maxn],U[maxn],R[maxn],L[maxn];
int finding[maxx][maxx];
int cc[maxx][maxx];
int store[maxx][maxx];
int dp[maxx][maxx];
int q1[maxn],q2[maxn]; 
int dot1,dot2,dot3,dot4;
int s,s1,s2,s3,s4,s5,s6,s7,s8,s9;
void init(int n)
{
    memset(finding,-1,sizeof(finding));
    int k=0;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            scanf("%d",&store[i][j]);
            finding[i][j]=k++;
        }
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            int id=finding[i][j];
            U[id]=finding[i-1][j];
            D[id]=finding[i+1][j];
            L[id]=finding[i][j-1];
            R[id]=finding[i][j+1];
            if(U[id]==-1&&L[id]==-1)
                s=id;
        }
    }
}
void right(int &x)
{
    x=R[x];
}
void down(int &x)
{
    x=D[x];
}
void left(int &x)
{
    x=L[x];
}
void up(int &x)
{
    x=U[x];
}
void looking(int x,int y,int h)
{
    s1=s;
    for(int i=1;i




你可能感兴趣的:(数据结构——十字链表,数据结构)