| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1102 人关注过本帖
标题:杭电——1467,求牛人解决
只看楼主 加入收藏
好孩子好宝贝
Rank: 1
等 级:新手上路
帖 子:35
专家分:2
注 册:2011-7-26
结帖率:87.5%
收藏
已结贴  问题点数:20 回复次数:11 
杭电——1467,求牛人解决
Triangles
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 116    Accepted Submission(s): 54


Problem Description
It is always very nice to have little brothers or sisters. You can tease them, lock them in the bathroom or put red hot chili in their sandwiches. But there is also a time when all meanness comes back!

As you know, in one month it is Christmas and this year you are honored to make the big star that will be stuck on the top of the Christmas tree. But when you get the triangle-patterned silver paper you realize that there are many holes in it. Your little sister has already cut out smaller triangles for the normal Christmas stars. Your only chance is to find an algorithm that tells you for each piece of silver paper the size of the largest remaining triangle.

Given a triangle structure with white and black fields inside you must find the largest triangle area of white fields, as shown in the following figure.


 

Input
The input contains several triangle descriptions. The first line of each description contains an integer n (1 <= n <= 100), which gives the height of the triangle. The next n lines contain characters of the set {space, #, -} representing the rows of the triangle, where `#' is a black and `-' a white field. The spaces are used only to keep the triangle shape in the input by padding at the left end of the lines. (Compare with the sample input. The first test case corresponds to the figure.)
For each triangle, the number of the characters `#' and `-' per line is odd and decreases from 2n - 1 down to 1.

The input is terminated by a description starting with n = 0.

 

Output
For each triangle in the input, first output the number of the triangle, as shown in the sample output. Then print the line ``The largest triangle area is a.'', where a is the number of fields inside the largest triangle that consists only of white fields. Note that the largest triangle can have its point at the top, as in the second case of the sample input.

Output a blank line after each test case.


 

Sample Input
5
#-##----#
 -----#-
  ---#-
   -#-
    -
4
#-#-#--
 #---#
  ##-
   -
0
 

我的代码:就是不过,不知道为什么,求牛人解决;
#include<iostream>
using namespace std;
#define T 120

int R;
char map[T][2*T+2];
int max_s,num[T][2*T+2];

int min(int i,int j,int k)
{
    i=i>j?j:i;
    return i>k?k:i;
}


int main()
{
    int i,j,c=0;
    while(scanf("%d",&R),R)
    {
        max_s=0;
        if(c!=0)printf("\n");
        for(i=1;i<=R;i++)
            scanf("%s",map[i]);
        memset(num,0,sizeof(num));
        for(i=1;i<=R;i++)
        {
            for(j=0;j<=2*R-2*i;j++)
            {
                if(map[i][j]=='-')
                {
                    if(map[i-1][j]=='-' && map[i-1][j+1]=='-'&& map[i-1][j+2]=='-')
                        num[i][j]=min(num[i-1][j],num[i-1][j+1],num[i-1][j+2])+1;
                    else
                        num[i][j]=1;
                    max_s=max_s>num[i][j]?max_s:num[i][j];
                }
            }
        }
        if(R>3)
        {
            memset(num,0,sizeof(num));
            for(i=1;i<R;i++)
            {
                if(map[i][0]=='-')  num[i][0]=1;
                if(map[i][1]=='-')  num[i][1]=1;
            }
            for(i=R-2;i>=1;i--)
            {
                for(j=2;j<2*R-2*i;j++)
                {
                    if(map[i][j]=='-')
                    {
                        if(map[i+1][j]=='-' && map[i+1][j-1]=='-'&& map[i+1][j-2]=='-')
                            num[i][j]=min(num[i+1][j],num[i+1][j-1],num[i+1][j-2])+1;
                        else
                            num[i][j]=1;
                        max_s=max_s>num[i][j]?max_s:num[i][j];
                    }
                }
            }
        }
        printf("Triangle #%d\nThe largest triangle area is %d.\n",++c,max_s*max_s);
    }
    return 0;
}
搜索更多相关主题的帖子: star brothers always Memory 
2011-08-13 19:27
_xiong_mao_1
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:49
专家分:102
注 册:2010-12-6
收藏
得分:0 
唉··看到这多英文,帮顶个把。
2011-08-15 00:18
hjywyj
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:3
帖 子:1114
专家分:2611
注 册:2010-4-14
收藏
得分:0 
没学好英语,只能帮顶!
2011-08-15 07:49
草狼
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:2
帖 子:577
专家分:1040
注 册:2010-4-6
收藏
得分:0 
跪求牛人给解题思路啊  菜鸟只能帮忙顶顶贴
2011-08-16 13:16
好孩子好宝贝
Rank: 1
等 级:新手上路
帖 子:35
专家分:2
注 册:2011-7-26
收藏
得分:0 
我的就是通过DP思路,先找向下的三角形,然后再找向上的
2011-08-17 13:49
zerokingf1
Rank: 2
等 级:论坛游民
帖 子:31
专家分:23
注 册:2011-7-30
收藏
得分:0 
看来要多学习英语了
2011-08-17 16:21
heartnheart
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:335
专家分:1096
注 册:2009-7-10
收藏
得分:20 
#include<iostream>
#include <cstdio>
#include <cstring>

using namespace std;
#define T 120

int R;
char map[T][2*T+2];
int max_s,num[T][2*T+2];


int min(int i,int j)
{
    return i < j ? i : j;
}

int main()
{
    int i,j,c=0;
    while(scanf("%d",&R),R)
    {
        max_s=0;
        for(i=1;i<=R;i++)
            scanf("%s",map[i]);
        memset(num,0,sizeof(num));
        for(i=1;i<=R;i++)
        {
            for(j=0;j<=2*R-2*i;j++)
            {
                if(map[i][j]=='-')
                {
                    if(j%2==0&&map[i-1][j]=='-' && map[i-1][j+1]=='-'&& map[i-1][j+2]=='-')
                        num[i][j]=min(num[i-1][j],num[i-1][j+2])+1;
                    else
                        num[i][j]=1;
                    max_s=max_s>num[i][j]?max_s:num[i][j];
                }
            }
        }
        if(R>3)
        {
            memset(num,0,sizeof(num));
            for(i=1;i<R;i++)
            {
                if(map[i][0]=='-')  num[i][0]=1;
                if(map[i][1]=='-')  num[i][1]=1;
            }
            for(i=R-2;i>=1;i--)
            {
                for(j=2;j<2*R-2*i;j++)
                {
                    if(map[i][j]=='-')
                    {
                        if(j%2==1&&map[i+1][j]=='-' && map[i+1][j-1]=='-'&& map[i+1][j-2]=='-')
                            num[i][j]=min(num[i+1][j],num[i+1][j-2])+1;
                        else
                            num[i][j]=1;
                        max_s=max_s>num[i][j]?max_s:num[i][j];
                    }
                }
            }
        }
        printf("Triangle #%d\nThe largest triangle area is %d.\n\n",++c,max_s*max_s);
    }
    return 0;
}
2011-08-17 22:16
好孩子好宝贝
Rank: 1
等 级:新手上路
帖 子:35
专家分:2
注 册:2011-7-26
收藏
得分:0 
回复 7楼 heartnheart
牛人,为什么在j%2==0和j%2==1这句话啊????小弟不懂,求解;】
今天杭电登不上去啦;我没有办法提交。。
2011-08-18 13:41
zjy2wyl
Rank: 1
等 级:新手上路
帖 子:12
专家分:1
注 册:2011-8-16
收藏
得分:0 
谷歌翻译下吧。。
2011-08-18 15:42
好孩子好宝贝
Rank: 1
等 级:新手上路
帖 子:35
专家分:2
注 册:2011-7-26
收藏
得分:0 
回复 7楼 heartnheart
还有为什么要多加几个有文件啊
2011-08-18 20:51
快速回复:杭电——1467,求牛人解决
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019516 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved