zoukankan      html  css  js  c++  java
  • hdu 1505 city game (1506 加强版)

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    char ss[33];
    int b[1002][1002],qian[1002],hou[1002];
    
    int main()
    {
        int i,j,n,m,t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d%d",&n,&m);
            memset(b,0,sizeof(b));
            for(i=1;i<=n;i++)
            {
                for(j=1;j<=m;j++)
                {
                    //getchar();
                    scanf("%s",ss);
                    if(ss[0]=='F')
                        b[i][j]=b[i-1][j]+1;
                    else
                        b[i][j]=0;
                        //printf("%d ",b[i][j]);
                }
            }
            int ans=0;
            for(i=1;i<=n;i++)
            {
                for(j=1;j<=m;j++)
                    hou[j]=qian[j]=j;
                for(j=2;j<=m;j++)
                {
                   while(qian[j]>=2&&b[i][qian[j]-1]>=b[i][j])
                        qian[j]=qian[qian[j]-1];
                }
    
                for(j=m-1;j>=1;j--)
                {
                    while(hou[j]<=m-1&&b[i][hou[j]+1]>=b[i][j])
                        hou[j]=hou[hou[j]+1];
                }
    
                for(j=1;j<=m;j++)
                {
                    int temp=(hou[j]-qian[j]+1)*b[i][j];
                    if(ans<temp)
                        ans=temp;
                }
            }
            printf("%d
    ",ans*3);
        }
        return 0;
    }

    一个一直wa的代码

     1 #include<iostream>;
     2 #include<cstdio>
     3 #include<cstring>
     4 using namespace std;
     5 char a[1002][1002];
     6 int b[1002][1002],qian[1002],hou[1002];
     7 
     8 int main()
     9 {
    10     int i,j,n,m,t;
    11     scanf("%d",&t);
    12     while(t--)
    13     {
    14         scanf("%d%d",&n,&m);
    15         memset(b,0,sizeof(b));
    16         for(i=1;i<=n;i++)
    17         {
    18             for(j=1;j<=m;j++)
    19             {
    20                 getchar();
    21                 scanf("%c",&a[i][j]);
    22                 if(a[i][j]=='F')
    23                     b[i][j]=b[i-1][j]+1;
    24                 else
    25                     b[i][j]=0;
    26                     //printf("%d ",b[i][j]);
    27             }
    28         }
    29         getchar();
    30         int ans=0;
    31         for(i=1;i<=n;i++)
    32         {
    33             for(j=1;j<=m;j++)
    34                 hou[j]=qian[j]=j;
    35             for(j=2;j<=m;j++)
    36             {
    37                while(qian[j]>=2&&b[i][qian[j]-1]>=b[i][j])
    38                     qian[j]=qian[qian[j]-1];
    39             }
    40 
    41             for(j=m-1;j>=2;j--)
    42             {
    43                 while(hou[j]<=m-1&&b[i][hou[j]+1]>=b[i][j])
    44                     hou[j]=hou[hou[j]+1];
    45             }
    46 
    47             for(j=1;j<=m;j++)
    48             {
    49                 int temp=(hou[j]-qian[j]+1)*b[i][j];
    50                 if(ans<temp)
    51                     ans=temp;
    52             }
    53         }
    54         printf("%d
    ",ans*3);
    55     }
    56     return 0;
    57 }

    其实也就把接受 字符串的  由一个一个的接受的  改成了用 char数组接受  ss[0]就是 所需的那个

    还是用字符串接受靠谱一些  以后真的得尽量用字符串来接受字符了!!

  • 相关阅读:
    ssh中的 Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
    Http中的Get/Post方法
    Node.js(day2)
    使用clipBoard.js进行页面内容复制
    SVG之图形的引用use、剪切clipPath和蒙板mask
    SVG之文本
    SVG之Path
    SVG之颜色、渐变和笔刷的使用
    SVG坐标系统
    SVG入门
  • 原文地址:https://www.cnblogs.com/assult/p/3475762.html
Copyright © 2011-2022 走看看