| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1676 人关注过本帖
标题:求解PKU 1185 炮兵阵地问题
只看楼主 加入收藏
hf201089
Rank: 2
等 级:论坛游民
帖 子:48
专家分:25
注 册:2012-3-4
收藏
得分:0 
回复 19楼 beyondyf
感谢啦!
仔细拜读去了!
2012-03-28 13:04
czz5242199
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:660
专家分:2400
注 册:2011-10-26
收藏
得分:0 
我也wa了。。真疼,,找到了wa的数据,不过太大了,真心不知道怎么找错,我测试了一下杨大哥的程序,这个数据也wa了

程序代码:
50 10
PPHPPHPPPP
PPPHPPPHPP
PHPPPHPPPH
PHPHHHHPPH
PPPPPPPPPH
PPPHPPHPPP
PHPPPPPHPH
HPHPPPPPPP
PPPHPHPPPP
HHHHPPPHHP
PPPHPPPHHP
PPPHPPPPHP
PPHHHPHPHP
PPHPHPPPHP
HHPPPPPPPP
HPPPPPHPPH
PPHPPPHPHH
HHHPHHPHPP
PPPHHPHPPH
HHPPPHPPHH
HPPPPPPHHH
PPPPHHPPPP
HPHPPPHPPH
PPPPPPPHPP
HPPPPPPPHP
HPPPPHPHHH
PHHHPHHPHP
PPPPPPPHPH
HPPPPHHPPP
PPPPPPHHHH
HPHPHHPPPH
PHPHHPPPPH
PHHPHHPPPH
HHPPPPPHHP
HPHPHPPHHP
PPHPHPPHPH
PHHPPPPPPH
PHHPHPHHHH
PHPHHPPPPP
PPHHPPPHHP
PPPPHPPHPH
PHPPPPHPHH
PPPPPHHHPP
PPPHPHHPHP
PPHPPPHHHP
PPHPPPPHHH
PHPPPPHPHP
HPPPPHPPHP
PPPPPPHHPH
PPHHHPPPPP

ans:127
2012-03-29 12:52
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
有数据就容易多了。感谢小曹的数据,话说你是怎么得到这组数据的?
我的代码中存在一处BUG,是优化代码结构时不小心引入的。
下面是修改后AC的代码。有兴趣的不妨对比一下我之前的WA代码,看看我修改了哪里,以及为什么
程序代码:
#include<stdio.h>
int ls[60];
int lc[60];
char lm[60][60];

int is_right(int s)
{
    for(; s; s >>= 1)
    if(s & 1 && s & 6) return 0;
    return 1;
}

int count(int s)
{
    int c;
    for(c = 0; s; c++) s &= s - 1;
    return c;
}

void initial()
{
    int i, j;
    for(j = i = 0; i < 586; i++)
        if(is_right(i)) lc[j] = count(ls[j] = i), j++;
    for(lm[0][0] = 1, i = 0; i < 60; i++)
    for(j = i + 1; j < 60; j++) lm[i][j] = lm[j][i] = (ls[i] & ls[j]) == 0;
}

int cal(int *map, int n, int m)
{
    int a[2][60][60] = {0}, (*f)[60] = a[0], (*p)[60] = a[1], (*t)[60];
    int w, i, j, k, r, c;
    for(w = 1 << m, i = 59; i > 0 && ls[i] >= w; i--); w = i;
    for(i = 0; i < n; i++, t = p, p = f, f = t)
    {
        for(j = 0; j <= w; j++)
        {
            if(ls[j] & map[i])
            {
                for(k = 0; k <= w; p[j][k++] = -1);
                continue;
            }
            for(k = 0; k <= w; k++)
            {
                if(!lm[j][k]){ p[j][k] = -1; continue; }
                for(c = -1, r = 0; r <= w; r++)
                if(f[k][r] >= 0 && lm[j][r] && f[k][r] + lc[j] > c) c = f[k][r] + lc[j];
                p[j][k] = c;
            }
        }
    }
    for(c = i = 0; i <= w; i++)
    for(j = 0; j <= w; j++)
    if(f[i][j] > c) c = f[i][j];
    return c;
}

int main()
{
    char str[32];
    int map[256], n, m, i, j;
    initial();
    scanf("%d%d", &n, &m);
    for(i = 0; i < n; i++)
    {
        scanf("%s", str);
        map[i] = 0;
        for(j = 0; j < m; j++)
            map[i] = (map[i] << 1) + (str[j] == 'H');
    }
    printf("%d\n", cal(map, n, m));
    return 0;
}

重剑无锋,大巧不工
2012-03-29 16:11
快速回复:求解PKU 1185 炮兵阵地问题
数据加载中...
 
   



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

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