poj 5024&&&2014 ACM/ICPC Asia Regional Guangzhou Online 1003(预处理)

http://acm.hdu.edu.cn/showproblem.php?pid=5024

分析:预处理每个点在八个方向的射线长度,再枚举八种L形状的路,取最大值。

注意题意是求一条最长路,要么一条直线,要么只有一个90角,即L型。其实直线就是L形的一个方向长度为0。

代码:

#include<iostream>
#include<map>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#define MOD 1000000007
typedef long long ll;
using namespace std;

char g[105][105];
int num[105][105][8];

int n;

void init()
{
    memset(num,0,sizeof num);
    for(int i=0;i<n;i++)
    {
        num[0][i][0]=g[0][i]=='.',num[i][0][0]=g[i][0]=='.';
        num[0][i][1]=g[0][i]=='.';
        num[0][i][2]=g[0][i]=='.',num[i][n-1][2]=g[i][n-1]=='.';
        num[i][n-1][3]=g[i][n-1]=='.';
        num[n-1][i][4]=g[n-1][i]=='.',num[i][n-1][4]=g[i][n-1]=='.';
        num[n-1][i][5]=g[n-1][i]=='.';
        num[n-1][i][6]=g[n-1][i]=='.',num[i][0][6]=g[i][0]=='.';
        num[i][0][7]=g[i][0]=='.';
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        {
            if(i&&j)num[i][j][0]=g[i][j]=='.'?num[i-1][j-1][0]+1:0;
            if(i)num[i][j][1]=g[i][j]=='.'?num[i-1][j][0]+1:0;
            if(i&&j){int jj=n-1-j;num[i][jj][2]=g[i][jj]=='.'?num[i-1][jj+1][2]+1:0;}
            if(j){int jj=n-1-j;num[i][jj][3]=g[i][jj]=='.'?num[i][jj+1][3]+1:0;}
            if(i&&j){int ii=n-1-i,jj=n-1-j;num[ii][jj][4]=g[ii][jj]=='.'?num[ii+1][jj+1][4]+1:0;}
            if(i){int ii=n-1-i;num[ii][j][5]=g[ii][j]=='.'?num[ii+1][j][5]+1:0;}
            if(i&&j){int ii=n-1-i;num[ii][j][6]=g[ii][j]=='.'?num[ii+1][j-1][6]+1:0;}
            if(j)num[i][j][7]=g[i][j]=='.'?num[i][j-1][7]+1:0;
        }
}
int main()
{
    while(~scanf("%d",&n)&&n)
    {
        for(int i=0;i<n;i++)
            scanf("%s",g[i]);
        int ans=0;
        init();
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
            {
                ans=max(ans,num[i][j][0]+num[i][j][2]-1);
                ans=max(ans,num[i][j][2]+num[i][j][4]-1);
                ans=max(ans,num[i][j][4]+num[i][j][6]-1);
                ans=max(ans,num[i][j][6]+num[i][j][0]-1);
                ans=max(ans,num[i][j][1]+num[i][j][3]-1);
                ans=max(ans,num[i][j][3]+num[i][j][5]-1);
                ans=max(ans,num[i][j][5]+num[i][j][7]-1);
                ans=max(ans,num[i][j][7]+num[i][j][1]-1);
            }
        printf("%d\n",ans);
        /*for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                for(int k=0;k<8;k++)
                    printf("%d%c",num[i][j][k],k==7?'\n':' ');*/
    }
    return 0;
}

Wang Xifeng‘s Little Plot

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 114    Accepted Submission(s): 76

Problem Description

《Dream of the Red Chamber》(also 《The Story of the Stone》) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. This novel was created in Qing Dynasty, by Cao Xueqin. But the last 40 chapters of the original
version is missing, and that part of current version was written by Gao E. There is a heart breaking story saying that after Cao Xueqin died, Cao‘s wife burned the last 40 chapter manuscript for heating because she was desperately poor. This story was proved
a rumor a couple of days ago because someone found several pages of the original last 40 chapters written by Cao.

In the novel, Wang Xifeng was in charge of Da Guan Yuan, where people of Jia family lived. It was mentioned in the newly recovered pages that Wang Xifeng used to arrange rooms for Jia Baoyu, Lin Daiyu, Xue Baochai and other teenagers. Because Jia Baoyu was
the most important inheritor of Jia family, and Xue Baochai was beautiful and very capable , Wang Xifeng didn‘t want Jia Baoyu to marry Xue Baochai, in case that Xue Baochai might take her place. So, Wang Xifeng wanted Baoyu‘s room and Baochai‘s room to be
located at two ends of a road, and this road should be as long as possible. But Baoyu was very bad at directions, and he demanded that there could be at most one turn along the road from his room to Baochai‘s room, and if there was a turn, that turn must be
ninety degree. There is a map of Da Guan Yuan in the novel, and redists (In China English, one whose job is studying 《Dream of the Red Chamber》is call a "redist") are always arguing about the location of Baoyu‘s room and Baochai‘s room. Now you can solve this
big problem and then become a great redist.

Input

The map of Da Guan Yuan is represented by a matrix of characters ‘.‘ and ‘#‘. A ‘.‘ stands for a part of road, and a ‘#‘ stands for other things which one cannot step onto. When standing on a ‘.‘, one can go to adjacent ‘.‘s through 8 directions: north, north-west,
west, south-west, south, south-east,east and north-east.

There are several test cases.

For each case, the first line is an integer N(0<N<=100) ,meaning the map is a N × N matrix.

Then the N × N matrix follows.

The input ends with N = 0.

Output

For each test case, print the maximum length of the road which Wang Xifeng could find to locate Baoyu and Baochai‘s rooms. A road‘s length is the number of ‘.‘s it includes. It‘s guaranteed that for any test case, the maximum length is at least 2.

Sample Input

3
#.#
##.
..#
3
...
##.
..#
3
...
###
..#
3
...
##.
...
0

Sample Output

3
4
3
5

Source

2014 ACM/ICPC Asia Regional Guangzhou Online

Recommend

hujie

时间: 2024-10-26 20:14:18

poj 5024&&&2014 ACM/ICPC Asia Regional Guangzhou Online 1003(预处理)的相关文章

2014 ACM/ICPC Asia Regional Guangzhou Online Wang Xifeng&#39;s Little Plot HDU5024

一道好枚举+模拟题目.转换思维视角 这道题是我做的,规模不大N<=100,以为正常DFS搜索,于是傻乎乎的写了起来.各种条件限制模拟过程 但仔细一分析发现对每个点进行全部八个方向的遍历100X100X100^8 .100X100个点,每个点在走的时候8中选择,TLE 于是改为另一个角度: 以符合要求的点为拐弯点,朝两个垂直的方向走,求出最远的距离.这样只要对每个点各个方向的长度知道,组合一下对应的就OK. 避免了每个点深搜. PS:搜索的时候x,y写反了,导致构图出现问题,以后用[dy][dx]

2014 ACM/ICPC Asia Regional Guangzhou Online

Wang Xifeng's Little Plot http://acm.hdu.edu.cn/showproblem.php?pid=5024 预处理出每个点八个方向能走的最远距离,然后枚举起点,枚举方向,每走一步都要枚举左转和右转的情况,因为预处理好了,所以可以直接算出来. 1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 const int M=128; 5 char a[M][M]; 6 in

HDU 5029 Relief grain(离线+线段树+启发式合并)(2014 ACM/ICPC Asia Regional Guangzhou Online)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5029 Problem Description The soil is cracking up because of the drought and the rabbit kingdom is facing a serious famine. The RRC(Rabbit Red Cross) organizes the distribution of relief grain in the disa

HDU 5014 Number Sequence(2014 ACM/ICPC Asia Regional Xi&#39;an Online) 题解

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5014 Number Sequence Problem Description There is a special number sequence which has n+1 integers. For each number in sequence, we have two rules: ● ai ∈ [0,n] ● ai ≠ aj( i ≠ j ) For sequence a and sequ

hdu 5008(2014 ACM/ICPC Asia Regional Xi&#39;an Online ) Boring String Problem(后缀数组&amp;二分)

Boring String Problem Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 219    Accepted Submission(s): 45 Problem Description In this problem, you are given a string s and q queries. For each que

2014 ACM/ICPC Asia Regional Xi&#39;an Online

03 hdu5009 状态转移方程很好想,dp[i] = min(dp[j]+o[j~i]^2,dp[i]) ,o[j~i]表示从j到i颜色的种数. 普通的O(n*n)是会超时的,可以想到o[]最大为sqrt(n),问题是怎么快速找到从i开始往前2种颜色.三种.四种...o[]种的位置. 离散化之后,可以边走边记录某个数最后一个出现的位置,初始为-1,而所要求的位置就等于 if(last[a[i]]==-1) 该数没有出现过,num[i][1] = i,num[i][j+1] = num[i-1

HDU 5000 2014 ACM/ICPC Asia Regional Anshan Online DP

Clone Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other) Total Submission(s) : 8   Accepted Submission(s) : 5 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description After eating food from Chernobyl,

2014 ACM/ICPC Asia Regional Xi&#39;an Online(HDU 5007 ~ HDU 5017)

题目链接 A题:(字符串查找,水题) 题意 :输入字符串,如果字符串中包含“ Apple”, “iPhone”, “iPod”, “iPad” 就输出 “MAI MAI MAI!”,如果出现 “Sony” 就输出“SONY DAFA IS GOOD!” ,大小写敏感. 思路 : 字符串查找,水题. 1 #include <string.h> 2 #include <stdio.h> 3 #include <iostream> 4 5 using namespace st

HDU 5014 Number Sequence 贪心 2014 ACM/ICPC Asia Regional Xi&#39;an Online

尽可能凑2^x-1 #include <cstdio> #include <cstring> const int N = 100005; int a[N], p[N]; int init(int x) { int cnt = 0; while(x > 1) { x /= 2; cnt ++; } return cnt + 1; } int main() { int n; while(~scanf("%d", &n)){ for(int i = 0;